Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/migrate-focus-visible.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/ui': minor
---

Migrate from `:focus` to `:focus-visible` so focus rings only appear during keyboard navigation
38 changes: 37 additions & 1 deletion packages/ui/src/baseTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ const clerkTheme: Appearance = {
theme.shadows.$focusRing.replace('{{color}}', theme.colors.$colorRing),
].toString(),
},
'&:focus:not(:focus-visible)': {
boxShadow: BUTTON_SOLID_SHADOW(theme.colors.$primary500),
},
'&:focus-visible': {
boxShadow: [
BUTTON_SOLID_SHADOW(theme.colors.$primary500),
theme.shadows.$focusRing.replace('{{color}}', theme.colors.$colorRing),
].toString(),
},
},
'&[data-color="danger"]': {
boxShadow: BUTTON_SOLID_SHADOW(theme.colors.$danger500),
Expand All @@ -132,6 +141,15 @@ const clerkTheme: Appearance = {
theme.shadows.$focusRing.replace('{{color}}', theme.colors.$dangerAlpha200),
].toString(),
},
'&:focus:not(:focus-visible)': {
boxShadow: BUTTON_SOLID_SHADOW(theme.colors.$danger500),
},
'&:focus-visible': {
boxShadow: [
BUTTON_SOLID_SHADOW(theme.colors.$danger500),
theme.shadows.$focusRing.replace('{{color}}', theme.colors.$dangerAlpha200),
].toString(),
},
},
},
'&[data-variant="outline"]': {
Expand All @@ -143,6 +161,15 @@ const clerkTheme: Appearance = {
theme.shadows.$focusRing.replace('{{color}}', theme.colors.$colorRing),
].toString(),
},
'&:focus:not(:focus-visible)': {
boxShadow: BUTTON_OUTLINE_SHADOW(theme.colors.$borderAlpha100),
},
'&:focus-visible': {
boxShadow: [
BUTTON_OUTLINE_SHADOW(theme.colors.$borderAlpha100),
theme.shadows.$focusRing.replace('{{color}}', theme.colors.$colorRing),
].toString(),
},
},
'&[data-variant="bordered"]': {
borderWidth: 0,
Expand All @@ -153,6 +180,15 @@ const clerkTheme: Appearance = {
theme.shadows.$focusRing.replace('{{color}}', theme.colors.$colorRing),
].toString(),
},
'&:focus:not(:focus-visible)': {
boxShadow: BUTTON_OUTLINE_SHADOW(theme.colors.$borderAlpha100),
},
'&:focus-visible': {
boxShadow: [
BUTTON_OUTLINE_SHADOW(theme.colors.$borderAlpha100),
theme.shadows.$focusRing.replace('{{color}}', theme.colors.$colorRing),
].toString(),
},
},
},
badge: {
Expand Down Expand Up @@ -214,7 +250,7 @@ const clerkTheme: Appearance = {
},
selectSearchInput__countryCode: {
boxShadow: 'none',
'&:focus': { boxShadow: 'none' },
'&:focus-visible': { boxShadow: 'none' },
},
cardBox: {
borderWidth: 0,
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/elements/ArrowBlockButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ export const ArrowBlockButton = React.forwardRef<HTMLButtonElement, ArrowBlockBu
padding: `${theme.space.$1x5} ${theme.space.$3} ${theme.space.$1x5} ${theme.space.$2x5}`,
'--arrow-opacity': '0',
'--arrow-transform': `translateX(-${theme.space.$2})`,
'&:hover,&:focus ': {
'&:hover,&:focus-visible ': {
'--arrow-opacity': '0.5',
'--arrow-transform': 'translateX(0px)',
},
'[dir="rtl"] &': {
'--arrow-transform': `translateX(${theme.space.$2})`,
},
'[dir="rtl"] &:hover, [dir="rtl"] &:focus': {
'[dir="rtl"] &:hover, [dir="rtl"] &:focus-visible': {
'--arrow-transform': 'translateX(0px)',
},
},
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/elements/InputGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export const InputGroup = forwardRef<
position: 'relative',
zIndex: 1,
...common.borderVariants(theme).normal,
':focus-within,&[data-focus-within="true"]': {
'&:has(:focus-visible),&[data-focus-within="true"]': {
...common.borderVariants(theme, {
focusRing: true,
}).normal['&:focus'],
}).normal['&:focus-visible'],
},
})}
>
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/elements/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ const NavButton = (props: NavButtonProps) => {
'&:hover': {
backgroundColor: isActive ? undefined : t.colors.$neutralAlpha25,
},
'&:focus': {
'&:focus-visible': {
backgroundColor: isActive ? undefined : t.colors.$neutralAlpha50,
},
}),
Expand Down
8 changes: 4 additions & 4 deletions packages/ui/src/elements/PhoneInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ const PhoneInputBase = forwardRef<HTMLInputElement, PhoneInputProps & { feedback
position: 'relative',
borderRadius: theme.radii.$md,
zIndex: 1,
'&:focus-within,&[data-focus-within="true"]': {
...common.borderVariants(theme, { hasError: rest.hasError }).normal['&:focus'],
'&:has(:focus-visible),&[data-focus-within="true"]': {
...common.borderVariants(theme, { hasError: rest.hasError }).normal['&:focus-visible'],
},
})}
>
Expand Down Expand Up @@ -119,7 +119,7 @@ const PhoneInputBase = forwardRef<HTMLInputElement, PhoneInputProps & { feedback
borderEndEndRadius: '0',
borderStartEndRadius: '0',
paddingInlineEnd: t.space.$2,
':focus': {
'&:focus-visible': {
zIndex: 2,
boxShadow: 'none',
},
Expand Down Expand Up @@ -191,7 +191,7 @@ const PhoneInputBase = forwardRef<HTMLInputElement, PhoneInputProps & { feedback
borderStartStartRadius: 0,
borderEndStartRadius: 0,
paddingInlineStart: t.space.$1,
'&:focus': {
'&:focus-visible': {
borderColor: 'unset',
boxShadow: 'unset',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/elements/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export const Tab = (props: TabProps) => {
borderRadius: 0,
padding: `${t.space.$2x5} ${t.space.$0x25}`,
width: 'fit-content',
'&:hover, :focus': { backgroundColor: t.colors.$transparent, boxShadow: 'none' },
'&:hover, &:focus-visible': { backgroundColor: t.colors.$transparent, boxShadow: 'none' },
}),
sx,
]}
Expand Down
14 changes: 8 additions & 6 deletions packages/ui/src/primitives/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const { applyVariants, filterProps } = createVariants(
'&:hover': {
backgroundColor: vars.accentHover,
},
'&:focus': props.hoverAsFocus
'&:focus-visible': props.hoverAsFocus
? {
backgroundColor: vars.accentHover,
}
Expand All @@ -98,7 +98,7 @@ const { applyVariants, filterProps } = createVariants(
borderColor: theme.colors.$borderAlpha150,
color: theme.colors.$neutralAlpha600,
'&:hover': { backgroundColor: theme.colors.$neutralAlpha50 },
'&:focus': props.hoverAsFocus
'&:focus-visible': props.hoverAsFocus
? { backgroundColor: theme.colors.$neutralAlpha50, borderColor: theme.colors.$borderAlpha300 }
: undefined,
},
Expand All @@ -109,14 +109,16 @@ const { applyVariants, filterProps } = createVariants(
color: vars.accentContrast,
backgroundColor: vars.accent,
'&:hover': { backgroundColor: vars.accentHover },
'&:focus': props.hoverAsFocus
'&:focus-visible': props.hoverAsFocus
? { backgroundColor: vars.accentHover, borderColor: theme.colors.$borderAlpha300 }
: undefined,
},
ghost: {
color: vars.accent,
'&:hover': { backgroundColor: vars.alpha, color: vars.accentHover },
'&:focus': props.hoverAsFocus ? { backgroundColor: vars.alpha, color: vars.accentHover } : undefined,
'&:focus-visible': props.hoverAsFocus
? { backgroundColor: vars.alpha, color: vars.accentHover }
: undefined,
},
link: {
minHeight: 'fit-content',
Expand All @@ -126,7 +128,7 @@ const { applyVariants, filterProps } = createVariants(
padding: 0,
color: theme.colors.$primary500,
'&:hover': { textDecoration: 'underline' },
'&:focus': props.hoverAsFocus ? { textDecoration: 'underline' } : undefined,
'&:focus-visible': props.hoverAsFocus ? { textDecoration: 'underline' } : undefined,
},
linkDanger: {
minHeight: 'fit-content',
Expand All @@ -136,7 +138,7 @@ const { applyVariants, filterProps } = createVariants(
padding: 0,
color: theme.colors.$danger500,
'&:hover': { textDecoration: 'underline' },
'&:focus': props.hoverAsFocus ? { textDecoration: 'underline' } : undefined,
'&:focus-visible': props.hoverAsFocus ? { textDecoration: 'underline' } : undefined,
},
unstyled: {},
roundWrapper: { padding: 0, margin: 0, height: 'unset', width: 'unset', minHeight: 'unset' },
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/primitives/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const { applyVariants, filterProps } = createVariants(theme => ({
},
focusRing: {
true: {
'&:focus': {
'&:focus-visible': {
outline: 'none',
...common.focusRing(theme),
},
Expand Down
60 changes: 37 additions & 23 deletions packages/ui/src/styledSystem/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,42 +94,50 @@ const borderVariants = (t: InternalTheme, props?: any) => {
boxShadow: hoverBoxShadow,
},
};
const borderColor = !props?.hasError
? !props?.hasWarning
? t.colors.$borderAlpha150
: t.colors.$warningAlpha300
: t.colors.$dangerAlpha500;

const boxShadow = !props?.hasError
? !props?.hasWarning
? t.colors.$borderAlpha100
: t.colors.$warningAlpha50
: t.colors.$borderAlpha150;

const defaultBoxShadow = t.shadows.$input.replace('{{color}}', boxShadow);

const focusStyleValues = {
borderColor: hoverBorderColor,
WebkitTapHighlightColor: 'transparent',
boxShadow: [
hoverBoxShadow,
t.shadows.$focusRing.replace(
'{{color}}',
!props?.hasError ? t.colors.$borderAlpha150 : (t.colors.$dangerAlpha200 as string),
),
].toString(),
};
const focusStyles =
props?.focusRing === false
? {}
: {
'&:focus': {
borderColor: hoverBorderColor,
WebkitTapHighlightColor: 'transparent',
boxShadow: [
hoverBoxShadow,
t.shadows.$focusRing.replace(
'{{color}}',
!props?.hasError ? t.colors.$borderAlpha150 : (t.colors.$dangerAlpha200 as string),
),
].toString(),
'&:focus': focusStyleValues,
'&:focus:not(:focus-visible)': {
borderColor,
boxShadow: defaultBoxShadow,
},
'&:focus-visible': focusStyleValues,
};

const borderColor = !props?.hasError
? !props?.hasWarning
? t.colors.$borderAlpha150 // Default border color
: t.colors.$warningAlpha300 // Warning border color
: t.colors.$dangerAlpha500; // Error border color

const boxShadow = !props?.hasError
? !props?.hasWarning
? t.colors.$borderAlpha100 // Default box shadow color
: t.colors.$warningAlpha50 // Warning box shadow color
: t.colors.$borderAlpha150; // Error box shadow color

return {
normal: {
borderRadius: t.radii.$md,
borderWidth: t.borderWidths.$normal,
borderStyle: t.borderStyles.$solid,
borderColor,
boxShadow: t.shadows.$input.replace('{{color}}', boxShadow),
boxShadow: defaultBoxShadow,
transitionProperty: t.transitionProperty.$common,
transitionTimingFunction: t.transitionTiming.$common,
transitionDuration: t.transitionDuration.$focusRing,
Expand Down Expand Up @@ -161,6 +169,12 @@ const focusRing = (t: InternalTheme) => {
'&:focus': {
...focusRingStyles(t),
},
'&:focus:not(:focus-visible)': {
boxShadow: 'none',
},
'&:focus-visible': {
...focusRingStyles(t),
},
} as const;
};

Expand Down
8 changes: 4 additions & 4 deletions packages/ui/src/themes/neobrutalism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createTheme } from './createTheme';
const buttonStyle = {
boxShadow: '3px 3px 0px #000',
border: '2px solid #000',
'&:focus': {
'&:focus-visible': {
boxShadow: '4px 4px 0px #000',
border: '2px solid #000',
transform: 'scale(1.01)',
Expand Down Expand Up @@ -49,7 +49,7 @@ export const neobrutalism = createTheme({
...buttonStyle,
...shadowStyle,
transition: 'all 0.2s ease-in-out',
'&:focus': {
'&:focus-visible': {
boxShadow: '4px 4px 0px #000',
border: '2px solid #000',
transform: 'scale(1.01)',
Expand All @@ -69,7 +69,7 @@ export const neobrutalism = createTheme({
formFieldInput: {
...shadowStyle,
transition: 'all 0.2s ease-in-out',
'&:focus': {
'&:focus-visible': {
boxShadow: '4px 4px 0px #000',
border: '2px solid #000',
transform: 'scale(1.01)',
Expand Down Expand Up @@ -102,7 +102,7 @@ export const neobrutalism = createTheme({
footerActionLink: {
fontWeight: '700',
borderBottom: '3px solid',
'&:focus': {
'&:focus-visible': {
boxShadow: 'none',
},
},
Expand Down
Loading