Skip to content

Instantly share code, notes, and snippets.

@guilhermerodz
Created February 28, 2024 21:01
Show Gist options
  • Save guilhermerodz/c073ad56f1104f48dc75b9e9c16fb34c to your computer and use it in GitHub Desktop.
Save guilhermerodz/c073ad56f1104f48dc75b9e9c16fb34c to your computer and use it in GitHub Desktop.
CSS hack for hiding input while autofill is ON
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