guilhermerodz / input-otp Goto Github PK
View Code? Open in Web Editor NEWOne time passcode Input. Accessible & unstyled.
Home Page: https://input-otp.rodz.dev
One time passcode Input. Accessible & unstyled.
Home Page: https://input-otp.rodz.dev
I found files with duplicate logic to utility to merge class names in:
This is intentional?
idk if intended behavior tho
The OTP (One-Time Password) input component currently does not allow users to paste codes into the input fields. This limitation can affect the user experience, especially for those who rely on password managers or receive their OTP codes through messaging apps, requiring them to manually type the code each time.
Users should be able to paste the OTP code into the input field.
OS: iOS 17.1
Browser: Safari
On some rare cases this error shows on some devices. This was sent to me by my client, She tried it on her husbands phone and the otp works, just on some devices it shows this error. I tried on other mobile devices I have here and couldn't recreate the error.
Uppon checking the source code is text : transparent
instead of color : transparent
. But I am not sure if this really the cause of the error.
Is there a possible fix/workaround for this?
Thanks for response ๐
On focus, I get a ring around my entire OTP component.
I use shadcn. This isn't unique to the new shadcn version of the component. Just the Tailwind might be the problem. Adding className="focus-visible:ring-0"
fixes it. Could this become a default class?
There's a problem with the implementation of shadcn that I mentioned here: shadcn-ui/ui#2953. I had to manually fix shadcn's code for this to work.
I think there should be a prop that makes focus on 1st slot by default like autoFocus in input element.
I encountered the following error while testing with vitest:
../../node_modules/input-otp/src/input.tsx:69:22
I'm currently encountering a TypeError: at.supports is not a function
when testing with vitest. Here's my vitest configuration:
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vitest/config';
import tsconfigPaths from 'vite-tsconfig-paths';
export default defineConfig({
plugins: [react(), tsconfigPaths()],
test: {
globals: true,
environment: 'jsdom',
setupFiles: './test-setup.ts',
css: true,
server: {
deps: {
inline: ['next-auth'],
},
},
},
});
Could someone provide insight into why this error is occurring?
having selection selector in the global.css changes the input color
::selection {
@apply bg-highlight text-foreground;
}
Color is transparent
Input text color takes the value defined in selection
Make color transparent for a selection selector
Not sure if this should be done at the library level or in shadcn-ui?
.selection\:text-transparent *::selection {
color: transparent;
}
input-otp
is an accessible input that renders:
pointer-events:none
<input />
) with pointer-events:all
and position:absolute
inset:0
.In short: it's 1 underlying native input as an overlay on top of N layers of render.
However, the core implementation has some limitations. The known limits are:
iOS don't provide a way to style input::selection
in CSS, we end up with a non-transparent selection when at least 1 char of the input is selected within the underlying input. I'm applying super negative letter-spacing to ensure the visible selection becomes as thin as possible (=1px) but can't render smaller than 1px otherwise iOS touch callout doesn't pop up.
This would barely go noticed in a normal OTP flow where the user types in an OTP code or autofills it from his password manager. The user wouldn't even notice the selection as developers usually choose to automatically submit the form using <input onComplete
prop so there's no time to look at 1px selections.
TODO: add image
The user cannot click/touch/hold-move and select a slot since the native input's letters are shrinked into a ~1px thin width due to added CSS letter-spacing:-.5em
, resulting in all characters being a ultra thin condensed area. Unfortunately, the user cannot manually choose his selection by mouse/touch, only by keyboard.
The expected behavior would be:
The video above has been a feature request.
Related issues by the community are #31
Is your feature request related to a problem? Please describe.
I want both letters & numbers. Its pretty common in various services that I use for OTP.
Heck, most authenticator apps like Twitter use alphanumeric. Ik this bcz its logging me out for the last 30 days everyday so I have to type it out lol.
Describe the solution you'd like
inputMode="alphanumeric"
Implementation: https://github.com/pilcrowOnPaper/oslo/blob/c1f60eca2137cda93bb7aefed35781d85d12c7b6/src/crypto/random.ts#L52-L67
As soon as I add an onChange handler, the OTP input stops working (i.e. no digits appear when i type).
This is my code:
"use client"
import React from 'react';
import { OTPInput } from 'input-otp';
import { Slot, FakeDash } from '@/components/ui/otp';
import SectionContainer from '@/components/layout/SectionContainer';
const Test = () => {
return (
<SectionContainer>
<OTPInput
onChange={(code) => { console.log(code) }}
maxLength={6}
containerClassName="group flex items-center has-[:disabled]:opacity-30"
render={({ slots }) => (
<>
<div className="flex">
{slots.slice(0, 3).map((slot, idx) => (
<Slot key={idx} {...slot} />
))}
</div>
<FakeDash />
<div className="flex">
{slots.slice(3).map((slot, idx) => (
<Slot key={idx} {...slot} />
))}
</div>
</>
)}
/>
</SectionContainer>
)
};
export default Test;
The OTP input works without onChange={(code) => { console.log(code) }}
, but when I add it, all the input boxes remain empty as I type.
I would expected the cursor position / selected cell to be the slot that is clicked
The cursor position seems to be picked as a relative position of the entire input based on where in the x direction the slot is clicked
Select the slot that is clicked always
Entering an OTP and thinking one can go back and edit or select a char (even if they won't be able to)
not yet looked but will do
not yet looked but will do
great component btw!
When you've finished typing/pasting the code, you would want to change the focus to the submit button. Right now it stays on the last slot and typing will keep rewriting it. How can we achieve this?
Thanks for the great library by the way :)
Input can be cleared completely
Input keeps the last character filled, navigating to the next item and back fixes this behavior
I'm using backspace on the video to delete the characters
Just noticed that this happens on the landing page
When using within an HTML <form>
I need an id
and name
attribute for the underlying input.
Right now, I'm having to wrap the component and use an effect to accomplish this:
const {name, id} = props
const inputRef = useRef<HTMLInputElement>(null)
useEffect(() => {
const el = inputRef.current
if (!el) return
if (id) el.id = id
if (name) el.name = name
}, [])
return (
<OTPInput
ref={inputRef}
// ...
It'll be nice to have id
and name
props that can be directly passed to OTPInput
.
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
Either the 1Password button save button is disabled or the CSS is adjusted to ensure it does not overlap the actual input's text
The Save in 1Password Button overlaps the final digit in the OTP input obscuring the entered digit either partially or entirely.
You can read a bit more about handling or disabling the 1Password integration in 1Password's docs
n/a
n/a
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.