CSS focus outline not removed with focus-visible polyfill #14479
-
I'm using a focus-visible polyfill, that way mouse events on clickable elements such as On nextjs, focus-visible successfully loads, because it's class and data attribute is added to the focus-visible is loaded by
Tried loading focus-visible inside The css used by both demos. // removes outline when clicking
.js-focus-visible :focus:not(.focus-visible) {
outline: none;
}
button {
display: block;
cursor: pointer;
border: none;
background: #ccc;
margin: 10px 0;
}
// displays when focusing with keyboard
button.focus-visible {
color: red;
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I was able to find the solution. The issue wasn't with NextJS but styled-jsx component. The solution was using the one-off global selector. For some reason using the Global style fails, but using the one-off global selector works. Global style fails <style jsx global>{`
.js-focus-visible :focus:not(.focus-visible) {
outline: none;
}
`}</style> But One-off global selector works <style jsx>{`
:global(.js-focus-visible) :focus:not(.focus-visible) {
outline: none;
}
`}</style> |
Beta Was this translation helpful? Give feedback.
-
Hey there, came across this discussion and I'm just curious why you wanted to remove outline? No offence but I thought it was a bad practice because of accessibility, right? |
Beta Was this translation helpful? Give feedback.
I was able to find the solution.
The issue wasn't with NextJS but styled-jsx component.
The solution was using the one-off global selector.
For some reason using the Global style fails, but using the one-off global selector works.
Global style fails
But One-off global selector works