Skip to content

[otp field] Keep focus on the invalid field when autoSubmit is blocked - #5089

Merged
atomiks merged 2 commits into
mui:masterfrom
lyzno1:codex/fix-otp-autosubmit-focus
Jun 22, 2026
Merged

atomiks merged 2 commits into
mui:masterfrom
lyzno1:codex/fix-otp-autosubmit-focus

Conversation

@lyzno1

@lyzno1 lyzno1 commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5088.

This is a small attempt to fix the OTP Field auto-submit focus behavior. When an OTP value becomes complete, the field currently handles completion before its pending slot focus. If autoSubmit calls requestSubmit() and Base UI Form blocks submission because an earlier field is invalid, the form focuses that invalid control, but the OTP pending focus then moves focus back to the final OTP slot.

This PR processes the OTP pending focus before the completion callback. That keeps the normal accepted-value focus behavior, while allowing Form's invalid-field focus to be the final focus update when auto-submit is blocked.

If this order is not the intended behavior, I am happy to adjust or leave the maintainers to take a different fix.

Reproduction: https://stackblitz.com/edit/fg7exrjh?file=src%2FApp.tsx

Validation:

  • pnpm test:jsdom OTPFieldRoot --no-watch
  • pnpm test:chromium OTPFieldRoot --no-watch
  • pnpm test:jsdom OTPField --no-watch
  • pnpm test:chromium OTPField --no-watch
  • pnpm exec eslint packages/react/src/otp-field/root/OTPFieldRoot.tsx packages/react/src/otp-field/root/OTPFieldRoot.test.tsx --max-warnings 0
  • pnpm exec prettier --check packages/react/src/otp-field/root/OTPFieldRoot.tsx packages/react/src/otp-field/root/OTPFieldRoot.test.tsx

@pkg-pr-new

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

commit: 9ff72a5

@code-infra-dashboard

code-infra-dashboard Bot commented Jun 20, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 0B(0.00%) 🔺+1B(0.00%)

Details of bundle changes

Performance

Total duration: 1,189.90 ms -38.27 ms(-3.1%) | Renders: 78 (+0)

Test Duration Renders
Slider mount (300 instances) 170.99 ms 🔺+29.66 ms(+21.0%) 3 (+0)
Checkbox mount (500 instances) 79.24 ms 🔺+18.91 ms(+31.3%) 1 (+0)
Select mount (200 instances) 119.01 ms ▼-55.20 ms(-31.7%) 3 (+0)

11 tests within noise — details

Metric alarms

Test Metric Change
Slider mount (300 instances) bench:paint 🔺 +48.95 ms
Checkbox mount (500 instances) bench:paint 🔺 +30.88 ms

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

@netlify

netlify Bot commented Jun 20, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Built without sensitive environment variables

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

Signed-off-by: yyh <[email protected]>
@lyzno1 lyzno1 changed the title [otp-field] Fix auto-submit invalid focus [otp field] Fix auto-submit invalid focus Jun 20, 2026
@lyzno1

lyzno1 commented Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

@lyzno1
lyzno1 marked this pull request as ready for review June 20, 2026 11:32

@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 @lyzno1

@atomiks atomiks changed the title [otp field] Fix auto-submit invalid focus [otp field] Keep focus on the invalid field when autoSubmit is blocked Jun 22, 2026
@atomiks
atomiks merged commit 9b128eb into mui:master Jun 22, 2026
6 of 7 checks passed
@lyzno1
lyzno1 deleted the codex/fix-otp-autosubmit-focus branch June 22, 2026 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[otp field] AutoSubmit keeps focus on the final OTP slot when form validation is blocked

2 participants