Skip to content

Commit c1d1852

Browse files
committed
feat(core): Tokenizer touch sheet behind experimental.presentation
Ports the Lab MobileTokenizer touch flow into Tokenizer as the `bottom-sheet` value of the experimental `presentation` option (`experimental={{presentation: 'popover' | 'bottom-sheet' | 'adaptive'}}`, spec:AST-017 FR21). `adaptive` resolves through useAdaptivePresentation, the policy Selector, MultiSelector and DropdownMenu share. Omitting `experimental` keeps the inline combobox unchanged. The sheet is one standalone BottomSheet driven by `isOpen`: the shared PanelSearchInput on top (grown to the 44px rows through a new internal fieldXstyle), checkbox rows that keep their place while the sheet is open and regroup selected-first on the next open, 50-row progressive rendering, a Create row with a trailing Add action under hasCreate, and a footer with a confirmed Clear all and Done. The list is busy from open and from each query change until the search settles. Selection stays in Tokenizer so the add, remove and create paths and their announcements are the inline field's own. The trigger is the control: base props and `ref` reach it, its accessible description lists the selected tokens, and a field that becomes disabled while the sheet is open closes it and takes focus back. Props with no sheet surface warn once in development. The surface loads with React.lazy and renders nothing during hydration, so a Tokenizer that does not opt in does not carry it. The sheet's parts expose no theming targets while the option is experimental. Also: @astryx.tokenizer.* catalog keys for the sheet's strings, doc.mjs prop and examples, a `Tokenizer — Adaptive presentation` block template (and its ShadCN route), three Core/Tokenizer stories, tests for the resolution and the ported flow, an [experimental] core changeset and a [docs] cli changeset, and the deletion of the spec's implementation-gap notes.
1 parent 79c26d5 commit c1d1852

10 files changed

Lines changed: 2579 additions & 60 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[experimental] Tokenizer gains a touch surface behind `experimental={{presentation: 'bottom-sheet' | 'adaptive'}}`. `bottom-sheet` replaces the inline combobox with a trigger that shows the selected tokens and opens one tall modal sheet: a search row on top, full-width checkbox rows that keep their place while the sheet is open and regroup selected-first on the next open, 50-row progressive rendering for long lists, a `Create "…"` row with a trailing Add action under `hasCreate`, and a footer with a confirmed Clear all and Done. `adaptive` uses the sheet on compact coarse-pointer screens and the popover otherwise, resolved the same way Selector resolves it. The sheet surface loads on demand, so a Tokenizer that does not opt in does not carry it. The trigger describes its selected tokens to assistive technology, announcements made while the sheet is open reach assistive technology through a live region inside the sheet, with `experimental` passed the component also accepts a `Ref<HTMLInputElement | HTMLButtonElement>` because `ref` reaches the trigger in the sheet presentation (the exported `TokenizerProps` interface is unchanged), and in development the field warns once about props that have no surface in the sheet presentation (`renderItem`, `renderToken`, `endContent`, `hasClear`, `hasEntriesOnFocus`, `menuWidth`, `tokenOverflowBehavior`, `hasAutoFocus`). New `@astryx.tokenizer.*` catalog keys for the sheet's strings; the sheet's parts expose no theming targets while the option is experimental. Anything inside Tokenizer's `experimental` prop may change or be removed in a patch release; omitting it keeps the stable behavior.
6+
7+
@imdreamrunner

‎apps/storybook/stories/Tokenizer.stories.tsx‎

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,3 +798,135 @@ export const CaretPlacement: Story = {
798798
}
799799
},
800800
};
801+
// A long, searchable dataset for the sheet presentation: enough entries to
802+
// see the 50-row batches of progressive rendering.
803+
const sheetTags: SearchableItem[] = Array.from({length: 1000}, (_, index) => {
804+
const number = index + 1;
805+
return {
806+
id: `tag-${number}`,
807+
label:
808+
number === 1
809+
? 'Design'
810+
: number === 2
811+
? 'Eng'
812+
: `Tag ${String(number).padStart(2, '0')}`,
813+
};
814+
});
815+
816+
const sheetTagSource: SearchSource = {
817+
search: (query: string) =>
818+
sheetTags.filter(tag =>
819+
tag.label.toLowerCase().includes(query.toLowerCase()),
820+
),
821+
bootstrap: () => sheetTags,
822+
};
823+
824+
/**
825+
* The experimental touch surface, forced on every device so it is reviewable
826+
* on a laptop: `experimental.presentation="bottom-sheet"`. The trigger shows
827+
* the selected tokens; tapping it opens one tall sheet with the search row on
828+
* top, checkbox rows that keep their place while the sheet is open, a Create
829+
* row for typed text, and a confirmed Clear all beside Done.
830+
*/
831+
export const ExperimentalBottomSheet: Story = {
832+
render: args => {
833+
const [value, setValue] = useState<SearchableItem[]>([
834+
sheetTags[0],
835+
sheetTags[1],
836+
]);
837+
return (
838+
<Tokenizer
839+
{...args}
840+
searchSource={sheetTagSource}
841+
value={value}
842+
onChange={items => setValue(items)}
843+
hasCreate
844+
maxMenuItems={1000}
845+
debounceMs={0}
846+
experimental={{presentation: 'bottom-sheet'}}
847+
/>
848+
);
849+
},
850+
args: {
851+
label: 'Tags',
852+
placeholder: 'Add tags',
853+
},
854+
name: 'Experimental: bottom sheet',
855+
};
856+
857+
/**
858+
* `experimental.presentation="adaptive"`: the sheet on a compact
859+
* coarse-pointer screen (narrow the viewport and emulate touch), otherwise the
860+
* inline combobox — the same resolution Selector uses.
861+
*/
862+
export const ExperimentalAdaptive: Story = {
863+
render: args => {
864+
const [value, setValue] = useState<SearchableItem[]>([sheetTags[0]]);
865+
return (
866+
<Tokenizer
867+
{...args}
868+
searchSource={sheetTagSource}
869+
value={value}
870+
onChange={items => setValue(items)}
871+
maxMenuItems={1000}
872+
debounceMs={0}
873+
experimental={{presentation: 'adaptive'}}
874+
/>
875+
);
876+
},
877+
args: {
878+
label: 'Tags',
879+
placeholder: 'Add tags',
880+
},
881+
name: 'Experimental: adaptive',
882+
};
883+
884+
/**
885+
* Disabled and at-limit states of the sheet presentation: the disabled
886+
* trigger stays focusable and does not open; at `maxEntries` the sheet's
887+
* unchecked rows are inert while checked rows still toggle.
888+
*/
889+
export const ExperimentalBottomSheetStates: Story = {
890+
render: args => {
891+
const [value, setValue] = useState<SearchableItem[]>([
892+
sheetTags[0],
893+
sheetTags[1],
894+
]);
895+
return (
896+
<div style={{display: 'grid', gap: 16}}>
897+
<Tokenizer
898+
{...args}
899+
label="Disabled"
900+
searchSource={sheetTagSource}
901+
value={[sheetTags[0], sheetTags[1]]}
902+
onChange={() => {}}
903+
isDisabled
904+
experimental={{presentation: 'bottom-sheet'}}
905+
/>
906+
<Tokenizer
907+
{...args}
908+
label="Disabled and empty"
909+
searchSource={sheetTagSource}
910+
value={[]}
911+
onChange={() => {}}
912+
isDisabled
913+
experimental={{presentation: 'bottom-sheet'}}
914+
/>
915+
<Tokenizer
916+
{...args}
917+
label="At the limit"
918+
searchSource={sheetTagSource}
919+
value={value}
920+
onChange={items => setValue(items)}
921+
maxEntries={2}
922+
debounceMs={0}
923+
experimental={{presentation: 'bottom-sheet'}}
924+
/>
925+
</div>
926+
);
927+
},
928+
args: {
929+
placeholder: 'Add tags',
930+
},
931+
name: 'Experimental: bottom sheet states',
932+
};

‎packages/core/locales/en.json‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,58 @@
15991599
"defaultMessage": "Removed {label}",
16001600
"description": "Polite screen-reader announcement after a token is removed from a Tokenizer, by its × button or by Backspace. Live-region text, never shown on screen; `{label}` is the token's visible text."
16011601
},
1602+
"@astryx.tokenizer.search": {
1603+
"defaultMessage": "Search {label}",
1604+
"description": "Accessible name of the search field at the top of a Tokenizer's bottom sheet (the touch presentation). `{label}` is the field's own label, e.g. `Search Tags`. Not shown on screen."
1605+
},
1606+
"@astryx.tokenizer.searchPlaceholder": {
1607+
"defaultMessage": "Search…",
1608+
"description": "Placeholder inside the search field at the top of a Tokenizer's bottom sheet, shown while the query is empty. Single word plus ellipsis."
1609+
},
1610+
"@astryx.tokenizer.noItems": {
1611+
"defaultMessage": "No items available",
1612+
"description": "Title of the empty state inside a Tokenizer's bottom sheet when the search source has nothing to choose from and no query is typed. Neutral tone (not error-y)."
1613+
},
1614+
"@astryx.tokenizer.noItemsDescription": {
1615+
"defaultMessage": "There are no items to choose from.",
1616+
"description": "Supporting sentence under the `No items available` empty-state title inside a Tokenizer's bottom sheet."
1617+
},
1618+
"@astryx.tokenizer.noResultsDescription": {
1619+
"defaultMessage": "Try a different search.",
1620+
"description": "Supporting sentence under the no-results empty-state title inside a Tokenizer's bottom sheet, suggesting the person change the query."
1621+
},
1622+
"@astryx.tokenizer.create": {
1623+
"defaultMessage": "Create \"{value}\"",
1624+
"description": "Label of the create row inside a Tokenizer's bottom sheet when `hasCreate` is set and the typed text matches no existing item. `{value}` is the typed text, e.g. `Create \"Marketing\"`."
1625+
},
1626+
"@astryx.tokenizer.add": {
1627+
"defaultMessage": "Add",
1628+
"description": "Visible label of the button at the end of the create row inside a Tokenizer's bottom sheet; pressing it adds the typed text as a new token. Imperative verb; short."
1629+
},
1630+
"@astryx.tokenizer.addValue": {
1631+
"defaultMessage": "Add {value}",
1632+
"description": "Screen-reader-only name of the create row's Add button inside a Tokenizer's bottom sheet. `{value}` is the typed text, e.g. `Add Marketing`."
1633+
},
1634+
"@astryx.tokenizer.done": {
1635+
"defaultMessage": "Done",
1636+
"description": "Label of the primary footer button inside a Tokenizer's bottom sheet; pressing it closes the sheet. Selections are already applied, so this is not a confirm."
1637+
},
1638+
"@astryx.tokenizer.clearAllTitle": {
1639+
"defaultMessage": "Clear all selected items?",
1640+
"description": "Title of the confirmation dialog shown when the person presses Clear all inside a Tokenizer's bottom sheet. A question."
1641+
},
1642+
"@astryx.tokenizer.clearAllDescription": {
1643+
"defaultMessage": "This removes all selected items from {label}.",
1644+
"description": "Body of the Clear all confirmation dialog inside a Tokenizer's bottom sheet. `{label}` is the field's own label, e.g. `This removes all selected items from Tags.`"
1645+
},
1646+
"@astryx.tokenizer.selectedCount": {
1647+
"defaultMessage": "{count, number} selected",
1648+
"description": "Screen-reader-only lead-in of the description on a Tokenizer's bottom-sheet trigger (the touch presentation), followed by the selected token labels. `{count}` is how many tokens are selected, e.g. `2 selected`. Not shown on screen."
1649+
},
1650+
"@astryx.tokenizer.clearSelection": {
1651+
"defaultMessage": "Clear selection",
1652+
"description": "Label of the destructive action button in the Clear all confirmation dialog inside a Tokenizer's bottom sheet. Imperative verb phrase; confirms removing every token."
1653+
},
16021654
"@astryx.lightbox.imagePosition": {
16031655
"defaultMessage": "Image {index, number} of {total, number}",
16041656
"description": "Polite screen-reader announcement when a Lightbox moves to a media item that has no alt text. Live-region text, never shown on screen; `{index}` is 1-based, example: `Image 3 of 12`."

‎packages/core/src/Field/PanelSearchInput.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
import {useCallback, useState, type Ref} from 'react';
4343
import * as stylex from '@stylexjs/stylex';
44+
import type {StyleXStyles} from '@stylexjs/stylex';
4445
import {Icon} from '../Icon';
4546
import {InputClearButton} from './InputClearButton';
4647
import {mergeProps} from '../utils';
@@ -177,6 +178,14 @@ export interface PanelSearchInputProps extends Omit<
177178
* handler of its own.
178179
*/
179180
onContainerKeyDown?: React.KeyboardEventHandler<HTMLDivElement>;
181+
182+
/**
183+
* Styles for the field box itself (the rounded row that draws the focus
184+
* ring), as opposed to `xstyle`, which lands on the outer gutter. A panel
185+
* whose rows are taller than a dropdown's — a touch sheet — uses it to grow
186+
* the field to the same height as its rows.
187+
*/
188+
fieldXstyle?: StyleXStyles;
180189
}
181190

182191
/**
@@ -199,6 +208,7 @@ export function PanelSearchInput({
199208
onFocus,
200209
onBlur,
201210
onContainerKeyDown,
211+
fieldXstyle,
202212
xstyle,
203213
className,
204214
style,
@@ -259,6 +269,7 @@ export function PanelSearchInput({
259269
{...stylex.props(
260270
styles.field,
261271
isKeyboardFocus && styles.fieldKeyboardFocus,
272+
fieldXstyle,
262273
)}>
263274
<Icon icon="search" size="sm" color="secondary" xstyle={styles.icon} />
264275
<input

‎packages/core/src/Tokenizer/Tokenizer.doc.mjs‎

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,14 @@ export const docs = {
266266
{
267267
name: 'containerClassName',
268268
type: 'string',
269-
description: 'Class name for the field container. Same targeting as `containerXstyle`.',
269+
description:
270+
'Class name for the field container. Same targeting as `containerXstyle`.',
270271
},
271272
{
272273
name: 'containerStyle',
273274
type: 'CSSProperties',
274-
description: 'Inline styles for the field container. Same targeting as `containerXstyle`.',
275+
description:
276+
'Inline styles for the field container. Same targeting as `containerXstyle`.',
275277
},
276278
{
277279
name: 'controlXstyle',
@@ -289,6 +291,13 @@ export const docs = {
289291
type: 'CSSProperties',
290292
description: 'Inline styles for the visual control box.',
291293
},
294+
{
295+
name: 'experimental',
296+
type: "{presentation?: 'popover' | 'bottom-sheet' | 'adaptive'}",
297+
stability: 'experimental',
298+
description:
299+
"Experimental options: anything in this object may change or be removed in a patch release, and omitting it keeps the stable behavior. presentation (default 'popover') chooses how the field presents its choices. popover is the inline combobox with its anchored suggestion menu. bottom-sheet replaces it with a trigger showing the selected tokens that opens one tall modal sheet: a search row on top, full-width checkbox rows that keep their place while the sheet is open, a Create row with hasCreate, and a footer with a confirmed Clear all and Done. adaptive uses the bottom sheet on compact touch screens and the popover otherwise, resolved the same way Selector resolves it. In the sheet presentation the trigger is the control (ref, id, aria-* and data-* reach it; with experimental passed, ref also accepts a Ref<HTMLInputElement | HTMLButtonElement>; the exported TokenizerProps interface is unchanged), and renderItem, renderToken, endContent, hasClear, hasEntriesOnFocus, menuWidth, tokenOverflowBehavior and hasAutoFocus have no surface to act on; the field warns once in development when they are passed.",
300+
},
292301
],
293302
theming: {
294303
targets: [
@@ -299,6 +308,32 @@ export const docs = {
299308
},
300309
],
301310
},
311+
examples: [
312+
{
313+
label: 'Basic',
314+
code: `const [members, setMembers] = useState([]);
315+
<Tokenizer
316+
label="Team members"
317+
searchSource={userSource}
318+
value={members}
319+
onChange={items => setMembers(items)}
320+
placeholder="Search people..."
321+
/>`,
322+
},
323+
{
324+
label: 'Touch sheet on compact screens (experimental)',
325+
code: `const [tags, setTags] = useState([]);
326+
<Tokenizer
327+
label="Tags"
328+
searchSource={tagSource}
329+
value={tags}
330+
onChange={items => setTags(items)}
331+
placeholder="Add tags"
332+
hasCreate
333+
experimental={{presentation: 'adaptive'}}
334+
/>`,
335+
},
336+
],
302337
usage: {
303338
description:
304339
'Tokenizer is a multi-select input that lets users search, select, and manage multiple items displayed as removable chips. Use it when users need to build a set of selections from a searchable data source, like adding team members, applying tags, or choosing filters.',
@@ -628,6 +663,13 @@ export const docsZh = {
628663
type: 'CSSProperties',
629664
description: '可视控件框的内联样式。',
630665
},
666+
{
667+
name: 'experimental',
668+
type: "{presentation?: 'popover' | 'bottom-sheet' | 'adaptive'}",
669+
stability: 'experimental',
670+
description:
671+
"实验性选项:此对象中的任何内容都可能在补丁版本中更改或移除;省略它即保持稳定行为。presentation(默认 'popover')决定字段如何呈现选项:popover 为内联组合框及其锚定建议菜单;bottom-sheet 改为一个显示已选标记的触发按钮,点按后打开一个高的模态底部面板——顶部为搜索行,下方为整行复选框行(面板打开期间位置保持不变),hasCreate 时有「创建」行,底部为需确认的「全部清除」和「完成」;adaptive 在紧凑触摸屏上使用底部面板,其他情况使用 popover,解析方式与 Selector 相同。在底部面板呈现中,触发按钮即为控件(ref、id、aria-* 和 data-* 都作用于它);renderItem、renderToken、endContent、hasClear、hasEntriesOnFocus、menuWidth、tokenOverflowBehavior 和 hasAutoFocus 没有作用对象,传入时开发模式下会警告一次。",
672+
},
631673
],
632674
theming: {
633675
targets: [
@@ -780,10 +822,12 @@ export const docsDense = {
780822
],
781823
},
782824
propDescriptions: {
783-
containerXstyle: 'StyleX styles for the field container; no effect in InputGroup or horizontal-labels FormLayout. No root xstyle/className/style.',
825+
containerXstyle:
826+
'StyleX styles for the field container; no effect in InputGroup or horizontal-labels FormLayout. No root xstyle/className/style.',
784827
containerClassName: 'Class name for the field container.',
785828
containerStyle: 'Inline styles for the field container.',
786-
controlXstyle: 'StyleX styles for the visual control box (border, background, icons); not the native input.',
829+
controlXstyle:
830+
'StyleX styles for the visual control box (border, background, icons); not the native input.',
787831
controlClassName: 'Class name for the visual control box.',
788832
controlStyle: 'Inline styles for the visual control box.',
789833
label: 'Accessible label for input.',
@@ -825,5 +869,7 @@ export const docsDense = {
825869
'Icon at input start, before tokens. Icon name, SVG component, or ReactNode.',
826870
endContent: 'Content at input row end. For buttons, counts, controls.',
827871
handleRef: 'Imperative handle for focus() and blur() control.',
872+
experimental:
873+
"Experimental; may change in a patch. presentation: 'popover' (default, inline combobox) | 'bottom-sheet' (trigger + one searchable modal sheet of checkbox rows) | 'adaptive' (sheet on compact touch, else popover).",
828874
},
829875
};

0 commit comments

Comments
 (0)