shadcn-ui / ui

Beautifully designed components that you can copy and paste into your apps. Accessible. Customizable. Open Source.
https://ui.shadcn.com
MIT License
64.49k stars 3.67k forks source link

[feat]: Autofocus for Input-OTP #4035

Closed WhyFenceCode closed 17 hours ago

WhyFenceCode commented 4 weeks ago

Feature description

I am wondering if we can add some simple code to the Input-OTP object that makes the first box of the Input-OTP object get selected when it begins to render. This should be a simple bool just like disabled, so that it can quickly work and is easy to use.

Affected component/components

Input-OTP

Additional Context

No response

Before submitting

bhaskarkhoraja commented 3 weeks ago

This features already exist just pass attribute autoFocus to InputOTP component

const InputWithAutoFocus = () => {
  return (
    <InputOTP maxLength={6} autoFocus> {/* <- autoFocus as boolean */}
      <InputOTPGroup>
        <InputOTPSlot index={0} />
        <InputOTPSlot index={1} />
        <InputOTPSlot index={2} />
      </InputOTPGroup>
      <InputOTPSeparator />
      <InputOTPGroup>
        <InputOTPSlot index={3} />
        <InputOTPSlot index={4} />
        <InputOTPSlot index={5} />
      </InputOTPGroup>
    </InputOTP>
  );
};
shadcn commented 17 hours ago

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.