Skip to content

Commit

Permalink
feat: better focus styles
Browse files Browse the repository at this point in the history
  • Loading branch information
maxholman committed Dec 25, 2022
1 parent b4354f7 commit 2c339d8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
7 changes: 4 additions & 3 deletions lib/buttons.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ const base = style({
cursor: 'default',
filter: 'grayscale(1)',
},
'&:active': {
outlineWidth: genericVars.border.weight.thick,
outlineColor: 'initial',
'&:focus': {
outlineStyle: 'auto',
outlineOffset: genericVars.space.nano,
outlineColor: hsl(toneH, toneS, contrastSchemeVars.level4.l),
},
},
});
Expand Down
21 changes: 13 additions & 8 deletions lib/forms.css.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createVar, style } from '@vanilla-extract/css';
import { calc } from '@vanilla-extract/css-utils';
import { genericVars } from './design-system.css.js';
import { colorThemeVars, contrastSchemeVars } from './schemes/color.css.js';
import { hsl } from './utils.js';
Expand All @@ -18,29 +17,35 @@ export const formInput = style({
fontSize: genericVars.text.size.normal,
selectors: {
'&[readonly]': {
paddingLeft: 0,
paddingRight: 0,
borderLeft: 0,
borderRight: 0,
paddingInline: 0,
borderInline: 0,
borderColor: 'transparent',
backgroundColor: 'transparent',
},
'&::placeholder': {
color: hsl(0, 0, contrastSchemeVars.level4.l),
},
'&:focus': {
outlineStyle: 'auto',
outlineOffset: genericVars.space.nano,
outlineColor: hsl(360, 80, contrastSchemeVars.level4.l),
},
},
});

export const formInputNotCheckRadio = style({
selectors: {
'&:focus-visible': {
outline: 'max(2px, 0.15em) solid currentColor',
outlineStyle: 'auto',
outlineColor: hsl(
colorThemeVars.tones.accent.h,
colorThemeVars.tones.accent.s,
contrastSchemeVars.level1.l,
contrastSchemeVars.level4.l,
),
outlineOffset: calc(borderWidthVar).negate().toString(),
outlineOffset: genericVars.space.nano,
},
'&:focus': {
outlineOffset: 'initial',
},
},
});
Expand Down
7 changes: 7 additions & 0 deletions lib/links.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ const linkStyle = style({
),
},
cursor: 'pointer',
selectors: {
'&:focus-visible': {
outlineStyle: 'auto',
outlineOffset: genericVars.space.nano,
outlineColor: 'currentColor',
},
},
});

export const linkStyleVariant = styleVariants(
Expand Down

0 comments on commit 2c339d8

Please sign in to comment.