@astryxdesign/core 0.7.2-canary.c5f72ea → 0.7.2-canary.f16dc9f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/Selector/hooks.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AACrC,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,SAAS,CAAC;AAyBhD,UAAU,4BAA4B;IACpC,MAAM,EAAE,OAAO,CAAC;IAChB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAC7C,SAAS,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;CAC1C;AAED,UAAU,2BAA2B;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,OAAO,CAAC;CACvB;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,MAAM,EACN,iBAAiB,EACjB,SAAS,EACT,UAAU,EACV,SAAS,GACV,EAAE,4BAA4B,GAAG,2BAA2B,CAgF5D;AAMD,UAAU,kBAAkB;IAC1B,eAAe,EAAE,kBAAkB,EAAE,CAAC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,MAAM,OAAO,CAAC;IACtB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB;;;;;OAKG;IACH,YAA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M,EACN,SAAiB,EACjB,MAAM,EACN,OAAO,EACP,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,SAAS,GACV,EAAE,kBAAkB,GAAG,iBAAiB,CAqOxC"}
@@ -6,8 +6,12 @@
6
6
  * @file hooks.ts
7
7
  * @input Uses untransformed DOM layout geometry from the Selector's outer
8
8
  * anchor, listbox, and selected option
9
- * @output Hooks for Selector
10
- * @position Internal hooks; used by Selector.tsx
9
+ * @output Hooks for Selector: useSelectedItemOffset, and useCombobox (public,
10
+ * exported from the Selector entry point; also used by CommandPalette)
11
+ * @position Selector hooks; used by Selector.tsx and CommandPalette
12
+ *
13
+ * SYNC: When useCombobox's options or return change, update:
14
+ * - /packages/core/src/Selector/useCombobox.doc.mjs
11
15
  */
12
16
  import { useCallback, useState } from 'react';
13
17
  import { useHighlightedOptionScroll } from "../hooks/useHighlightedOptionScroll.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/core",
3
- "version": "0.7.2-canary.c5f72ea",
3
+ "version": "0.7.2-canary.f16dc9f",
4
4
  "displayName": "Astryx Core",
5
5
  "description": "The component library. Accessible, themeable React components with built-in spacing, dark mode, and StyleX styling.",
6
6
  "author": "Meta Open Source",
@@ -787,8 +787,8 @@
787
787
  "react-dom": ">=19.0.0"
788
788
  },
789
789
  "devDependencies": {
790
- "@astryxdesign/a11y-spec": "0.7.2-canary.c5f72ea",
791
- "@astryxdesign/cli": "0.7.2-canary.c5f72ea",
790
+ "@astryxdesign/a11y-spec": "0.7.2-canary.f16dc9f",
791
+ "@astryxdesign/cli": "0.7.2-canary.f16dc9f",
792
792
  "@babel/cli": "^7.29.7",
793
793
  "@babel/core": "^7.29.7",
794
794
  "@babel/preset-react": "^7.29.7",
@@ -6,8 +6,12 @@
6
6
  * @file hooks.ts
7
7
  * @input Uses untransformed DOM layout geometry from the Selector's outer
8
8
  * anchor, listbox, and selected option
9
- * @output Hooks for Selector
10
- * @position Internal hooks; used by Selector.tsx
9
+ * @output Hooks for Selector: useSelectedItemOffset, and useCombobox (public,
10
+ * exported from the Selector entry point; also used by CommandPalette)
11
+ * @position Selector hooks; used by Selector.tsx and CommandPalette
12
+ *
13
+ * SYNC: When useCombobox's options or return change, update:
14
+ * - /packages/core/src/Selector/useCombobox.doc.mjs
11
15
  */
12
16
 
13
17
  import {useCallback, useState} from 'react';
@@ -0,0 +1,237 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('@astryxdesign/cli/authoring').HookDoc} */
4
+ export const docs = {
5
+ name: 'useCombobox',
6
+ displayName: 'useCombobox',
7
+ group: 'Selector',
8
+ keywords: [
9
+ 'combobox',
10
+ 'listbox',
11
+ 'select',
12
+ 'dropdown',
13
+ 'highlight',
14
+ 'active option',
15
+ 'aria-activedescendant',
16
+ 'keyboard',
17
+ 'arrow keys',
18
+ 'headless',
19
+ 'apg',
20
+ 'accessibility',
21
+ 'a11y',
22
+ ],
23
+ params: [
24
+ {
25
+ name: 'options',
26
+ type: 'UseComboboxOptions',
27
+ description: 'Configuration object.',
28
+ required: true,
29
+ },
30
+ {
31
+ name: 'options.selectableItems',
32
+ type: 'SelectorOptionData[]',
33
+ description:
34
+ 'The options in the same order as they render. Options with `disabled` cannot be picked and are skipped while moving through the open list; ArrowDown or ArrowUp that opens the list still lands on the first or last option.',
35
+ required: true,
36
+ },
37
+ {
38
+ name: 'options.isOpen',
39
+ type: 'boolean',
40
+ description: 'Whether the list is shown. The caller owns this state.',
41
+ required: true,
42
+ },
43
+ {
44
+ name: 'options.onOpen',
45
+ type: '() => unknown',
46
+ description:
47
+ 'Called to show the list. Return `false` to refuse; the hook then leaves the highlight alone.',
48
+ required: true,
49
+ },
50
+ {
51
+ name: 'options.onClose',
52
+ type: '() => void',
53
+ description:
54
+ 'Called when the hook hides the list; the hook resets the highlight first. When the caller closes the list itself (an outside press, say), it should also call `setHighlightedIndex(-1)`.',
55
+ required: true,
56
+ },
57
+ {
58
+ name: 'options.listboxId',
59
+ type: 'string',
60
+ description:
61
+ "The listbox element's id. Option ids are derived from it through `getItemId`.",
62
+ required: true,
63
+ },
64
+ {
65
+ name: 'options.value',
66
+ type: 'string',
67
+ description:
68
+ 'The selected value. Without search, opening by a press, Enter or Space highlights it, or the first option when nothing is selected; ArrowDown and ArrowUp open on the first and last option.',
69
+ },
70
+ {
71
+ name: 'options.onSelect',
72
+ type: '(value: string) => void',
73
+ description:
74
+ 'Called with the picked value. Picking also closes the list.',
75
+ },
76
+ {
77
+ name: 'options.onClear',
78
+ type: '() => void',
79
+ description:
80
+ 'Clears the value. When provided, Delete or Backspace on the closed control clears it, so clearing is not pointer-only. Ignored while the list is open or with `hasSearch`.',
81
+ },
82
+ {
83
+ name: 'options.hasSearch',
84
+ type: 'boolean',
85
+ description:
86
+ 'Whether the list has its own search field. Space then types instead of picking, opening by a press or Enter does not pre-highlight (ArrowDown and ArrowUp still open on the first and last option), and printable keys on the closed control go to `onSearchSeed`.',
87
+ default: 'false',
88
+ },
89
+ {
90
+ name: 'options.onSearchSeed',
91
+ type: '(char: string) => void',
92
+ description:
93
+ 'With `hasSearch`, receives each printable character except Space typed while the control has focus, opening the list first when it is closed, so type-to-find needs no separate open step.',
94
+ },
95
+ {
96
+ name: 'options.isDisabled',
97
+ type: 'boolean',
98
+ description: 'Whether the control ignores clicks and keys.',
99
+ default: 'false',
100
+ },
101
+ ],
102
+ returns: [
103
+ {
104
+ name: 'highlightedIndex',
105
+ type: 'number',
106
+ description:
107
+ 'Index of the active option, or -1 when none is active. With `hasSearch`, opening by a press or Enter does not set one, so it stays -1 after the hook itself closes the list; ArrowDown and ArrowUp still open on the first or last option. Render it as the active option and name it in `aria-activedescendant` only while it points at a rendered option.',
108
+ },
109
+ {
110
+ name: 'setHighlightedIndex',
111
+ type: '(index: number) => void',
112
+ description:
113
+ 'Sets the active option, for example from a filter that changes the options.',
114
+ },
115
+ {
116
+ name: 'getItemId',
117
+ type: '(index: number) => string',
118
+ description:
119
+ "The id to render on the option at `index`. Set the control's `aria-activedescendant` to `isOpen && highlightedIndex >= 0 && highlightedIndex < selectableItems.length ? getItemId(highlightedIndex) : undefined`, so it never names an option that does not exist, including in an empty list.",
120
+ },
121
+ {
122
+ name: 'onTriggerClick',
123
+ type: '() => void',
124
+ description: 'Toggles the list from a press on the control.',
125
+ },
126
+ {
127
+ name: 'onKeyDown',
128
+ type: '(e: React.KeyboardEvent) => void',
129
+ description:
130
+ 'Key handler for the control that keeps focus. ArrowDown and ArrowUp open the list or move the active option; Enter (and Space without search) picks it or opens the list; Escape and Tab close it; Home, End, PageUp and PageDown jump to the first or last option. An editable control that keeps Home and End for the caret does not pass them to this handler, as CommandPalette does.',
131
+ },
132
+ {
133
+ name: 'onItemSelect',
134
+ type: '(item: SelectorOptionData) => void',
135
+ description: 'Picks an option from a press on it, then closes the list.',
136
+ },
137
+ {
138
+ name: 'onItemMouseEnter',
139
+ type: '(item: SelectorOptionData, index: number) => void',
140
+ description:
141
+ 'Makes the hovered option active without scrolling the list or moving focus.',
142
+ },
143
+ ],
144
+ usage: {
145
+ description:
146
+ 'Tracks the active option of a single-select combobox and handles its keys, while DOM focus stays on the control. It powers Selector and CommandPalette; use it to build a combobox those components do not cover. It renders nothing and sets no attributes: the caller renders the control, the listbox and the options, and wires `role`, `aria-expanded`, `aria-controls` and `aria-activedescendant` from what it returns.',
147
+ bestPractices: [
148
+ {
149
+ guidance: true,
150
+ description:
151
+ "Render each option with `id={getItemId(index)}` and set the control's `aria-activedescendant` only while `isOpen` and `highlightedIndex` points at a rendered option, as CommandPalette does.",
152
+ },
153
+ {
154
+ guidance: true,
155
+ description:
156
+ "For type-to-select without a search field, run useTypeahead's handler first and fall through to this `onKeyDown` when it returns false, as Selector does.",
157
+ },
158
+ {
159
+ guidance: true,
160
+ description:
161
+ 'Announce the number of results through useAnnounce when the options change for a new query.',
162
+ },
163
+ {
164
+ guidance: false,
165
+ description:
166
+ 'Move DOM focus onto the options; the active option is announced through `aria-activedescendant` while focus stays on the control.',
167
+ },
168
+ ],
169
+ },
170
+ relatedComponents: ['Selector', 'CommandPalette'],
171
+ relatedHooks: ['useMultiCombobox', 'useTypeahead', 'useAnnounce'],
172
+ importPath: '@astryxdesign/core/Selector',
173
+ category: 'focus',
174
+ };
175
+
176
+ /** @type {import('@astryxdesign/cli/authoring').HookTranslationDoc} */
177
+ export const docsDense = {
178
+ description:
179
+ 'Single-select combobox state + keys; focus stays on control. Powers Selector / CommandPalette. Renders nothing, sets no attrs: caller renders control / listbox / options and wires role, aria-expanded, aria-controls, aria-activedescendant.',
180
+ paramDescriptions: {
181
+ options: 'config.',
182
+ 'options.selectableItems':
183
+ 'options in render order; disabled ones not pickable, skipped while moving in open list (ArrowDown/Up opening still lands first / last).',
184
+ 'options.isOpen': 'list shown; caller owns state.',
185
+ 'options.onOpen':
186
+ 'show list; return false to refuse (highlight untouched).',
187
+ 'options.onClose':
188
+ 'hook hides list; resets highlight first. caller closing itself (outside press): also setHighlightedIndex(-1).',
189
+ 'options.listboxId': 'listbox id; option ids derive from it (getItemId).',
190
+ 'options.value':
191
+ 'selected value; w/o search, press / Enter / Space opening highlights it (else first); ArrowDown/Up open on first / last.',
192
+ 'options.onSelect': 'called w/ picked value; picking closes.',
193
+ 'options.onClear':
194
+ 'clears value; Delete / Backspace on closed control. ignored when open or hasSearch.',
195
+ 'options.hasSearch':
196
+ 'list has own search field: Space types, press / Enter opening does not pre-highlight (ArrowDown/Up still first / last), printable keys on closed control -> onSearchSeed.',
197
+ 'options.onSearchSeed':
198
+ 'w/ hasSearch, each printable char except Space typed while control focused (opens first if closed).',
199
+ 'options.isDisabled': 'ignore clicks + keys.',
200
+ },
201
+ returnDescriptions: {
202
+ highlightedIndex:
203
+ 'active option index, -1 = none. hasSearch: press / Enter opening sets none (stays -1 after hook closes); ArrowDown/Up still first / last. name in aria-activedescendant only when it points at a rendered option.',
204
+ setHighlightedIndex: 'set active option (e.g. after filtering).',
205
+ getItemId:
206
+ 'id for option at index; aria-activedescendant = isOpen && highlightedIndex >= 0 && highlightedIndex < selectableItems.length ? getItemId(highlightedIndex) : undefined (empty list safe).',
207
+ onTriggerClick: 'toggle list from a press on control.',
208
+ onKeyDown:
209
+ 'control keydown: ArrowDown/Up open or move; Enter (Space w/o search) picks or opens; Escape / Tab close; Home / End / PageUp / PageDown jump. editable control keeping Home / End for caret: do not pass them.',
210
+ onItemSelect: 'pick from a press, then close.',
211
+ onItemMouseEnter: 'hover makes option active; no scroll, no focus move.',
212
+ },
213
+ usage: {
214
+ description:
215
+ 'Headless single-select combobox: active option + keys, focus stays on control. Caller renders + wires ARIA.',
216
+ bestPractices: [
217
+ {
218
+ guidance: true,
219
+ description:
220
+ 'Option id = getItemId(index); aria-activedescendant only while open and highlightedIndex points at a rendered option.',
221
+ },
222
+ {
223
+ guidance: true,
224
+ description:
225
+ 'Type-to-select w/o search: run useTypeahead first, fall through when it returns false.',
226
+ },
227
+ {
228
+ guidance: true,
229
+ description: 'Announce result count via useAnnounce on new query.',
230
+ },
231
+ {
232
+ guidance: false,
233
+ description: 'Move DOM focus onto options; use aria-activedescendant.',
234
+ },
235
+ ],
236
+ },
237
+ };