Skip to content

Commit 2cff8d8

Browse files
desiprisgnikosdouvlis
authored andcommittedNov 22, 2022
feat(clerk-js): Add hoverAsFocus prop to Button primitive
The hoverAsFocus prop will enable the hover style on focus of the button. Useful for accessibility when we set the focusRing to false.
1 parent aa3ba35 commit 2cff8d8

File tree

6 files changed

+19
-10
lines changed

6 files changed

+19
-10
lines changed
 

‎packages/clerk-js/src/ui/components/OrganizationSwitcher/OtherOrganizationActions.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ const PreviewButton = (props: PropsOfComponent<typeof Button>) => {
106106
variant='ghost'
107107
colorScheme='neutral'
108108
focusRing={false}
109+
hoverAsFocus
109110
isDisabled={card.isLoading}
110111
sx={[
111112
t => ({

‎packages/clerk-js/src/ui/components/SignIn/SignInAccountSwitcher.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ const UserPreviewButton = (props: UserPreviewButtonProps) => {
9191
variant='ghost'
9292
colorScheme='neutral'
9393
focusRing={false}
94+
hoverAsFocus
9495
isDisabled={card.isLoading}
9596
sx={theme => ({ height: theme.sizes.$14, justifyContent: 'flex-start' })}
9697
{...rest}

‎packages/clerk-js/src/ui/components/UserButton/OtherSessionActions.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const UserPreviewButton = (props: UserPreviewButtonProps) => {
3030
variant='ghost'
3131
colorScheme='neutral'
3232
focusRing={false}
33+
hoverAsFocus
3334
isDisabled={card.isLoading}
3435
{...rest}
3536
sx={[

‎packages/clerk-js/src/ui/elements/Actions.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const Action = (props: ActionProps) => {
5555
colorScheme='neutral'
5656
textVariant='buttonSmallRegular'
5757
focusRing={false}
58+
hoverAsFocus
5859
// TODO: colors should be colorTextSecondary
5960
sx={[
6061
theme => ({

‎packages/clerk-js/src/ui/elements/Menu.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export const MenuItem = (props: MenuItemProps) => {
159159
<Button
160160
ref={buttonRef}
161161
focusRing={false}
162+
hoverAsFocus
162163
variant='ghost'
163164
colorScheme={destructive ? 'danger' : 'neutral'}
164165
role='menuitem'
@@ -173,9 +174,6 @@ export const MenuItem = (props: MenuItemProps) => {
173174
borderRadius: theme.radii.$none,
174175
paddingLeft: theme.space.$4,
175176
paddingRight: theme.space.$4,
176-
':focus': {
177-
backgroundColor: theme.colors.$blackAlpha200,
178-
},
179177
}),
180178
sx,
181179
]}

‎packages/clerk-js/src/ui/primitives/Button.tsx

+14-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Spinner } from './Spinner';
88

99
const vars = createCssVariables('accent', 'accentDark', 'accentDarker', 'accentLighter', 'accentLightest', 'border');
1010

11-
const { applyVariants, filterProps } = createVariants(theme => {
11+
const { applyVariants, filterProps } = createVariants((theme, opts: { hoverAsFocus: boolean }) => {
1212
return {
1313
base: {
1414
margin: 0,
@@ -60,35 +60,40 @@ const { applyVariants, filterProps } = createVariants(theme => {
6060
solid: {
6161
backgroundColor: vars.accent,
6262
color: theme.colors.$colorTextOnPrimaryBackground,
63-
'&:hover, :focus': { backgroundColor: vars.accentDark },
63+
'&:hover': { backgroundColor: vars.accentDark },
64+
'&:focus': opts.hoverAsFocus ? { backgroundColor: vars.accentDark } : undefined,
6465
'&:active': { backgroundColor: vars.accentDarker },
6566
},
6667
outline: {
6768
border: theme.borders.$normal,
6869
borderColor: vars.accentLighter,
6970
color: vars.accent,
70-
'&:hover, :focus': { backgroundColor: vars.accentLightest },
71+
'&:hover': { backgroundColor: vars.accentLightest },
72+
'&:focus': opts.hoverAsFocus ? { backgroundColor: vars.accentLightest } : undefined,
7173
'&:active': { backgroundColor: vars.accentLighter },
7274
},
7375
ghost: {
7476
color: vars.accent,
75-
'&:hover, :focus': { backgroundColor: vars.accentLightest },
77+
'&:hover': { backgroundColor: vars.accentLightest },
78+
'&:focus': opts.hoverAsFocus ? { backgroundColor: vars.accentLightest } : undefined,
7679
'&:active': { backgroundColor: vars.accentLighter },
7780
},
7881
icon: {
7982
color: vars.accent,
8083
border: theme.borders.$normal,
8184
borderRadius: theme.radii.$lg,
8285
borderColor: vars.border,
83-
'&:hover, :focus': { backgroundColor: vars.accentLightest },
86+
'&:hover': { backgroundColor: vars.accentLightest },
87+
'&:focus': opts.hoverAsFocus ? { backgroundColor: vars.accentLightest } : undefined,
8488
'&:active': { backgroundColor: vars.accentLighter },
8589
},
8690
ghostIcon: {
8791
color: vars.accent,
8892
minHeight: theme.sizes.$6,
8993
width: theme.sizes.$6,
9094
padding: `${theme.space.$1} ${theme.space.$1}`,
91-
'&:hover, :focus': { color: vars.accentDark },
95+
'&:hover': { color: vars.accentDark },
96+
'&:focus': opts.hoverAsFocus ? { backgroundColor: vars.accentDark } : undefined,
9297
'&:active': { color: vars.accentDarker },
9398
},
9499
link: {
@@ -99,7 +104,8 @@ const { applyVariants, filterProps } = createVariants(theme => {
99104
textTransform: 'none',
100105
padding: 0,
101106
color: vars.accent,
102-
'&:hover, :focus': { textDecoration: 'underline' },
107+
'&:hover': { textDecoration: 'underline' },
108+
'&:focus': opts.hoverAsFocus ? { textDecoration: 'underline' } : undefined,
103109
'&:active': { color: vars.accentDark },
104110
},
105111
roundWrapper: { padding: 0, margin: 0, height: 'unset', width: 'unset', minHeight: 'unset' },
@@ -126,6 +132,7 @@ type OwnProps = PrimitiveProps<'button'> & {
126132
loadingText?: string;
127133
isDisabled?: boolean;
128134
isActive?: boolean;
135+
hoverAsFocus?: boolean;
129136
};
130137
type ButtonProps = OwnProps & StyleVariants<typeof applyVariants>;
131138

0 commit comments

Comments
 (0)
Please sign in to comment.