Skip to content

[combobox] Clear value on Escape from Trigger in input-inside-popup#4946

Draft
spokodev wants to merge 1 commit into
mui:masterfrom
spokodev:fix/combobox-trigger-escape-clears-value
Draft

[combobox] Clear value on Escape from Trigger in input-inside-popup#4946
spokodev wants to merge 1 commit into
mui:masterfrom
spokodev:fix/combobox-trigger-escape-clears-value

Conversation

@spokodev
Copy link
Copy Markdown

Fixes #4938.

In the input-inside-popup pattern (<Combobox.Trigger> outside, <Combobox.Input> inside <Combobox.Popup>), Combobox.Trigger was the keyboard entry point when the popup was closed, but it had no handler for Escape. So users could not clear a selected value without first opening the popup, focusing the Input, and pressing Escape there. The issue author posted a manual workaround that simulated a click on Combobox.Clear.

This adds an Escape branch to Combobox.Trigger's onKeyDown that mirrors the existing clear path in ComboboxInput.tsx (around line 399): it only fires when inputInsidePopup is true and the popup is not mounted, calls setSelectedValue with null (single) or [] (multiple), and stops propagation only when there was something to clear, not inline, and propagation was not explicitly allowed. disabled and readOnly are respected via the early return at the top of the handler.

Combobox.Input in the outside-popup pattern keeps its existing behavior. The Trigger handler only activates when the popup is closed, so when the popup is open the Escape goes through the Input as before.

11 new tests in ComboboxTrigger.test.tsx cover:

  • Two positive cases (single value cleared to null, multi to [])
  • Three negative cases (Tab on Trigger no-op; Trigger in input-outside-popup no-op; Trigger Escape while popup is open does not duplicate Input's clear)
  • Six edge cases (no value selected, Trigger disabled, Combobox.Root disabled, Combobox.Root readOnly, controlled value flow, details.reason === REASONS.escapeKey)

All four fail on master and pass on this branch.

Verification

pnpm test:jsdom ComboboxTrigger --no-watch
# 54 passed | 1 skipped (55)

pnpm test:jsdom Combobox --no-watch
# 685 passed | 17 skipped (702) across 25 test files

pnpm typescript
# clean

pnpm eslint packages/react/src/combobox/trigger/ComboboxTrigger.tsx packages/react/src/combobox/trigger/ComboboxTrigger.test.tsx
# clean

pnpm prettier --check packages/react/src/combobox/trigger/
# clean

Open as draft until CI confirms.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 29, 2026

commit: 4deae86

@code-infra-dashboard
Copy link
Copy Markdown

code-infra-dashboard Bot commented May 29, 2026

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+246B(+0.05%) 🔺+39B(+0.03%)

Details of bundle changes

Performance

Total duration: 1,122.83 ms +24.80 ms(+2.3%) | Renders: 50 (+0) | Paint: 1,687.75 ms +17.78 ms(+1.1%)

Test Duration Renders
Popover mount (300 instances) 75.69 ms 🔺+15.04 ms(+24.8%) 1 (+0)
Mixed surface mount (app-like density) 57.86 ms ▼-16.55 ms(-22.2%) 5 (+0)

10 tests within noise — details


Check out the code infra dashboard for more information about this PR.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 29, 2026

Deploy Preview for base-ui ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 4deae86
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a19bdd3e989f700084055a1
😎 Deploy Preview https://deploy-preview-4946--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

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.

[combobox] clearing value using the input-inside-popup pattern

1 participant