I'm currently creating a Password field with an option to hide or display the password in React/Ionic.
- I want to keep focus on the password field when you change the type of the input. (like PayPay Login page does) I'm doing it with
event.preventDefault()onmousedown-Event.
const input = document.querySelector('input')
function toggleVisibility() {
if (input.type === "text")
input.type = "password"
else
input.type = "text"
}
function keepFocus(event) {
event.preventDefault()
}
<input placeholder="Password" type="text">
<button onmousedown="keepFocus(event)" onclick="toggleVisibility()">Show Password</button>
Problem
- When I change the type of the input field the cursor flips back to the start of the input field. I would like to keep the cursor where it was before. (Again like on PayPal)