Skip to content

[autocomplete] Fix popup input FormData submission - #4725

Merged
atomiks merged 7 commits into
mui:masterfrom
lunaxislu:autocomplete-popup-input-formdata-fix
May 4, 2026
Merged

atomiks merged 7 commits into
mui:masterfrom
lunaxislu:autocomplete-popup-input-formdata-fix

Conversation

@lunaxislu

Copy link
Copy Markdown
Contributor

Fixes #4724.

Summary

  • keep popup-positioned Autocomplete inputs from owning the native form name
  • let the persistent hidden input submit selectionMode="none" values when the input is inside a Positioner
  • preserve outside and inline Autocomplete native submission through the visible input
  • add regression coverage for popup, inline, and default-value-before-open native FormData paths

Root cause

Autocomplete.Root delegates to AriaCombobox with selectionMode="none", so the submitted field value is the input value rather than a selected value. Base UI Form.onFormSubmit could read that value through the Field registry, but native FormData only reads named DOM controls.

When the input is rendered inside the popup, the visible input is transient and can unmount after selection. The persistent hidden input existed, but it was unnamed for selectionMode="none", so native FormData had no stable named control to read from.

This complements #4687, which fixed the adjacent Combobox popup-input Field registration path.

Validation

  • pnpm test:jsdom AutocompleteRoot --no-watch -t "native FormData"
  • pnpm test:chromium AutocompleteRoot --no-watch -t "native FormData"
  • pnpm test:jsdom ComboboxRoot --no-watch -t "submits when input inside popup renders a field-aware input"
  • pnpm test:chromium ComboboxRoot --no-watch -t "submits when input inside popup renders a field-aware input"
  • pnpm test:jsdom AutocompleteRoot --no-watch
  • pnpm typescript
  • pnpm prettier
  • pnpm eslint
  • git diff --check

@pkg-pr-new

pkg-pr-new Bot commented May 2, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@4725
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@4725
    

commit: 09ad8f0

@lunaxislu
lunaxislu marked this pull request as ready for review May 2, 2026 09:11
@netlify

netlify Bot commented May 2, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 27da381
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69f5bf799469de00085c4b79
😎 Deploy Preview https://deploy-preview-4725--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.

@code-infra-dashboard

code-infra-dashboard Bot commented May 2, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+230B(+0.05%) 🔺+64B(+0.04%)

Details of bundle changes

Performance

Total duration: 1,190.46 ms 🔺+28.32 ms(+2.4%) | Renders: 53 (+0) | Paint: 1,853.86 ms 🔺+65.96 ms(+3.7%)

Test Duration Renders
Slider mount (300 instances) 146.20 ms 🔺+16.48 ms(+12.7%) 3 (+0)
Checkbox mount (500 instances) 71.12 ms 🔺+11.25 ms(+18.8%) 1 (+0)
Dialog mount (300 instances) 75.28 ms 🔺+11.18 ms(+17.4%) 2 (+0)
Scroll Area mount (300 instances) 84.23 ms 🔺+6.63 ms(+8.5%) 3 (+0)
Select open (500 options) 47.21 ms 🔺+3.77 ms(+8.7%) 14 (+0)

…and 7 more — details


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

@netlify

netlify Bot commented May 2, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 09ad8f0
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69f928e74650c1000814dcd3
😎 Deploy Preview https://deploy-preview-4725--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.

@oliviertassinari oliviertassinari added the component: autocomplete Changes related to the autocomplete component. label May 2, 2026
@atomiks

atomiks commented May 4, 2026

Copy link
Copy Markdown
Contributor

The names here get a bit confusing.

inputInsidePositioner fixes the immediate ambiguity, but it adds a second boolean next to inputInsidePopup, which sounds similar. (To be fair, its existing meaning is already broader than the name suggests (hasPositionerParent || inline) which should possibly be refactored later). The two similar-sounding names makes this hard to reason about because one flag is about focus/layout behavior and the new one is really about native form ownership.

Could we keep inputInsidePopup unchanged to reduce how much gets changed in this PR, but rename the new state to the concept it controls?

inputOwnsFormValue: selectionMode === 'none' && !hasPositionerParent,

Then the hidden input branch reads:

const hiddenInputOwnsNoneValue =
  !inputOwnsFormValue ||
  // Before the popup input mounts, trigger-control comboboxes still need
  // the persistent hidden input to own native form submission.
  (!inline && triggerElement != null && inputElement == null);

@lunaxislu

lunaxislu commented May 4, 2026 •

Copy link
Copy Markdown
Contributor Author

The names here get a bit confusing.

inputInsidePositioner fixes the immediate ambiguity, but it adds a second boolean next to inputInsidePopup, which sounds similar. (To be fair, its existing meaning is already broader than the name suggests (hasPositionerParent || inline) which should possibly be refactored later). The two similar-sounding names makes this hard to reason about because one flag is about focus/layout behavior and the new one is really about native form ownership.

Could we keep inputInsidePopup unchanged to reduce how much gets changed in this PR, but rename the new state to the concept it controls?

inputOwnsFormValue: selectionMode === 'none' && !hasPositionerParent,

Then the hidden input branch reads:

const hiddenInputOwnsNoneValue =
  !inputOwnsFormValue ||
  // Before the popup input mounts, trigger-control comboboxes still need
  // the persistent hidden input to own native form submission.
  (!inline && triggerElement != null && inputElement == null);

That makes perfect sense !!.
Separating the layout/focus flag from the native form ownership makes the intent much clearer.

I'll revert inputInsidePopup to keep the PR scope small and rename the new state to inputOwnsFormValue as you suggested. I also reused inputOwnsFormValue in the input's name branch to keep the same concept in one place.

Updating the PR shortly! Thanks for the review.

@atomiks atomiks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the fix @lunaxislu

@atomiks
atomiks merged commit cd17b07 into mui:master May 4, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: autocomplete Changes related to the autocomplete component.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[autocomplete] Popup input value is missing from native FormData

3 participants