Skip to content

refactor(fuselage): rewrite AutoComplete with derived selection state#2025

Draft
ggazzo wants to merge 1 commit into
mainfrom
autocomplete-rewrite
Draft

refactor(fuselage): rewrite AutoComplete with derived selection state#2025
ggazzo wants to merge 1 commit into
mainfrom
autocomplete-rewrite

Conversation

@ggazzo

@ggazzo ggazzo commented Jun 18, 2026

Copy link
Copy Markdown
Member

Why

Current AutoComplete keeps a local selected state duplicated from the controlled value and syncs it via useEffect. The sync only filters out now-invalid selections — it never re-adds newly-valid ones — so selected drifts from value/options. Selection logic also writes both setSelected and onChange, doubling bookkeeping.

What

  • Derived selection: selected is now useMemo(() => getSelected(value, options)). Single source of truth, drift bug gone, no sync effect.
  • Fixed multiple-mode type bug: append guards Array.isArray(value) ? value : [] (was value || [], which spreads a string into chars).
  • Dedicated keyboard hook: new useAutoCompleteCursor (scoped to AutoComplete) using event.key instead of deprecated keyCode, returning a named object instead of a 5-tuple. The shared useCursor (used by Menu/Select/MultiSelect) is left untouched.

Compatibility

  • No public API change.
  • No visual change — all 7 story snapshots unchanged; a11y checks pass.
  • 18/18 tests green.

Replace duplicated local selection state with a value-derived useMemo,
eliminating drift between value/options and the rendered chips. Extract
keyboard navigation into a dedicated event.key-based hook scoped to
AutoComplete, leaving the shared useCursor untouched. Same visual and
public API; snapshots unchanged.
@changeset-bot

changeset-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8bf2b46

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@rocket.chat/fuselage Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant