Skip to content

Commit 617f8cc

Browse files
committed
feat(Typeahead, Tokenizer): open on a package-internal opening query
BaseTypeahead, Typeahead and Tokenizer read a package-internal opening query, so a Core owner can open a value editor on text the person typed (component:BaseTypeahead FR18, component:Typeahead FR14, component:Tokenizer FR31). No caller prop, handle method or export is added. - BaseTypeahead mounts holding the text with the caret at its end. Its search waits for the threshold and the debounce like a keystroke's, and the list opens only once the input has focus. A field that mounts with a selected value (Typeahead's token) reads none. - Tokenizer's inline input holds it as BaseTypeahead does. The sheet's first open after mount searches it instead of listing the bootstrap set, also after an adaptive swap, and a close clears it. - The same input can open Tokenizer's sheet as it mounts. That Tokenizer renders only its sheet, returns focus to the owner's element, and tells the owner once the exit has completed. A field disabled at mount opens none. BaseTypeahead FR18 and Tokenizer FR31 name the OpeningQueryContext module and its members, and the three status cells move from the implementation gap to current behavior.
1 parent b05e2e3 commit 617f8cc

12 files changed

Lines changed: 860 additions & 99 deletions
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+
[chore] Internal: `BaseTypeahead`, `Typeahead`, and `Tokenizer` can mount holding an opening query that another Core component passes them through a package-internal context, so PowerSearch can open a value editor on text the person typed (`component:BaseTypeahead` FR18, `component:Typeahead` FR14, `component:Tokenizer` FR31). The input holds the text as if typed and searches it only after the threshold and the debounce, once it has focus; a Tokenizer's sheet starts its first open after mount searching it, or opens as the Tokenizer mounts (a Tokenizer disabled at mount opens none). No prop, handle method, export, or rendered output changes for callers.
6+
7+
@imdreamrunner

‎docs/specs/components/Tokenizer/Tokenizer.spec.md‎

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

‎docs/specs/components/Typeahead/BaseTypeahead.spec.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Consumer migration instructions belong in consumer docs and release notes.
132132
| FR15 | When a dialog-role menu closes (Escape, an outside press, `close`), focus returns to the element that had focus when the menu was asked to open (`open()` called, or the menu shown), or to the input when that element is gone. A press outside that moves focus to another control leaves it there. A focus return to the input does not open the list. | DEC-1 |
133133
| FR16 | `handleRef` exposes `open()` and `close()`, and `onOpenChange` reports each open and close; there is no controlled open state (DEC-1). `open()` runs after the commit it is called in, so it uses the menu the caller rendered in the same event: a dialog opens at once, and a listbox shows its results, loading them first if needed. A pick whose `onChange` calls `open()` keeps the menu open, so switching from the list to a dialog keeps the same layer on the same anchor without closing it. When the menu stays a listbox after such a pick, focus returns to the input and the list loads its focus entries, or closes when there are none. | DEC-1 |
134134
| FR17 | Each result option row carries the `typeahead-option` target with `size`, `highlighted` and `selected` reflections. `highlighted` marks the active option, the one `aria-activedescendant` names, so a theme can style the option the keyboard or pointer is on; result content inside the row keeps its own target (`typeahead-item`). | `architecture:public-component-api` DEC-2; `architecture:component-theming-surface`; current tests |
135-
| FR18 | A Core owner in the same package can open the input with an opening query, a package-internal input that `component:PowerSearch` FR29 and FR30 use to open a value editor on the text a "More" row carries; a caller has no prop for it. The input mounts holding that text, with the caret at its end, as if the person had typed it: FR2's threshold and debounce, FR3, and FR10 apply to it as to typed text, and the list opens once the input has focus, as typing opens it. The input reads the opening query once, when it mounts: a later change does nothing until the input mounts again, and the person's edits replace the text as they replace typed text. Implementation gap: the input always mounts empty. | `component:PowerSearch` FR29, FR30; `spec:AST-002/DEC-1` |
135+
| FR18 | A Core owner in the same package can open the input with an opening query, a package-internal input that `component:PowerSearch` FR29 and FR30 use to open a value editor on the text a "More" row carries; a caller has no prop for it. The input mounts holding that text, with the caret at its end, as if the person had typed it: FR2's threshold and debounce, FR3, and FR10 apply to it as to typed text, and the list opens once the input has focus, as typing opens it. The input reads the opening query once, when it mounts: a later change does nothing until the input mounts again, and the person's edits replace the text as they replace typed text. The owner provides it through `OpeningQueryContext` (`Typeahead/OpeningQueryContext.ts`), a package-internal context that BaseTypeahead and Tokenizer read, with `query` and, for `component:Tokenizer/FR31`, `sheet`: no existing internal context carries text into a field's input, and a prop on the re-exported props types would ship as public API. | `component:PowerSearch` FR29, FR30; `spec:AST-002/DEC-1` |
136136

137137
### Allowed variation
138138

‎docs/specs/components/Typeahead/Typeahead.spec.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ BaseTypeahead and TypeaheadItem keep their own records. `menu`, `handleRef`
118118
| FR11 | `menu` and `handleRef` reach BaseTypeahead unchanged, so the menu's listbox and dialog roles, its open handle and its focus return follow `component:BaseTypeahead` FR13–FR16, and `onOpenChange` reports the same opens and closes. | `component:BaseTypeahead` FR13–FR16 |
119119
| FR12 | Backspace or Delete on the focused Token's button acts on the selected value. With `hasClear`, it clears the value as the clear button does: `onChange(null)`, a polite announcement that names the cleared value through the shared live region, and focus on the empty input, as a Tokenizer token's removal does. Without `hasClear`, it enters edit mode, as a click on the Token does. A disabled field ignores both keys. | Current tests |
120120
| FR13 | Each result option row carries the `typeahead-option` target with `size`, `highlighted` and `selected` reflections. `highlighted` marks the active option, the one `aria-activedescendant` names, so a theme can style the option the keyboard or pointer is on, as it can an Item or CommandPaletteItem row; the default content inside the row keeps `typeahead-item`. | `architecture:public-component-api` DEC-2; `component:BaseTypeahead` FR17 |
121-
| FR14 | Typeahead takes the package-internal opening query of `component:BaseTypeahead` FR18 and passes it to its BaseTypeahead, so `component:PowerSearch` FR29 and FR30 can open a `string` search-source editor on the text a "More" row carries; a caller has no prop for it. An empty field mounts with its input holding that text, searched as BaseTypeahead FR18 states. A field that mounts with a selected value shows its Token (FR8) and does not read the opening query. Implementation gap: the input always mounts empty. | `component:BaseTypeahead` FR18; `component:PowerSearch` FR29, FR30 |
121+
| FR14 | Typeahead takes the package-internal opening query of `component:BaseTypeahead` FR18 and passes it to its BaseTypeahead, so `component:PowerSearch` FR29 and FR30 can open a `string` search-source editor on the text a "More" row carries; a caller has no prop for it. An empty field mounts with its input holding that text, searched as BaseTypeahead FR18 states. A field that mounts with a selected value shows its Token (FR8) and does not read the opening query. | `component:BaseTypeahead` FR18; `component:PowerSearch` FR29, FR30 |
122122
| FR15 | A status paints the status border. Outside InputGroup, `attached` and `tooltip` placement show a trailing status icon in the end controls, after the clear button; `detached` placement shows its glyph only in the message box; inside InputGroup no status icon renders. `tooltip` renders no message box, and with a message its status icon is a focusable button whose tooltip holds the message and describes the input; hover, keyboard focus, or a tap reveals it, and a click on it keeps focus on it. A click on the plain `attached` icon moves focus to the input, as a click elsewhere in the field does. The input's description names the message box only when one renders. | `family:input-fields` FR8; `component:TextInput` FR9 |
123123

124124
### Allowed variation

‎packages/core/src/Tokenizer/Tokenizer.test.tsx‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import userEvent from '@testing-library/user-event';
2525
import {Tokenizer, type TokenizerHandle} from './Tokenizer';
2626
import {Typeahead} from '../Typeahead/Typeahead';
2727
import {TokenizerItemRemovableContext} from './TokenizerItemRemovableContext';
28+
import {OpeningQueryContext} from '../Typeahead/OpeningQueryContext';
2829
import {InputGroup} from '../InputGroup/InputGroup';
2930
import {InputGroupText} from '../InputGroup/InputGroupText';
3031
import {__resetLiveRegionsForTest} from '../hooks/useAnnounce';
@@ -4719,3 +4720,37 @@ describe('Tokenizer locked tokens (internal removable context)', () => {
47194720
expect(onChange).not.toHaveBeenCalled();
47204721
});
47214722
});
4723+
4724+
describe('Tokenizer opening query (component:Tokenizer FR31)', () => {
4725+
const tags: SearchableItem[] = [
4726+
{id: 'design', label: 'Design'},
4727+
{id: 'eng', label: 'Eng'},
4728+
{id: 'energy', label: 'Energy'},
4729+
];
4730+
4731+
it('mounts the inline input holding the opening query and searches it once focused', async () => {
4732+
const search = vi.fn((query: string) =>
4733+
tags.filter(item =>
4734+
item.label.toLowerCase().includes(query.toLowerCase()),
4735+
),
4736+
);
4737+
render(
4738+
<OpeningQueryContext value={{query: 'en'}}>
4739+
<Tokenizer
4740+
label="Tags"
4741+
searchSource={{search, bootstrap: () => tags}}
4742+
value={[]}
4743+
onChange={() => {}}
4744+
debounceMs={0}
4745+
presentation="popover"
4746+
/>
4747+
</OpeningQueryContext>,
4748+
);
4749+
const input = screen.getByRole('combobox');
4750+
expect(input).toHaveValue('en');
4751+
expect(search).not.toHaveBeenCalled();
4752+
act(() => input.focus());
4753+
await screen.findByRole('option', {name: 'Eng', hidden: true});
4754+
expect(search).toHaveBeenLastCalledWith('en', expect.anything());
4755+
});
4756+
});

0 commit comments

Comments
 (0)