guilhermerodz / input-otp

One time passcode Input. Accessible & unstyled.
https://input-otp.rodz.dev
MIT License
2.35k stars 47 forks source link

Support pasting codes as "XXX-XXX" #53

Open necky2 opened 2 months ago

necky2 commented 2 months ago

Is your feature request related to a problem? Please describe. By my understanding, splitting a code into 2 parts is done for better user readability. This library supports and even suggests, configuring the input as "XXX-XXX". I think it's a problem that a code with a hyphen or space in the middle cannot be pasted into the field.

Describe the solution you'd like Accept pasting of "XXX-XXX" and "XXX XXX" (and possibly other formats)

Describe alternatives you've considered -

Additional context I can have a shot at implementing this if others agree that this makes sense.

guilhermerodz commented 2 months ago

@necky2 thanks for bringing that up. While I still can't think of a great solution for this, there's a workaround such as handling onPaste event.

That would require a change on the current implementation, because it's always calling the library's default pasteListener.

If I allow for the user/developer setting up a custom paste event listener over the default library behavior, then it should be possible. I'm also not sure whether or not input.selectionStart and input.selectionEnd should be managed during this act of pasting a code with a decorative character.

trm217 commented 1 week ago

@guilhermerodz Pasting should really be a thing. From how I know the usage behaviour, the majority of people still use plain old copy and paste.