Created
February 28, 2024 21:01
-
-
Save guilhermerodz/c073ad56f1104f48dc75b9e9c16fb34c to your computer and use it in GitHub Desktop.
CSS hack for hiding input while autofill is ON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
syncTimeouts(() => { | |
if (input.matches(':autofill')) { | |
console.log('input has autofilled') | |
input.style.opacity = '0 !important' | |
} else { | |
console.log('input is no longer autofilled') | |
input.style.opacity = '1' | |
} | |
}) | |
if (!document.getElementById('input-otp-style')) { | |
const styleEl = document.createElement('style') | |
styleEl.id = 'input-otp-style' | |
document.head.appendChild(styleEl) | |
styleEl.sheet?.insertRule( | |
'[data-input-otp]::selection { background: transparent !important; }', | |
) | |
styleEl.sheet?.insertRule( | |
'[data-input-otp]:autofill { background: transparent !important; text: transparent !important; border-color: transparent !important; opacity: 0 !important; }', | |
) | |
styleEl.sheet?.insertRule( | |
'[data-input-otp]:-webkit-autofill { background: transparent !important; text: transparent !important; border-color: transparent !important; opacity: 0 !important }', | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment