Skip to content

[autocomplete] Fix input value and clear#48263

Merged
mj12albert merged 2 commits into
mui:masterfrom
mj12albert:autocomplete/fix-input-value-and-clear-2of5
Apr 14, 2026
Merged

[autocomplete] Fix input value and clear#48263
mj12albert merged 2 commits into
mui:masterfrom
mj12albert:autocomplete/fix-input-value-and-clear-2of5

Conversation

@mj12albert

@mj12albert mj12albert commented Apr 10, 2026

Copy link
Copy Markdown
Member

Fixes #40099
Fixes #43458

1. Clear-on-escape breaks subsequent open-on-focus #43458

Demo: https://deploy-preview-48263--material-ui.netlify.app/material-ui/react-autocomplete/#creatable

  1. Select a film from the dropdown
  2. Click away to blur, then click back into the input — popup opens (confirms openOnFocus works)
  3. Press Escape — popup closes
  4. Press Escape again — value clears
  5. Click away to blur
  6. Click back into the input

With this fix: Popup opens on step 6

Without the fix: Popup doesn't open on step 6, the escape-clear breaks focusOnOpen afterwards


2. Controlled free solo input value doesn't clear #40099

Demo: https://stackblitz.com/edit/krui4i59-h253ekpy?file=src%2FDemo.tsx

  1. Select an option
  2. Click the external reset button

With this fix: input is cleared

Without the fix: input not cleared (stackblitz)

@mj12albert mj12albert added type: bug It doesn't behave as expected. scope: autocomplete Changes related to the autocomplete. This includes ComboBox. labels Apr 10, 2026
@mui-bot

mui-bot commented Apr 10, 2026

Copy link
Copy Markdown

Netlify deploy preview

https://deploy-preview-48263--material-ui.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/material 🔺+43B(+0.01%) 🔺+21B(+0.01%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against f1cb316

@mj12albert mj12albert force-pushed the autocomplete/fix-input-value-and-clear-2of5 branch from 2e15ebf to 8e38a83 Compare April 13, 2026 00:13
@mj12albert mj12albert force-pushed the autocomplete/fix-input-value-and-clear-2of5 branch from 8e38a83 to f1cb316 Compare April 13, 2026 07:24
@mj12albert mj12albert marked this pull request as ready for review April 13, 2026 08:20
expect(textbox).toHaveFocus();

// Blur and re-focus: onOpen should be called (ignoreFocus was NOT set)
act(() => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

would user.tab and user.tab({shift}) also work here?

@mj12albert mj12albert enabled auto-merge (squash) April 14, 2026 15:09
@code-infra-dashboard

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@mui/material 🔺+43B(+0.01%) 🔺+20B(+0.01%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Deploy preview

https://deploy-preview-48263--material-ui.netlify.app/


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

@mj12albert mj12albert merged commit 22a9d00 into mui:master Apr 14, 2026
19 checks passed
frewsxcv added a commit to observ-ing/core that referenced this pull request May 19, 2026
9.0.1 ships a useAutocomplete change (mui/material-ui#48263) that
clears the input in freeSolo/null-value scenarios. Our TaxaAutocomplete
hits that path, which broke tests/observation-edit.spec.ts "edit modal
pre-populates species".
frewsxcv added a commit to observ-ing/core that referenced this pull request May 19, 2026
Isolates the suspected breakage from the larger PR #477 dep bundle.
9.0.1 ships mui/material-ui#48263 (resetInputValue change for
freeSolo+null value); the goal here is to reproduce the
observation-edit "pre-populates species" test failure and try fixes.
frewsxcv added a commit to observ-ing/core that referenced this pull request May 19, 2026
@mui/material 9.0.1 (mui/material-ui#48263) made `useAutocomplete`'s
`resetInputValue` clear a non-empty `inputValue` when `value` is
null and `freeSolo` is set. Our `inputValue` was controlled but
`value` was not, so an async `setSpecies("Quercus alba")` in
UploadModal's edit-mode useEffect was wiped before the user saw it.

Controlling `value` alongside `inputValue` flips
`isOptionSelected` to true, so the reset path short-circuits.
@mj12albert mj12albert deleted the autocomplete/fix-input-value-and-clear-2of5 branch June 3, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: autocomplete Changes related to the autocomplete. This includes ComboBox. type: bug It doesn't behave as expected.

Projects

None yet

3 participants