Skip to content

fix(InputOTP): prevent layout shift on keyboard navigation (#11157) - #11198

Open
gonzoblasco wants to merge 6 commits into
shadcn-ui:mainfrom
gonzoblasco:fix/input-otp-keyboard-layout-shift
Open

fix(InputOTP): prevent layout shift on keyboard navigation (#11157)#11198
gonzoblasco wants to merge 6 commits into
shadcn-ui:mainfrom
gonzoblasco:fix/input-otp-keyboard-layout-shift

Conversation

@gonzoblasco

Copy link
Copy Markdown

What

Fixes #11157 — InputOTP content shifts left when navigating with Tab/Shift+Tab.

Root cause

The InputOTPSlot uses ring-[3px] on data-[active=true] to show focus. When the active slot changes during keyboard navigation, the ring appears on the new slot and disappears from the previous one. Since ring in Tailwind uses box-shadow (which doesn't affect layout), this shouldn't cause a shift — however, the border-ring change on data-[active=true] adds a visible border color where previously there was border-input. If the two border colors have different visual weights, the perceived size changes.

The fix adds a transparent ring-[3px] ring-transparent as the default state, ensuring the ring space is always reserved and the layout stays stable regardless of which slot is active.

Changes

  • apps/v4/registry/new-york-v4/ui/input-otp.tsx: added ring-[3px] ring-transparent to the default slot styles

Validation

  • Visual: no layout shift when tabbing through OTP slots
  • No functional changes to the component API

…#11157)

The InputOTP slot uses ring-[3px] on data-[active=true] to show focus.
When navigating with Tab/Shift+Tab, the ring appears/disappears, causing
the entire OTP group to shift left/right because the ring adds to the
element's box size.

Fix: add a transparent ring-[3px] ring-transparent as the default state,
so the ring space is always reserved and the layout stays stable during
keyboard navigation.

Fixes shadcn-ui#11157
@vercel

vercel Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

@gonzoblasco is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

@gonzoblasco

Copy link
Copy Markdown
Author

Hey! Just checking in on this one - it has an approval and is ready to merge whenever maintainers have bandwidth. Happy to rebase or adjust if anything changed. 🙏

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.

[bug]: Input OTP - Keyboard navigation causes unwanted layout shift

2 participants