Skip to content

feat(core): add XDSTypeahead and XDSTokenizer components - #299

Merged
cixzhang merged 4 commits into
mainfrom
navi/feat/typeahead-tokenizer
Mar 3, 2026
Merged

cixzhang merged 4 commits into
mainfrom
navi/feat/typeahead-tokenizer

Conversation

@cixzhang

@cixzhang cixzhang commented Feb 23, 2026 •

Copy link
Copy Markdown
Contributor

Adds XDSTypeahead and XDSTokenizer, split out from #286.

XDSTypeahead

  • Search-as-you-type combobox with keyboard navigation
  • Async and sync search via XDSSearchSource interface
  • Bootstrap results on focus, configurable debounce
  • Selected value shown as Token chip with clear button
  • Status border styles (error/warning/success)
  • Full ARIA combobox pattern with aria-activedescendant

XDSTokenizer

  • Multi-select token input with inline 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 via renderToken/renderItem

Shared Infrastructure

  • XDSBaseTypeahead: unstyled combobox engine (used by both)
  • XDSTypeaheadItem: default dropdown item renderer
  • XDSSearchSource/XDSSearchableItem: generic search interface with cancel support
  • @media (hover: hover) guards on all :hover styles

Rebase Cleanup

  • Rebased onto latest main
  • Removed orphaned VRT snapshots (VRT removed in chore: remove visual regression testing #392)
  • Removed dead startIcon prop (declared but never wired up)
  • Fixed xstyle prop passthrough to XDSBaseTypeahead
  • Removed unused import in Tokenizer stories
  • Squashed 8 commits into 1 clean commit

Crafted with care by Navi

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Feb 23, 2026
@cixzhang
cixzhang force-pushed the navi/feat/typeahead-tokenizer branch from 8578915 to e06778e Compare February 24, 2026 04:20
@cixzhang
cixzhang force-pushed the navi/feat/popover-only branch from ad95f43 to 445c750 Compare February 24, 2026 04:45
czarandy
czarandy previously approved these changes Feb 24, 2026

@czarandy czarandy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may want to either add caching here or else recommend that the search source implementation has its own caching

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +698 to +704
!isEmbedded && styles.wrapper,
!isEmbedded && sizeStyle,
isDisabled && styles.wrapperDisabled,
isEmbedded && styles.wrapperEmbedded,
!isEmbedded && statusType && statusBorderStyles[statusType],
!isEmbedded && statusType && statusHoverShadowStyles[statusType],
!isEmbedded && statusType && statusFocusStyles[statusType],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it may be nicer to read if you combine all the !isEmbedded into a single item that returns an array

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be capitalized XStyle? that's how we do it in XDS on www right now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, you're right — renamed to wrapperXStyle and inputXStyle to match the XDS convention.

@cixzhang
cixzhang force-pushed the navi/feat/typeahead-tokenizer branch from e06778e to 66bd264 Compare February 25, 2026 00:22
@cixzhang
cixzhang changed the base branch from navi/feat/popover-only to main February 25, 2026 00:23

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Caching — Added JSDoc on search() recommending internal caching for expensive sources
  2. Debounce — New debounceMs prop (default 150, set to 0 for local sources). Exposed on all three components.
  3. Cancel API — Added optional cancel?() to XDSSearchSource. Called before new searches, on dropdown hide, and on unmount. JSDoc example shows AbortController pattern.
  4. !isEmbedded consolidation — Extracted wrapperStyles array that branches once on isEmbedded
  5. XStyle capitalization — Renamed wrapperXstyle → wrapperXStyle, inputXstyle → inputXStyle

@github-actions

github-actions Bot commented Feb 25, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

New Components

Tokenizer · View in Storybook
Metric Value
Bundle Size (ESM) 531B
Bundle Size (CJS) 649B
Lines of Code 417
Source Files 2
Complexity Very High (44)
Exports XDSTokenizer
Props Count N/A
Has Tests Yes
Has Stories Yes
Typeahead · View in Storybook
Metric Value
Bundle Size (ESM) 619B
Bundle Size (CJS) 801B
Lines of Code 933
Source Files 5
Complexity Very High (118)
Exports XDSBaseTypeahead, XDSTypeahead, XDSTypeaheadItem
Props Count N/A
Has Tests Yes
Has Stories Yes

Modified Components

Token · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 203B N/A
Lines of Code N/A 323 -
Complexity N/A Medium (14) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 8.1KB 13.2KB 2.0KB

Accessibility Audit

Status: 1 accessibility violation(s) found — 1 serious.

XDSToken - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 2/9 stories · Learn more
    • WCAG: 1.4.3 (Level AA)

Component Previews

Includes interactive hover previews as animated GIFs.

XDSToken

Default

Screenshot:

Default

Interaction Preview: (view video)

Default interaction

View in Storybook · core-xdstoken--default

Colors

Screenshot:

Colors

View in Storybook · core-xdstoken--colors

With Icon

Screenshot:

With Icon

View in Storybook · core-xdstoken--with-icon

With Remove

Screenshot:

With Remove

View in Storybook · core-xdstoken--with-remove

Clickable

Screenshot:

Clickable

View in Storybook · core-xdstoken--clickable

As Link

Screenshot:

As Link

View in Storybook · core-xdstoken--as-link

With End Content

Screenshot:

With End Content

View in Storybook · core-xdstoken--with-end-content

Disabled

Screenshot:

Disabled

View in Storybook · core-xdstoken--disabled

All Variations

Screenshot:

All Variations

View in Storybook · core-xdstoken--all-variations

XDSTokenizer

Default

Screenshot:

Default

Interaction Preview: (view video)

Default interaction

View in Storybook · form-xdstokenizer--default

Pre-selected Items

Screenshot:

Pre-selected Items

View in Storybook · form-xdstokenizer--with-preselected

With Clear All Button

Screenshot:

With Clear All Button

View in Storybook · form-xdstokenizer--with-clear

Max 3 Entries

Screenshot:

Max 3 Entries

View in Storybook · form-xdstokenizer--max-entries

Required

Screenshot:

Required

View in Storybook · form-xdstokenizer--required

With Description

Screenshot:

With Description

View in Storybook · form-xdstokenizer--with-description

With Error

Screenshot:

With Error

View in Storybook · form-xdstokenizer--with-error

With Warning

Screenshot:

With Warning

View in Storybook · form-xdstokenizer--with-warning

With Success

Screenshot:

With Success

View in Storybook · form-xdstokenizer--with-success

Disabled

Screenshot:

Disabled

View in Storybook · form-xdstokenizer--disabled

XDSTypeahead

Default

Screenshot:

Default

Interaction Preview: (view video)

Default interaction

View in Storybook · form-xdstypeahead--default

With Bootstrap Results

Screenshot:

With Bootstrap Results

View in Storybook · form-xdstypeahead--with-bootstrap

Required

Screenshot:

Required

View in Storybook · form-xdstypeahead--required

Optional

Screenshot:

Optional

View in Storybook · form-xdstypeahead--optional

With Description

Screenshot:

With Description

View in Storybook · form-xdstypeahead--with-description

With Error

Screenshot:

With Error

View in Storybook · form-xdstypeahead--with-error

With Warning

Screenshot:

With Warning

View in Storybook · form-xdstypeahead--with-warning

With Success

Screenshot:

With Success

View in Storybook · form-xdstypeahead--with-success

Disabled

Screenshot:

Disabled

View in Storybook · form-xdstypeahead--disabled

Without Clear Button

Screenshot:

Without Clear Button

View in Storybook · form-xdstypeahead--no-clear

Max 3 Results

Screenshot:

Max 3 Results

View in Storybook · form-xdstypeahead--limited-results


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@thedjpetersen

Copy link
Copy Markdown
Contributor

🔴 CI: build + test failing — Build fails on a missing font token:

Property '--text-xs' does not exist on type ... Did you mean '--text-4xs'?

The Typeahead/Tokenizer components reference a --text-xs token that doesn't exist in the current font token set. The available small tokens are --text-4xs, --text-3xs, --text-2xs, --text-xsm. Likely needs --text-xs → --text-xsm (or whichever maps to the intended size).

— Navi (after-hours CI triage)

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'],

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'],

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@thedjpetersen

Copy link
Copy Markdown
Contributor

🤖 Night Watch QA Report

visual-regression failing

The visual regression check is failing due to screenshot baseline drift. Several recent merges to main (XDSStack consolidation, TopNav mega menu changes, Button endSlot) updated component rendering, so branches that haven't rebased will show pixel diffs.

Fix: Rebase on main and update snapshots:

git rebase main
yarn playwright test e2e/visual-regression.spec.ts --update-snapshots
git add -A && git commit -m "chore: update visual regression snapshots"

All other CI checks are passing. ✅


Night Watch QA — automated CI health check

@cixzhang
cixzhang force-pushed the navi/feat/typeahead-tokenizer branch 3 times, most recently from 7716829 to 71924e5 Compare February 27, 2026 22:37
@github-actions

github-actions Bot commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

❌ Visual Regression — Failed

Screenshots differ from baselines for: XDSTokenizer, XDSBaseTypeahead, XDSTypeahead, XDSTypeaheadItem, XDSToken

View diff artifacts to review the visual changes.

To accept these changes, comment /update-baselines on this PR.
Baselines will be regenerated and committed automatically.

@thedjpetersen

Copy link
Copy Markdown
Contributor

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.
@cixzhang
cixzhang force-pushed the navi/feat/typeahead-tokenizer branch from eb5fb56 to 13c9041 Compare March 3, 2026 08:53
cixzhang and others added 3 commits March 3, 2026 15:25
…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]>
@cixzhang

cixzhang commented Mar 3, 2026

Copy link
Copy Markdown
Contributor Author

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.

@cixzhang
cixzhang added this pull request to the merge queue Mar 3, 2026
Merged via the queue into main with commit 678ac37 Mar 3, 2026
12 checks passed
This was referenced Mar 7, 2026
@cixzhang
cixzhang deleted the navi/feat/typeahead-tokenizer branch March 13, 2026 10:51
cixzhang added a commit that referenced this pull request Apr 26, 2026
* 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]>
cixzhang added a commit that referenced this pull request Jun 21, 2026
* 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]>
cixzhang added a commit that referenced this pull request Jun 21, 2026
* 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.


---------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants