Skip to content

Commit e4211cc

Browse files
authored
fix: add missing focus state styling to buttons and checkboxes (#10614)
* fix: add focus styling to checkboxes * fix: add focus styling to icon buttons * fix: add focus styling to switches * fix: swap outlines for box-shadows for more styling control
1 parent f400d8a commit e4211cc

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

site/src/theme/theme.ts

+39-2
Original file line numberDiff line numberDiff line change
@@ -427,15 +427,42 @@ dark = createTheme(dark, {
427427
MuiCheckbox: {
428428
styleOverrides: {
429429
root: {
430+
/**
431+
* Adds focus styling to checkboxes (which doesn't exist normally, for
432+
* some reason?).
433+
*
434+
* The checkbox component is a root span with a checkbox input inside
435+
* it. MUI does not allow you to use selectors like (& input) to
436+
* target the inner checkbox (even though you can use & td to style
437+
* tables). Tried every combination of selector possible (including
438+
* lots of !important), and the main issue seems to be that the
439+
* styling just never gets processed for it to get injected into the
440+
* CSSOM.
441+
*
442+
* Had to settle for adding styling to the span itself (which does
443+
* make the styling more obvious, even if there's not much room for
444+
* customization).
445+
*/
446+
"&.Mui-focusVisible": {
447+
boxShadow: `0 0 0 2px ${colors.blue[7]}`,
448+
},
449+
430450
"&.Mui-disabled": {
431451
color: colors.gray[11],
432452
},
433453
},
434454
},
435455
},
436456
MuiSwitch: {
437-
defaultProps: {
438-
color: "primary",
457+
defaultProps: { color: "primary" },
458+
styleOverrides: {
459+
root: {
460+
".Mui-focusVisible .MuiSwitch-thumb": {
461+
// Had to thicken outline to make sure that the focus color didn't
462+
// bleed into the thumb and was still easily-visible
463+
boxShadow: `0 0 0 3px ${colors.blue[7]}`,
464+
},
465+
},
439466
},
440467
},
441468
MuiAutocomplete: {
@@ -496,5 +523,15 @@ dark = createTheme(dark, {
496523
},
497524
},
498525
},
526+
527+
MuiIconButton: {
528+
styleOverrides: {
529+
root: {
530+
"&.Mui-focusVisible": {
531+
boxShadow: `0 0 0 2px ${colors.blue[7]}`,
532+
},
533+
},
534+
},
535+
},
499536
},
500537
} as ThemeOptions);

0 commit comments

Comments
 (0)