Skip to content

Add flag to combobox to allow text to remain in input area - #113

Merged
joshunrau merged 3 commits into
DouglasNeuroInformatics:mainfrom
david-roper:edit-combobox
Aug 10, 2026
Merged

Add flag to combobox to allow text to remain in input area#113
joshunrau merged 3 commits into
DouglasNeuroInformatics:mainfrom
david-roper:edit-combobox

Conversation

@david-roper

@david-roper david-roper commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an allowCustomValue option to ComboBox, letting the input accept free text instead of always reverting to the previously selected item.

Details

  • ComboBoxRoot.tsx (new): wraps Combobox.Root from @base-ui/react and adds an allowCustomValue?: boolean | ((inputValue: string) => Value) prop.
    • Default (false): unchanged behavior — text that doesn't match an item is discarded on close and the input reverts to the selected item.
    • Enabled: unmatched text is committed as the value (via onValueChange) when the user clicks away, tabs out, or presses Enter. Escape still reverts, and selecting an existing item still takes priority over free text (matched case-insensitively by label).
    • Pass a function instead of true to transform the typed string into a Value, which is required when items are objects rather than strings.
    • Ignored when multiple is set.
  • ComboBox.tsx: ComboBox root is now built on top of ComboboxRoot instead of binding Combobox.Root directly, so the new prop flows through the existing compound-component API with no other changes to consumers.
  • ComboBox.stories.tsx: adds an AllowCustomValue story demonstrating the new flag.
  • ComboBox.test.tsx (new): covers the default discard-on-close behavior, committing custom values on blur/outside-click/Enter, reverting on Escape, and preferring an exact item match over a custom value.

Test plan

  • ComboBox.test.tsx covers default and allowCustomValue behaviors
  • Manually verified the AllowCustomValue story in Storybook

Closes issue #114

@david-roper
david-roper requested a review from joshunrau as a code owner August 7, 2026 15:15
@joshunrau
joshunrau merged commit ed2a298 into DouglasNeuroInformatics:main Aug 10, 2026
1 check passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 6.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants