Skip to content

[select][combobox][number field] Ignore hidden-input changes while readonly or disabled - #4810

Merged
atomiks merged 7 commits into
mui:masterfrom
lunaxislu:fix/select-combobox-hidden-input-autofill-lock-state
May 18, 2026
Merged

atomiks merged 7 commits into
mui:masterfrom
lunaxislu:fix/select-combobox-hidden-input-autofill-lock-state

Conversation

@lunaxislu

Copy link
Copy Markdown
Contributor

Fixes #4809.

Follow-up to #4806.

SelectRoot and AriaCombobox use the same hidden-input autofill pattern that
OTPFieldRoot used before #4806, but their hidden-input onChange handlers
still only guard defaultPrevented, not disabled || readOnly.

This PR applies the same locked-state guard to those remaining handlers.

AriaCombobox is the shared root used by:

  • Combobox.Root (selectionMode='single' | 'multiple')
  • Autocomplete.Root (selectionMode='none')

What changed

  • SelectRoot.tsx: hidden-input onChange guard now matches OTP's
  • AriaCombobox.tsx: same one-line guard update
  • Regression tests added for:
    • Select
    • Combobox (selectionMode='single')
    • Autocomplete (selectionMode='none')

Each regression test fires change on the hidden input and verifies that no public state change happens while readOnly or disabled.

No public API change.

@pkg-pr-new

pkg-pr-new Bot commented May 11, 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@4810
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@4810
    

commit: faf04c0

@code-infra-dashboard

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

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+104B(+0.02%) 🔺+52B(+0.04%)

Details of bundle changes

Performance

Total duration: 1,207.70 ms -238.21 ms(-16.5%) | Renders: 50 (+0) | Paint: 1,838.51 ms -350.34 ms(-16.0%)

Test Duration Renders
Tabs mount (200 instances) 208.49 ms ▼-65.66 ms(-23.9%) 4 (+0)
Scroll Area mount (300 instances) 85.08 ms ▼-36.47 ms(-30.0%) 3 (+0)
Checkbox mount (500 instances) 65.93 ms ▼-34.31 ms(-34.2%) 1 (+0)
Popover mount (300 instances) 63.42 ms ▼-24.44 ms(-27.8%) 1 (+0)
Tooltip mount (300 contained roots) 46.79 ms ▼-13.82 ms(-22.8%) 1 (+0)

7 tests within noise — details


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

@netlify

netlify Bot commented May 11, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit faf04c0
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a0aa2daf8427300085f9c65
😎 Deploy Preview https://deploy-preview-4810--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.

@zannager zannager added component: select Changes related to the select component. component: combobox Changes related to the combobox component. labels May 11, 2026
@mj12albert mj12albert added the type: bug It doesn't behave as expected. label May 11, 2026
@lunaxislu
lunaxislu requested a review from mj12albert May 12, 2026 07:26
@lunaxislu
lunaxislu requested a review from mj12albert May 14, 2026 13:57
@atomiks

atomiks commented May 15, 2026

Copy link
Copy Markdown
Contributor

Code Review (GPT-5.5)

Request changes 🔴 because the same readOnly hidden-input autofill path still exists in NumberField, and the new regression coverage can be much smaller.

1. Bugs / Issues

1. 🔴 NumberField still accepts hidden-input autofill while readOnly (blocking)

The PR fixes Select and AriaCombobox, but NumberField has the same supported hidden-input autofill path and still only guards defaultPrevented. By code reading, a readOnly NumberField can still update through this hidden input because the input does not receive readOnly, and the handler does not check the root locked state.

packages/react/src/number-field/root/NumberFieldRoot.tsx

onChange(event) {
  // Workaround for https://github.com/facebook/react/issues/9023
  if (event.nativeEvent.defaultPrevented) {
    return;
  }

  // Handle browser autofill.
  const nextValue = event.currentTarget.valueAsNumber;
  const parsedValue = Number.isNaN(nextValue) ? null : nextValue;

  setDirty(parsedValue !== validityData.initialValue);
  setValue(parsedValue, details);
}

This leaves the same class of bug open in another public component that already has a hidden-input browser autofill test.

Fix: Apply the same locked-state guard to NumberFieldRoot and add a regression for at least readOnly hidden-input autofill; include event.preventBaseUIHandler?.() there too when the handler is wrapped by Field.Root.

2. 🟡 The locked-state regression tests can be table-driven (non-blocking)

The new tests repeat the same matrix several times: readOnly vs disabled, inside Field.Root vs outside Field.Root, then the same hidden-input change and “no public state changed” assertions. That makes this bug fix look larger than it is.

packages/react/src/select/root/SelectRoot.test.tsx

it('ignores hidden-input autofill when readOnly', async () => { ... });
it('ignores hidden-input autofill when disabled', async () => { ... });
it('ignores hidden-input autofill when readOnly outside Field', async () => { ... });
it('ignores hidden-input autofill when disabled outside Field', async () => { ... });

Recommendation: Extract small render/assert helpers per component and drive the lock state with it.each(['readOnly', 'disabled'] as const). For Select and Combobox, a second table dimension for withField would keep the Field error assertion where it matters while removing most of the duplicated JSX.

2. Simplification Opportunities

The production change is already close to minimal for Select and AriaCombobox. If NumberField is included too, a tiny shared predicate may be worth it, for example “ignore this hidden input change when the native event was already prevented or the root is locked, and prevent the Field validation handler when possible.” I would only add that helper if it removes duplication across Select, AriaCombobox, and NumberField; otherwise the source-level inline guard is fine.

@lunaxislu

lunaxislu commented May 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Addressed the NumberField gap in 5b5865d.

  • Added the same locked-state guard to NumberField's hidden input autofill path: defaultPrevented || disabled || readOnly now returns early and calls event.preventBaseUIHandler?.() so Field validation handlers do not clear existing errors while locked.
  • Added NumberField regression coverage for readOnly and disabled, both inside and outside Field.Root.
  • Reduced the existing Select and Combobox locked-state regression tests to table-driven coverage while preserving the inside/outside Field assertions.

I considered adding readOnly={readOnly} to NumberField's hidden input for consistency with Select/Combobox/OTPField, but kept this as a handler guard only. Unlike those text hidden inputs, NumberField uses a type="number" hidden input with native min/max/step/required validation; setting readOnly on the input would bar it from constraint validation and could silently allow invalid read-only values through form submission.

Verified with:

  • pnpm test:jsdom NumberField --no-watch
  • pnpm test:jsdom Select --no-watch
  • pnpm test:jsdom Combobox --no-watch

@lunaxislu lunaxislu changed the title [select][combobox] Ignore hidden-input changes while readonly or disabled [select][combobox][number field] Ignore hidden-input changes while readonly or disabled May 16, 2026

@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 254809a into mui:master May 18, 2026
6 checks passed
mbrookes pushed a commit to mbrookes/base-ui that referenced this pull request May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: combobox Changes related to the combobox component. component: select Changes related to the select component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[select][combobox] Hidden input ignores readonly/disabled during browser autofill

4 participants