An open source design system that's fully customizable and agent ready
TypeScript
fix(Tokenizer): a confirmed Clear all in the sheet keeps focus on Clear all, not the search field (#9882)
Xinzi Zhoub4f383decaa6
diff --git a/.changeset/tokenizer-sheet-clear-all-keeps-focus.md b/.changeset/tokenizer-sheet-clear-all-keeps-focus.mdnew file mode 100644index 0000000000..2071ba7490--- /dev/null+++ b/.changeset/tokenizer-sheet-clear-all-keeps-focus.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] Tokenizer's bottom-sheet presentation (`presentation="bottom-sheet"`, and the default `adaptive` on compact touch screens): a confirmed Clear all keeps focus on the Clear all action, now disabled with its reason, instead of moving it to the search field, which raised the on-screen keyboard over the rows the person had just cleared. The inline presentation is unchanged.++@imdreamrunnerdiff --git a/docs/specs/components/Tokenizer/Tokenizer.spec.md b/docs/specs/components/Tokenizer/Tokenizer.spec.mdindex 618fd6bee9..ad9362b085 100644--- a/docs/specs/components/Tokenizer/Tokenizer.spec.md+++ b/docs/specs/components/Tokenizer/Tokenizer.spec.md@@ -249,7 +249,7 @@ end lane.| FR21 | Long lists render progressively: 50 rows at a time, the next batch when the list scrolls within 200px of its end, with the window reset to the first batch on open and on each query change. The rendered and total counts are exposed as `data-rendered-count` and `data-total-count` on the list, and the rows sit in a `list` whose `listitem` wrappers carry `aria-setsize` with the total and `aria-posinset` with the row's position — the `checkbox` role itself admits neither — so a person moving through the rows can learn that more exist before the list has scrolled; whether a screen reader speaks the position ("n of total") from the focused checkbox depends on the screen reader (`spec:AST-009/FR8`), and the accessibility tree proves the `list`, `listitem`, `aria-setsize`, and `aria-posinset` exposure; focus reaching the last rendered row renders the next batch (WCAG 2.2 SC 1.3.1 Info and Relationships and 4.1.2 Name, Role, Value through `spec:AST-020/FR1`). | DEC-3; touch-flow evidence | Verified current behavior. || FR22 | With `hasCreate`, a non-empty trimmed query that matches no draft-selected id, no draft-selected label, and no result label (case-insensitive) adds a create row above the list showing `Create "{text}"` with a trailing Add action named `Add {text}`. Activating it adds to the draft an item with the text as both id and label — reported by Save as a `create` when that create is the last edit that still holds (FR26) — announces it, clears the query, and moves focus to the sheet's search field, since the row it was on is gone. The create row is absent while the draft is at `maxEntries`. | DEC-3; touch-flow evidence; `hasCreate` contract of the inline field | Verified current behavior. || FR23 | `maxEntries` is enforced on the draft: while the draft holds `maxEntries` items, unchecked rows carry `aria-disabled="true"`, stay focusable, and ignore activation; checked rows remain toggleable so the person can make room (`spec:AST-085/FR1`). While the draft holds more than `maxEntries` — a `value` over the limit when the sheet opened, or `maxEntries` lowered while the sheet is open — Save is `aria-disabled`, still in the focus order, with a tooltip naming the limit ("Select up to {count} items"), and does nothing until the draft is within it. | DEC-3; touch-flow evidence; `spec:AST-085` | Verified current behavior. |-| FR24 | Clear all is disabled while the draft is empty: `aria-disabled`, still in the focus order, with a tooltip saying nothing is selected, and a click opens nothing (`spec:AST-085/FR1`). Otherwise it opens the sheet's confirmation (FR27) naming the field, with Cancel as the safe action and Clear selection as the destructive one; confirming empties the draft — recorded as a removal of the draft's last item, which Save names in its `remove` when the clear is the last edit that holds (FR26); `value` is untouched until Save, so a discard restores it — closes the confirmation, and, once the confirmation has closed, moves focus to the sheet's search field, the destination this record names (`spec:AST-085/FR4`): the clear is spent, and the search field is where the next selection starts (WCAG 2.2 SC 2.4.3 through `spec:AST-020/FR1`), and announces "All items removed" inside the sheet (AR6); cancelling changes nothing and focus returns to Clear all. Clear all stays visible and reachable while searching, since the footer is pinned (FR18). | DEC-3; touch-flow evidence | Verified current behavior. |+| FR24 | Clear all is disabled while the draft is empty: `aria-disabled`, still in the focus order, with a tooltip saying nothing is selected, and a click opens nothing (`spec:AST-085/FR1`). Otherwise it opens the sheet's confirmation (FR27) naming the field, with Cancel as the safe action and Clear selection as the destructive one; confirming empties the draft — recorded as a removal of the draft's last item, which Save names in its `remove` when the clear is the last edit that holds (FR26); `value` is untouched until Save, so a discard restores it — closes the confirmation, and, once the confirmation has closed, returns focus to Clear all, which is now `aria-disabled` and still in the focus order, so it keeps focus as a control that becomes disabled does (`spec:AST-085/FR4`, WCAG 2.2 SC 2.4.3 through `spec:AST-020/FR1`); focus never moves to the search field, which would raise the on-screen keyboard over the rows just cleared; and announces "All items removed" inside the sheet (AR6); cancelling changes nothing and focus returns to Clear all the same way. Clear all stays visible and reachable while searching, since the footer is pinned (FR18). | DEC-3; touch-flow evidence | Verified current behavior. || FR25 | The result list follows `component:BaseTypeahead` FR12: a press on the field's input or its buttons, or in the list, keeps it open, and a press anywhere else closes it. | `component:BaseTypeahead` FR12 | Verified current behavior || FR26 | One open sheet edits one draft. The draft starts as `value` when the sheet opens and takes every row toggle, create, and Clear all (FR19, FR22, FR24); `value` and `onChange` are untouched while the sheet is open. Save closes the sheet; with an unchanged draft it reports nothing, and with a changed one it reports the whole draft once through `onChange(items, change)`, where `change` names the last edit that still holds: the last toggle, create, or clear when its item is in the draft and was not selected at open (`add`, or `create` for an item created in this sheet) or was selected at open and is not in the draft (`remove`); otherwise, when the last edit was a removal and some item selected at open is gone, a `remove` naming one such item; otherwise an `add` (`create` when the last edit created that item) naming an item in the draft that was not selected at open; otherwise a `remove` naming an item gone since open. A field that is disabled when Save fires reports nothing. A toggle is announced when it happens (AR6), not again on Save. | DEC-4 | Verified current behavior. || FR27 | Swipe, scrim, and Escape dismissal of the sheet close it directly while the draft equals the selection at open. While the draft differs, they open a discard confirmation inside the sheet — "Discard changes?", "Your changes to {label} haven't been saved." — with Discard changes as the destructive action and Keep editing as the safe one, which is focused first; Discard changes closes the sheet without reporting the draft, and Keep editing closes the confirmation and moves focus to the search field so editing resumes where the sheet's own reading order starts (`spec:AST-085/FR4`). The sheet's confirmations (this one and Clear all's, FR24) are one modal dialog shape: a title, a description, and two full-width large actions stacked in reading order — the destructive action, then the safe action, which takes focus first; the two actions are one action group (`family:action-groups`) while keeping their separated, full-width, stacked look; scrim and Escape take the safe action. A close the field forces (becoming disabled, FR17) asks nothing and reports nothing: the draft is dropped. | DEC-4 | Verified current behavior, with one implementation gap: the confirmation's two actions are separated Buttons, not yet one action group (`family:action-groups`). |diff --git a/packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx b/packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsxindex 0b945a1cd2..997a237701 100644--- a/packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx+++ b/packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx@@ -771,7 +771,7 @@ describe('Tokenizer sheet presentation (single-sheet touch flow)', () => {expect(screen.getAllByText('Design')).toHaveLength(1);});- it('mounts the Clear all confirmation only from the press until it closes: no alertdialog while none is pending, focus placed on cancel and on confirm (FR24; INV7)', async () => {+ it('mounts the Clear all confirmation only from the press until it closes: no alertdialog while none is pending, focus back on Clear all on cancel and on confirm (FR24; INV7)', async () => {const matches = Element.prototype.matches;const modalSpy = vi.spyOn(Element.prototype, 'matches')@@ -803,15 +803,15 @@ describe('Tokenizer sheet presentation (single-sheet touch flow)', () => {expect(clearAll).toHaveFocus();expect(screen.getByRole('checkbox', {name: 'Design'})).toBeChecked();- // Confirm: the confirmation goes, the search field takes focus, the- // clear is announced inside the sheet.+ // Confirm: the confirmation goes, Clear all keeps focus (now+ // aria-disabled), the clear is announced inside the sheet.fireEvent.click(clearAll);const second = await screen.findByRole('alertdialog');fireEvent.click(within(second).getByRole('button', {name: 'Clear selection'}),);await waitFor(noConfirmation);- expect(screen.getByLabelText('Search Tags')).toHaveFocus();+ expect(screen.getByRole('button', {name: 'Clear all'})).toHaveFocus();await waitFor(() =>expect(sheet.querySelector(@@ -886,7 +886,7 @@ describe('Tokenizer sheet presentation (single-sheet touch flow)', () => {expect(document.querySelector('[data-total-count]')).toBeNull();});- it('moves focus to the search field after a confirmed Clear all, since Clear all is disabled by then (FR24; AST-085 FR4)', async () => {+ it('keeps focus on Clear all after a confirmed Clear all — aria-disabled, in the focus order — and never moves it to the search field, which would raise the keyboard (FR24; AST-085 FR4)', async () => {render(<Harness />);fireEvent.click(openTrigger());await screen.findByRole('dialog', {name: 'Tags'});@@ -903,7 +903,8 @@ describe('Tokenizer sheet presentation (single-sheet touch flow)', () => {const clearAllAfter = screen.getByRole('button', {name: 'Clear all'});expect(clearAllAfter).toHaveAttribute('aria-disabled', 'true');expect(clearAllAfter).not.toBeDisabled();- expect(screen.getByLabelText('Search Tags')).toHaveFocus();+ expect(clearAllAfter).toHaveFocus();+ expect(screen.getByLabelText('Search Tags')).not.toHaveFocus();expect(document.activeElement).not.toBe(document.body);});@@ -3104,9 +3105,11 @@ describe('Tokenizer sheet under the BottomSheet stack (component:BottomSheet FR8await waitFor(() =>expect(screen.queryByRole('alertdialog')).not.toBeInTheDocument(),);- // Back in the field's sheet: focus on its search field, the sheet the+ // Back in the field's sheet: focus on its Clear all, the sheet the// outlet again, the host still covered beneath.- expect(screen.getByLabelText('Search Tags')).toHaveFocus();+ expect(+ within(sheet).getByRole('button', {name: 'Clear all'}),+ ).toHaveFocus();expect(getActiveModalOutlet()).toBe(sheet);expect(stackSummary()).toEqual(['Value:covered:1', 'Tags:top:0']);});diff --git a/packages/core/src/Tokenizer/TokenizerBottomSheet.tsx b/packages/core/src/Tokenizer/TokenizerBottomSheet.tsxindex 6d68af425d..44bc253e75 100644--- a/packages/core/src/Tokenizer/TokenizerBottomSheet.tsx+++ b/packages/core/src/Tokenizer/TokenizerBottomSheet.tsx@@ -354,10 +354,10 @@ function TokenizerSheetContent<T extends SearchableItem>({// has an entrance animation and no exit, so a close is its unmount; the// close handler commits that unmount at once and then places focus itself,// now that the modal is gone and the sheet's content can take focus again- // (`architecture:react-component-runtime` INV2): on the search field- // after a confirmed clear — the clear is spent, and the search field is- // where the next selection starts (FR24, `spec:AST-085` FR4) — and back on- // Clear all after a cancel. A confirmed clear is announced there too — a+ // (`architecture:react-component-runtime` INV2). After a clear, Clear all+ // is aria-disabled but stays focusable, so it keeps focus (FR24,+ // `spec:AST-085` FR4). Focus on the search field opens the on-screen+ // keyboard over the cleared rows. A confirmed clear is announced too — a// change the person hears about, as an add or a remove is// (`component:Tokenizer` AR6) — after the confirmation's dialog has gone,// so the sheet is the modal on top and the words are delivered inside it@@ -372,11 +372,9 @@ function TokenizerSheetContent<T extends SearchableItem>({const closeClearConfirmation = (confirmed: boolean) => {// eslint-disable-next-line @eslint-react/dom-no-flush-sync -- the confirmation must be gone before focus moves into the sheet and the words are routed into itflushSync(() => setIsClearConfirmationOpen(false));+ clearAllRef.current?.focus();if (confirmed) {- searchRef.current?.focus();announce(t('@astryx.tokenizer.allRemoved'));- } else {- clearAllRef.current?.focus();}};// Keep editing: the confirmation is gone, and focus returns to the search@@ -1000,11 +998,9 @@ function TokenizerSheetContent<T extends SearchableItem>({variant="secondary"size="lg"isDisabled={draftValue.length === 0}- // With a tooltip, Button's disabled mode is `aria-disabled`: the- // action keeps its focus order and says why it does nothing- // (`spec:AST-085` FR1), instead of leaving the tab order as a- // natively disabled button does — a confirmed Clear all returns- // focus here before the search field takes it (FR24).+ // With a tooltip, Button uses aria-disabled, so Clear all stays+ // focusable after a clear and says why it does nothing+ // (`spec:AST-085` FR1; FR24).tooltip={draftValue.length === 0? t('@astryx.tokenizer.nothingToClear')