#how to auto focus input otp shadcn element
36 messages · Page 1 of 1 (latest)
🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord
🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize
✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)
try passing autoFocus to <InputOTP />
that didn't work either
probabaly because of this: but I can't edit this state in the parent
{hasFakeCaret && (
<div className="pointer-events-none absolute inset-0 flex items-center justify-center">
<div className="h-2/3 w-px animate-caret-blink bg-foreground duration-1000" />
</div>
)}
what is this? could you show the full code
this is the input-otp.tsx
The reason focus does not place a cursor is because it's not actually a cursor its just a div, but I can't manipulate the fake Caret state in the parent
I know this is shadcn
"use client";
import {
InputOTP,
InputOTPGroup,
InputOTPSeparator,
InputOTPSlot,
} from "@/components/ui/input-otp";
export function InputOTPDemo() {
return (
<InputOTP maxLength={6} autoFocus>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP>
);
}
this code work out of the box
... But that doesn't auto focus
so you have to show the code on how are you rendering the input
I don't see you are rendering input-otp here
I think you misunderstand my problem
I am rendering it fine, the values update no problem, and it links to my db fine as well
the problem is I can't focus it on render, because its a fake cursor, its two divs which allow the caret to have an animation
Thats why when you focus it it only has an outline but the caret doesn't show up
and there is no way to update the state outside of the parent
like I said, this code work out of the box
you have to pass autoFocus to <InputOTP />
i did bro
<InputOTPSlot /> is a div
didnt do anything
<InputOTP /> is the input
Im using tauri so idk maybe its different
I literally copy and pasted the shadcn thing in
well consider showing your code, otherwise I can't help
its the same code you sent. Ive tried auto focus in every element
But I have another component I already made so its all good, thx for the help