Skip to content

Input prohibition #4738

Answered by Rall3n
foxter111 asked this question in Q&A
Aug 23, 2021 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

Hello @foxter111,

I hope you don't mind me converting your issue into a discussion, as this is a more appropriate place for questions.

In its current state you can't directly prohibit the input of numbers into the Select component (by using <input pattern="">).
But you can remove numbers from the input by using the onInputChange prop.

<Select
  onInputChange={(inputValue) => {
    let value = inputValue.replace(/\d/g, '');

    // Either setState when controlled
    setInputValueState(value);
    // or return for uncontrolled.
    return value;
  }}
/>

CodeSandbox example

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@foxter111
Comment options

@Rall3n
Comment options

Rall3n Aug 24, 2021
Collaborator

Answer selected by foxter111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #4737 on August 23, 2021 12:23.