Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add separator support #144

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

cliffordrice3
Copy link

Description

Adds support for separators such as hyphens, colons, commas, etc. between input items.

Useful for when the verification code in question has a format (e.g. 000-00-0000) that will help the user easily visually verify the correctness of the code.

Examples

Screenshot 2024-09-06 at 11 34 03 AM

Screenshot 2024-09-06 at 11 37 36 AM

Test Coverage

Maintains 100% coverage

Screenshot 2024-09-06 at 11 38 37 AM

@cliffordrice3
Copy link
Author

FWIW, can manage this w/ CSS, but it feels pretty hacky.

Open to other separator handling strategies (e.g. an alternative to length that is grouped lengths={[3, 2, 4]}, a config string format={'XXX-XX-XXXX'}, etc. etc.), but feels like this should have first-class support in the library. Let me know if there's a preferred way & I can make the changes

@sbking
Copy link

sbking commented Sep 12, 2024

Does this allow pasting input that has separators in the copied text?

@cliffordrice3
Copy link
Author

@sbking not currently, but good question.

On that note- what should the desired value be for inputs w/ separators. i.e. should 123-456 yield 123456 or 123-456 (I think 123-456 actually, as it's easier for the caller to strip out the separators as needed rather than add them in). Possibly could add another prop to include the separators in the value or not?

Can also add some UX handling for the user manually keying in a separator (e.g. user hits - in a box that follows a separator, ignore the input)

I'll do another pass at this by EOW to add support

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.

2 participants