Using states
How to apply a state, and the six places it usually goes wrong. For the model behind these rules, see Overview. For the full property table and tokens, see Reference.
Letting the component draw the state
States live in the components. A button already hovers, presses, focuses and disables; a row already selects. Writing them again on top is how a component ends up with two answers for the same state.
Reach for the tokens directly only when you are building something the library does not have.
Giving two states two properties
A row can be coloured by somebody and selected at the same time, so those two cannot both be a background.
Do
Selected is a leading edge, so the colour somebody set is still there. Both states are readable at once.
Do not
Selected paints the background, so the colour is gone. Somebody's data was overwritten by a state.
What else can this element be at the same time? Answer that before adding a state to it. If any of those already own the property you were about to take, take a different one.
Dimming only what is disabled
Opacity belongs to disabled. A second state that also dims is not a second state, because nobody can tell the two apart.
Do
Disabled dims. Locked keeps full contrast and says why with a glyph and its tooltip.
Do not
Two states, one treatment. There is no way to tell which one cannot be clicked and which one needs a permission.
Keeping a disabled control readable
Disabled means it cannot be operated. It does not mean the content is gone.
Somebody looking at a disabled field often wants to read and copy what is in it. Turning off text selection takes that away for no gain.
The form controls are already settled: the preset turns selection off together with pointer events on a disabled input, select, checkbox and the other controls it dresses. On a row, a panel or a container you disable yourself, leave selection on. Turn it off only where a drag or a double click would otherwise pick up the label of something you are dragging.
Never removing the focus outline
Focus is applied for the whole interface on :focus-visible, so a focusable element already draws a ring. You do not write it, and the one thing you must not do is take it away.
A few controls move the ring rather than drawing a second one: a bordered input takes it on its own boundary, the three controls that hide their real input draw it on the box beside them, and a composite widget clears it on the container and redraws it on the item the user is on. Moving a ring is not removing one.
An outline removed and not replaced makes the interface unusable by keyboard, and nothing looks broken until somebody tries to tab. If an outline is in the wrong place, move it with an offset.
Making everything clickable reachable
If an element responds to a click, it has to be reachable by keyboard and operable by Enter or Space.
The usual way this breaks is a click handler on a plain container. A div takes no focus and answers no key, so the behaviour exists for a pointer and does not exist otherwise. Use a real control, or give the element a role, a tab stop and key handling.
Anything that appears on hover needs the same treatment: a row action that only exists while a pointer is over it is unreachable for somebody who never moves a pointer.
Choosing between read-only and disabled
Read-only means you may read the value and not change it. Disabled means the control does not apply right now. Read-only against disabled has the full comparison.
Leave a read-only field at full contrast. Dimming is the disabled treatment, and a dimmed field will be read as disabled.