Repository navigation
feat(core): add XDSTypeahead and XDSTokenizer components - #299
Conversation
8578915 to
e06778e
Compare
ad95f43 to
445c750
Compare
czarandy
left a comment
There was a problem hiding this comment.
approving since it seems overall good but maybe some of the comments could be good to address?
|
|
||
| searchTimeoutRef.current = setTimeout(() => { | ||
| if (newQuery.length > 0) { | ||
| performSearch(newQuery); |
There was a problem hiding this comment.
we may want to either add caching here or else recommend that the search source implementation has its own caching
There was a problem hiding this comment.
Good call — added a JSDoc note on search() recommending that implementations cache internally for expensive operations. Also added a cancel() method to the interface (see below) which pairs well with this: cancel the old request, then search again.
| } else if (hasEntriesOnFocus) { | ||
| performBootstrap(); | ||
| } | ||
| }, 150); |
There was a problem hiding this comment.
should this debounce be configurable?
I'm also wondering if it makes sense to move the debounce logic into the search source itself. For example if you have a local search source there's no reason to wait an extra 150ms, it only really makes sense for expensive calls that you want to avoid. So it may be more appropriate to have the UI component just do a direct call and the search source handles debouncing. We could offer a XDSAsyncSearchSource that provides that service.
or maybe I am wrong and we do want debouncing even for local data (but then maybe a smaller delay)? curious as to your thoughts
There was a problem hiding this comment.
Great point — debounce is now configurable via debounceMs prop (default 150). Setting it to 0 skips the timeout entirely, which makes sense for local/synchronous sources. Exposed on XDSTypeahead, XDSTokenizer, and XDSBaseTypeahead.
I kept the debounce in the UI component rather than moving it to the search source — felt like the simpler default since most consumers just want "type → results" without thinking about debouncing. But a search source can always do its own debouncing internally and set debounceMs={0} on the component.
| [listboxId], | ||
| ); | ||
|
|
||
| // Cleanup timeout on unmount |
There was a problem hiding this comment.
it could also be good to add a cancel() API to the search source, so that any backend query that allows cancel behavior could use that. For example if using the fetch() API you can use AbortController to cancel. In any case it doesn't seem to hurt to have it, if not implemented it would just do nothing.
There was a problem hiding this comment.
Done — added cancel?(): void to XDSSearchSource. It's optional so existing sources don't break. The component calls it:
- Before each new search (so the old one can abort)
- When the dropdown hides
- On unmount
Updated the JSDoc example to show the AbortController pattern.
| !isEmbedded && styles.wrapper, | ||
| !isEmbedded && sizeStyle, | ||
| isDisabled && styles.wrapperDisabled, | ||
| isEmbedded && styles.wrapperEmbedded, | ||
| !isEmbedded && statusType && statusBorderStyles[statusType], | ||
| !isEmbedded && statusType && statusHoverShadowStyles[statusType], | ||
| !isEmbedded && statusType && statusFocusStyles[statusType], |
There was a problem hiding this comment.
it may be nicer to read if you combine all the !isEmbedded into a single item that returns an array
There was a problem hiding this comment.
Done — extracted a wrapperStyles array that branches once on isEmbedded, so the stylex.props() call is now just ...wrapperStyles, isDisabled && styles.wrapperDisabled. Much easier to read.
| /** | ||
| * Additional StyleX styles for the input wrapper. | ||
| */ | ||
| wrapperXstyle?: StyleXStyles; |
There was a problem hiding this comment.
should this be capitalized XStyle? that's how we do it in XDS on www right now
There was a problem hiding this comment.
Yep, you're right — renamed to wrapperXStyle and inputXStyle to match the XDS convention.
e06778e to
66bd264
Compare
cixzhang
left a comment
There was a problem hiding this comment.
Addressed all 5 comments — see replies on each thread. Also rebased onto main (was stacked on popover branch but doesn't depend on it). Summary of changes:
- Caching — Added JSDoc on
search()recommending internal caching for expensive sources - Debounce — New
debounceMsprop (default 150, set to 0 for local sources). Exposed on all three components. - Cancel API — Added optional
cancel?()toXDSSearchSource. Called before new searches, on dropdown hide, and on unmount. JSDoc example shows AbortController pattern. - !isEmbedded consolidation — Extracted
wrapperStylesarray that branches once onisEmbedded - XStyle capitalization — Renamed
wrapperXstyle→wrapperXStyle,inputXstyle→inputXStyle
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR New ComponentsTokenizer · View in Storybook
Typeahead · View in Storybook
Modified ComponentsToken · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 1 accessibility violation(s) found — 1 serious. XDSToken - 1 issue(s)
Component PreviewsIncludes interactive hover previews as animated GIFs. XDSTokenXDSTokenizerDefaultScreenshot: Interaction Preview: (view video) View in Storybook · XDSTypeaheadDefaultScreenshot: Interaction Preview: (view video) View in Storybook · Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
|
🔴 CI: The Typeahead/Tokenizer components reference a — Navi (after-hours CI triage) |
294e8c3 to
58f5a94
Compare
cixzhang
left a comment
There was a problem hiding this comment.
Lightweight Night Watch review — found :hover styles missing @media (hover: hover) guards.
XDSTextInput and XDSToken already use the guarded pattern for the same styles (border-color, box-shadow, opacity). Without the guard, hover states will "stick" on touch devices after a tap.
Pattern to follow (from XDSTextInput):
':hover': {
'@media (hover: hover)': colorVars['--color-divider-high-contrast'],
},Same issue appears in both XDSBaseTypeahead.tsx and XDSTokenizer.tsx — 6 instances each (wrapper borderColor, wrapper boxShadow, clearButton opacity, and the 3 status hover shadows).
| borderStyle: 'solid', | ||
| borderColor: { | ||
| default: colorVars['--color-divider-emphasized'], | ||
| ':hover': colorVars['--color-divider-high-contrast'], |
There was a problem hiding this comment.
Missing @media (hover: hover) guard — will cause sticky hover on touch devices.
XDSTextInput uses the guarded pattern for this same style:
':hover': {
'@media (hover: hover)': colorVars['--color-divider-high-contrast'],
},Same applies to the boxShadow hover on line 215, clearButton opacity hover on line 320, and all three status hover shadows (lines 353, 359, 365).
| borderRadius: radiusVars['--radius-element'], | ||
| backgroundColor: colorVars['--color-surface'], | ||
| transitionProperty: 'border-color, outline, box-shadow', | ||
| transitionDuration: transitionVars['--transition-fast'], |
There was a problem hiding this comment.
Same hover guard issue here — XDSTokenizer duplicates the wrapper styles from XDSBaseTypeahead without @media (hover: hover) guards. All 6 :hover styles in this file need the guard (borderColor, boxShadow, clearAllButton opacity, and status shadows).
🤖 Night Watch QA Report
|
7716829 to
71924e5
Compare
❌ Visual Regression — FailedScreenshots differ from baselines for: XDSTokenizer, XDSBaseTypeahead, XDSTypeahead, XDSTypeaheadItem, XDSToken View diff artifacts to review the visual changes.
|
|
Re-triggering CI |
Searchable combobox (XDSTypeahead) and multi-select token input (XDSTokenizer), built on a shared XDSBaseTypeahead engine. XDSTypeahead: - Search-as-you-type with keyboard navigation - Async and sync search via XDSSearchSource interface - Bootstrap results on focus, debounced search - Selected value shown as Token chip with clear - Status border styles (error/warning/success) XDSTokenizer: - Multi-select with inline token chips and remove buttons - Filters already-selected items from search results - Max entries support with graceful input collapse - Clear all button, backspace to remove last token - Custom token and item rendering Shared: - XDSBaseTypeahead: unstyled combobox with useXDSLayer positioning - XDSTypeaheadItem: default dropdown item renderer - XDSSearchSource/XDSSearchableItem: generic search interface - Full ARIA combobox pattern with activedescendant - @media (hover: hover) guards on all :hover styles Includes unit tests and Storybook stories for both components.
eb5fb56 to
13c9041
Compare
…ource - Token spacing compensation: wrap selected token in tokenContainer with negative margin matching the Tokenizer pattern (equidistant from edges) - Editable typeahead: clicking the token or input enters edit mode — removes token, populates input with the value's label text, selects all. Blurring without selecting restores the original token. Escape also restores. - Storybook source fix: rewrite stories to use args-based pattern with inline render functions instead of wrapper components, so the source code panel shows actual component usage instead of opaque helper calls. - Add 3 tests for edit mode behavior (enter, restore on blur, container click) Co-authored-by: Navi <[email protected]>
…nsumers XDSBaseTypeahead is now a pure combobox engine — just the input, search, keyboard navigation, and dropdown. No wrapper div, no border styling, no token rendering, no edit mode, no isEmbedded flag. Consumers provide their own wrapper and pass anchorRef for dropdown positioning: - XDSTypeahead: owns wrapper div with borders, status styles, padding, token with spacing compensation, edit mode (click to edit, blur to restore, escape to cancel) - XDSTokenizer: already owned its wrapper, now passes wrapperRef as anchorRef instead of using isEmbedded Removed from base: isEmbedded, wrapperXStyle, statusType, startContent, hasClear, size, wrapper/token/status styles. Added to base: anchorRef (RefObject) for dropdown positioning. Falls back to the input element itself if not provided. Co-authored-by: Navi <[email protected]>
After selecting an item via keyboard, focus the token's internal button so keyboard users stay in the component. The token uses onClick to enable its internal button (keyboard-focusable), and Enter/Space on the focused token enters edit mode. Also simplified token rendering — removed tokenContainer wrapper div in favor of xstyle prop on XDSToken directly for spacing compensation. Co-authored-by: Navi <[email protected]>
|
Landing this for now, but we should create a new issue to fix the tokenizer -- the typeahead input width is still taking up a bit too much room once tokens are added, placeholder appears cut off with tokens, height when there are multiple lines appears too short. We will also eventually want a horizontal overflow to limit the tokenizer to 1 line when not in focus to save space in some cases. |
* feat(core): add XDSTypeahead and XDSTokenizer components Searchable combobox (XDSTypeahead) and multi-select token input (XDSTokenizer), built on a shared XDSBaseTypeahead engine. XDSTypeahead: - Search-as-you-type with keyboard navigation - Async and sync search via XDSSearchSource interface - Bootstrap results on focus, debounced search - Selected value shown as Token chip with clear - Status border styles (error/warning/success) XDSTokenizer: - Multi-select with inline token chips and remove buttons - Filters already-selected items from search results - Max entries support with graceful input collapse - Clear all button, backspace to remove last token - Custom token and item rendering Shared: - XDSBaseTypeahead: unstyled combobox with useXDSLayer positioning - XDSTypeaheadItem: default dropdown item renderer - XDSSearchSource/XDSSearchableItem: generic search interface - Full ARIA combobox pattern with activedescendant - @media (hover: hover) guards on all :hover styles Includes unit tests and Storybook stories for both components. * fix(typeahead): spacing compensation, editable token, and storybook source - Token spacing compensation: wrap selected token in tokenContainer with negative margin matching the Tokenizer pattern (equidistant from edges) - Editable typeahead: clicking the token or input enters edit mode — removes token, populates input with the value's label text, selects all. Blurring without selecting restores the original token. Escape also restores. - Storybook source fix: rewrite stories to use args-based pattern with inline render functions instead of wrapper components, so the source code panel shows actual component usage instead of opaque helper calls. - Add 3 tests for edit mode behavior (enter, restore on blur, container click) Co-authored-by: Navi <[email protected]> * refactor(typeahead): move wrapper and token ownership from base to consumers XDSBaseTypeahead is now a pure combobox engine — just the input, search, keyboard navigation, and dropdown. No wrapper div, no border styling, no token rendering, no edit mode, no isEmbedded flag. Consumers provide their own wrapper and pass anchorRef for dropdown positioning: - XDSTypeahead: owns wrapper div with borders, status styles, padding, token with spacing compensation, edit mode (click to edit, blur to restore, escape to cancel) - XDSTokenizer: already owned its wrapper, now passes wrapperRef as anchorRef instead of using isEmbedded Removed from base: isEmbedded, wrapperXStyle, statusType, startContent, hasClear, size, wrapper/token/status styles. Added to base: anchorRef (RefObject) for dropdown positioning. Falls back to the input element itself if not provided. Co-authored-by: Navi <[email protected]> * fix(typeahead): maintain focus on token after keyboard selection After selecting an item via keyboard, focus the token's internal button so keyboard users stay in the component. The token uses onClick to enable its internal button (keyboard-focusable), and Enter/Space on the focused token enters edit mode. Also simplified token rendering — removed tokenContainer wrapper div in favor of xstyle prop on XDSToken directly for spacing compensation. Co-authored-by: Navi <[email protected]> --------- Co-authored-by: Navi <[email protected]>
* feat(core): add XDSTypeahead and XDSTokenizer components Searchable combobox (XDSTypeahead) and multi-select token input (XDSTokenizer), built on a shared XDSBaseTypeahead engine. XDSTypeahead: - Search-as-you-type with keyboard navigation - Async and sync search via XDSSearchSource interface - Bootstrap results on focus, debounced search - Selected value shown as Token chip with clear - Status border styles (error/warning/success) XDSTokenizer: - Multi-select with inline token chips and remove buttons - Filters already-selected items from search results - Max entries support with graceful input collapse - Clear all button, backspace to remove last token - Custom token and item rendering Shared: - XDSBaseTypeahead: unstyled combobox with useXDSLayer positioning - XDSTypeaheadItem: default dropdown item renderer - XDSSearchSource/XDSSearchableItem: generic search interface - Full ARIA combobox pattern with activedescendant - @media (hover: hover) guards on all :hover styles Includes unit tests and Storybook stories for both components. * fix(typeahead): spacing compensation, editable token, and storybook source - Token spacing compensation: wrap selected token in tokenContainer with negative margin matching the Tokenizer pattern (equidistant from edges) - Editable typeahead: clicking the token or input enters edit mode — removes token, populates input with the value's label text, selects all. Blurring without selecting restores the original token. Escape also restores. - Storybook source fix: rewrite stories to use args-based pattern with inline render functions instead of wrapper components, so the source code panel shows actual component usage instead of opaque helper calls. - Add 3 tests for edit mode behavior (enter, restore on blur, container click) Co-authored-by: Navi <[email protected]> * refactor(typeahead): move wrapper and token ownership from base to consumers XDSBaseTypeahead is now a pure combobox engine — just the input, search, keyboard navigation, and dropdown. No wrapper div, no border styling, no token rendering, no edit mode, no isEmbedded flag. Consumers provide their own wrapper and pass anchorRef for dropdown positioning: - XDSTypeahead: owns wrapper div with borders, status styles, padding, token with spacing compensation, edit mode (click to edit, blur to restore, escape to cancel) - XDSTokenizer: already owned its wrapper, now passes wrapperRef as anchorRef instead of using isEmbedded Removed from base: isEmbedded, wrapperXStyle, statusType, startContent, hasClear, size, wrapper/token/status styles. Added to base: anchorRef (RefObject) for dropdown positioning. Falls back to the input element itself if not provided. Co-authored-by: Navi <[email protected]> * fix(typeahead): maintain focus on token after keyboard selection After selecting an item via keyboard, focus the token's internal button so keyboard users stay in the component. The token uses onClick to enable its internal button (keyboard-focusable), and Enter/Space on the focused token enters edit mode. Also simplified token rendering — removed tokenContainer wrapper div in favor of xstyle prop on XDSToken directly for spacing compensation. Co-authored-by: Navi <[email protected]> --------- Co-authored-by: Navi <[email protected]>
* feat(core): add XDSTypeahead and XDSTokenizer components Searchable combobox (XDSTypeahead) and multi-select token input (XDSTokenizer), built on a shared XDSBaseTypeahead engine. XDSTypeahead: - Search-as-you-type with keyboard navigation - Async and sync search via XDSSearchSource interface - Bootstrap results on focus, debounced search - Selected value shown as Token chip with clear - Status border styles (error/warning/success) XDSTokenizer: - Multi-select with inline token chips and remove buttons - Filters already-selected items from search results - Max entries support with graceful input collapse - Clear all button, backspace to remove last token - Custom token and item rendering Shared: - XDSBaseTypeahead: unstyled combobox with useXDSLayer positioning - XDSTypeaheadItem: default dropdown item renderer - XDSSearchSource/XDSSearchableItem: generic search interface - Full ARIA combobox pattern with activedescendant - @media (hover: hover) guards on all :hover styles Includes unit tests and Storybook stories for both components. * fix(typeahead): spacing compensation, editable token, and storybook source - Token spacing compensation: wrap selected token in tokenContainer with negative margin matching the Tokenizer pattern (equidistant from edges) - Editable typeahead: clicking the token or input enters edit mode — removes token, populates input with the value's label text, selects all. Blurring without selecting restores the original token. Escape also restores. - Storybook source fix: rewrite stories to use args-based pattern with inline render functions instead of wrapper components, so the source code panel shows actual component usage instead of opaque helper calls. - Add 3 tests for edit mode behavior (enter, restore on blur, container click) * refactor(typeahead): move wrapper and token ownership from base to consumers XDSBaseTypeahead is now a pure combobox engine — just the input, search, keyboard navigation, and dropdown. No wrapper div, no border styling, no token rendering, no edit mode, no isEmbedded flag. Consumers provide their own wrapper and pass anchorRef for dropdown positioning: - XDSTypeahead: owns wrapper div with borders, status styles, padding, token with spacing compensation, edit mode (click to edit, blur to restore, escape to cancel) - XDSTokenizer: already owned its wrapper, now passes wrapperRef as anchorRef instead of using isEmbedded Removed from base: isEmbedded, wrapperXStyle, statusType, startContent, hasClear, size, wrapper/token/status styles. Added to base: anchorRef (RefObject) for dropdown positioning. Falls back to the input element itself if not provided. * fix(typeahead): maintain focus on token after keyboard selection After selecting an item via keyboard, focus the token's internal button so keyboard users stay in the component. The token uses onClick to enable its internal button (keyboard-focusable), and Enter/Space on the focused token enters edit mode. Also simplified token rendering — removed tokenContainer wrapper div in favor of xstyle prop on XDSToken directly for spacing compensation. ---------
Adds XDSTypeahead and XDSTokenizer, split out from #286.
XDSTypeahead
XDSSearchSourceinterfacearia-activedescendantXDSTokenizer
renderToken/renderItemShared Infrastructure
XDSBaseTypeahead: unstyled combobox engine (used by both)XDSTypeaheadItem: default dropdown item rendererXDSSearchSource/XDSSearchableItem: generic search interface with cancel support@media (hover: hover)guards on all:hoverstylesRebase Cleanup
startIconprop (declared but never wired up)xstyleprop passthrough toXDSBaseTypeaheadCrafted with care by Navi