0

I have a reference (created with useRef() ) that points to an input field, but when the user presses on "space" once, i get the following in my ref:

<input autocomplete="off" type="search" aria-expanded="false" aria-haspopup="true" placeholder="Unit" title=" " value=" "> 

Which means that the input field's placeholder doesn't show..

How can i detect if there's just one space entered, and if there is, reset the field to the following? (so that the placeholder shows)

<input autocomplete="off" type="search" aria-expanded="false" aria-haspopup="true" placeholder="Unit" title value> 

1 Answer 1

1

You could e.g. prevent user from entering a whitespace and the beginning of the input.

value={value.replace(/^\s+/, '')} ' some text' --> 'some text' ' ' --> '' 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.