Skip to content

✨ feat(combobox): add opt-in @onClose callback - #216

Open
dmcnamara-eng wants to merge 1 commit into
GavinJoyce:masterfrom
phorest:feat/combobox-on-close
Open

dmcnamara-eng wants to merge 1 commit into
GavinJoyce:masterfrom
phorest:feat/combobox-on-close

Conversation

@dmcnamara-eng

Copy link
Copy Markdown
Collaborator

What

Adds an optional @onClose argument to <Combobox>. It's called once, with no arguments, whenever an open combobox closes:

  • clicking outside
  • Tab
  • Escape
  • selecting an option
  • toggling with the button

It isn't called on render, or when the combobox was already closed.

<Combobox @value={{this.value}} @onChange={{this.select}} @onClose={{this.commitQuery}} as |combobox|>
  <combobox.Input @onChange={{this.setQuery}} />
  ...
</Combobox>

Why

Some consumers accept free text: they filter options as the user types and keep whatever was typed even if no option is picked. Right now there's no way to tell when the combobox has been dismissed. On click outside, handleClickOutside resets the input to the selected value, so the typed query is lost. Consumers end up adding their own focusout handler on a wrapper element. We have two of these in one app.

This mirrors onClose on Headless UI React v2's Combobox.

Why not call @onChange on blur?

We considered calling @onChange with the typed text when the combobox closes, and decided against it:

  • @onChange receives option values, which are often objects. Passing a raw string there would break that contract for every existing consumer.
  • Resetting the input on dismissal is intentional (handleClickOutside restores _originalValue). It also matches Headless UI React, where free text is offered as an option.

@onClose is opt-in and doesn't change behaviour for anyone who doesn't pass it.

Implementation

The hook is in the isOpen setter, which every close path already goes through. It fires only on an open → closed transition, after state has been updated.

Tests

There's a new Combobox @onClose module in combobox-test.js with 7 tests:

  • one for each close path
  • not called on render, or on click outside while closed
  • typed text never reaches @onChange

The full <Combobox> suite passes locally: 100 pass, 0 fail, plus the existing skip/todo. With the onClose call removed, the 5 positive tests fail.

🤖 Generated with Claude Code

Called once whenever an open combobox closes: click outside, Tab,
Escape, selecting an option or the button toggle. Lets consumers react
to dismissal (e.g. commit a typed query as free text) without wiring
their own focusout handler. Mirrors Headless UI React v2's `onClose`.

@onchange is unchanged and is still only called with option values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dmcnamara-eng dmcnamara-eng self-assigned this Nov 12, 2026
@dmcnamara-eng
dmcnamara-eng marked this pull request as ready for review November 12, 2026 10:49

This branch has not been deployed

No deployments
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