Why is the Checkbox component "jumping" when hovered on/off?

I've created the Checkbox component in React, but when I hover over it, the component appears to "jump". Why does it happen if the height of the component doesn't change? https://stackblitz.com/edit/vitejs-vite-fkhdvvb4?file=src%2Fcheckbox%2FCheckbox.tsx
StackBlitz
Vitejs - Vite (forked) - StackBlitz
Next generation frontend tooling. It's fast!
6 Replies
Chris Bolson
Chris Bolson3w ago
On your "checked" state you are removing the border, this makes the checkbox smaller, hence the "jump". Changing border:noneto. border-color: transparent; should remove the jump.
glutonium
glutonium3w ago
or u can also use outline this does not change the amount of space the element takes
ἔρως
ἔρως3w ago
outline is best reserved for accessibility for example, a keyboard user will rely on outlines to know where the focus is people that nuke the outlines and mess with them to uselessness make it hard/impossible for people to use the keyboard to navigate the website and in extension, anybody with mobility difficulties that cant use a mouse will be unable to use your site
glutonium
glutonium2w ago
hmm ok
Jochem
Jochem2w ago
to expand on this, the accessibility issue comes when you entirely remove the outline from a focusable element. In this case, overwriting it with the checked state would make it hard to tell what's going on when the element is checked, which could be solved by having a specific :checked:focus state. it's fine to use outline on non-focusable elements, or on focusable elements as long as you have a clear visual distinction between the focused and unfocused states
ἔρως
ἔρως2w ago
that is absolutely true however, it's easier if people just dont touch it, since people tend to forget those small touches and just nuke it all i see so many resets with the dreaded * { outline: none }

Did you find this page helpful?