the problem is that when ever in focusing the password input the button show up but when i try to click the button its lose the focus on the input and then the button disappear.
<div className='input-wrapper'>
<input
onFocus={() => setShowButton(true)}
onBlur={() => setShowButton(false)}
title='password'
type={
type === 'password' && toggle ?
"text" : "password"
}
{...props}
/>
{showButton && <button
type='button'
className={type === 'password' ? "password" : ""}
onClick={() => setToggle(!toggle)}
>
{toggle ? <ShowPasswordIcon /> : <HidePasswordIcon />}
</button>}
</div>
well i want that the button will be somehow included in the input focus (if that make sense somehow)
2
Answers
I believe you are looking for :focus-within:
React example, with focus management:
You can use the css pseudo-class
:focus-within
on the wrapper. When the wrapper on any of it’s children (button / input) is focused, the button would be visible: