Skip to content

Commit

Permalink
Merge pull request #241 from storybookjs/focus-visible
Browse files Browse the repository at this point in the history
Use focus-visible to hide outlines when using mouse
  • Loading branch information
domyen authored Jan 5, 2021
2 parents 1957d19 + e3ce406 commit 1f60429
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 72 deletions.
71 changes: 1 addition & 70 deletions src/components/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@ export const StyledButton = styled.button`
&:active {
transform: translate3d(0, 0, 0);
}
&:focus {
box-shadow: ${rgba(color.primary, 0.4)} 0 1px 9px 2px;
}
&:focus:hover {
box-shadow: ${rgba(color.primary, 0.2)} 0 8px 18px 0px;
}
`}
${Text} {
Expand Down Expand Up @@ -168,12 +160,6 @@ export const StyledButton = styled.button`
&:active {
box-shadow: rgba(0, 0, 0, 0.1) 0 0 0 3em inset;
}
&:focus {
box-shadow: ${rgba(color.primary, 0.4)} 0 1px 9px 2px;
}
&:focus:hover {
box-shadow: ${rgba(color.primary, 0.2)} 0 8px 18px 0px;
}
`
}
`}
Expand All @@ -193,12 +179,6 @@ export const StyledButton = styled.button`
&:active {
box-shadow: rgba(0, 0, 0, 0.1) 0 0 0 3em inset;
}
&:focus {
box-shadow: ${rgba(color.secondary, 0.4)} 0 1px 9px 2px;
}
&:focus:hover {
box-shadow: ${rgba(color.secondary, 0.2)} 0 8px 18px 0px;
}
`
}
`}
Expand All @@ -218,12 +198,6 @@ export const StyledButton = styled.button`
&:active {
box-shadow: rgba(0, 0, 0, 0.1) 0 0 0 3em inset;
}
&:focus {
box-shadow: ${rgba(color.darkest, 0.15)} 0 1px 9px 2px;
}
&:focus:hover {
box-shadow: ${rgba(color.darkest, 0.05)} 0 8px 18px 0px;
}
`
}
`}
Expand Down Expand Up @@ -251,16 +225,7 @@ export const StyledButton = styled.button`
&:active:focus:hover {
${/* This prevents the semi-transparent border from appearing atop the background */ ''}
background: ${opacify(0.05, color.border)};
box-shadow: ${rgba(color.darkest, 0.15)} 0 1px 9px 2px;
}
&:focus {
box-shadow: ${opacify(0.05, color.border)} 0 0 0 1px inset,
${rgba(color.darkest, 0.15)} 0 1px 9px 2px;
}
&:focus:hover {
box-shadow: ${opacify(0.05, color.border)} 0 0 0 1px inset,
${rgba(color.darkest, 0.05)} 0 8px 18px 0px;
box-shadow: transparent 0 0 0 1px inset;
}
`
};
Expand All @@ -282,12 +247,6 @@ export const StyledButton = styled.button`
box-shadow: ${color.primary} 0 0 0 1px inset;
color: ${color.lightest};
}
&:focus {
box-shadow: ${color.primary} 0 0 0 1px inset, ${rgba(color.primary, 0.4)} 0 1px 9px 2px;
}
&:focus:hover {
box-shadow: ${color.primary} 0 0 0 1px inset, ${rgba(color.primary, 0.2)} 0 8px 18px 0px;
}
`};
${(props) =>
Expand All @@ -306,14 +265,6 @@ export const StyledButton = styled.button`
box-shadow: ${color.secondary} 0 0 0 1px inset;
color: ${color.lightest};
}
&:focus {
box-shadow: ${color.secondary} 0 0 0 1px inset,
${rgba(color.secondary, 0.4)} 0 1px 9px 2px;
}
&:focus:hover {
box-shadow: ${color.secondary} 0 0 0 1px inset,
${rgba(color.secondary, 0.2)} 0 8px 18px 0px;
}
`};
${(props) =>
Expand All @@ -331,12 +282,6 @@ export const StyledButton = styled.button`
&:active {
box-shadow: rgba(0, 0, 0, 0.1) 0 0 0 3em inset;
}
&:focus {
box-shadow: ${rgba(color.primary, 0.4)} 0 1px 9px 2px;
}
&:focus:hover {
box-shadow: ${rgba(color.primary, 0.2)} 0 8px 18px 0px;
}
`
}
`}
Expand All @@ -356,12 +301,6 @@ export const StyledButton = styled.button`
&:active {
box-shadow: rgba(0, 0, 0, 0.1) 0 0 0 3em inset;
}
&:focus {
box-shadow: ${rgba(color.secondary, 0.4)} 0 1px 9px 2px;
}
&:focus:hover {
box-shadow: ${rgba(color.secondary, 0.2)} 0 8px 18px 0px;
}
`
}
`}
Expand All @@ -382,14 +321,6 @@ export const StyledButton = styled.button`
box-shadow: ${color.lightest} 0 0 0 1px inset;
color: ${color.darkest};
}
&:focus {
box-shadow: ${color.lightest} 0 0 0 1px inset,
${rgba(color.darkest, 0.4)} 0 1px 9px 2px;
}
&:focus:hover {
box-shadow: ${color.lightest} 0 0 0 1px inset,
${rgba(color.darkest, 0.2)} 0 8px 18px 0px;
}
`};
`;

Expand Down
1 change: 0 additions & 1 deletion src/components/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const GithubNavItem = styled(NavItem)`
`;

const MobileMenuTooltip = styled(WithTooltip)`
outline: none;
&:focus svg {
color: ${color.secondary};
}
Expand Down
6 changes: 5 additions & 1 deletion src/components/shared/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const bodyStyles = css`
input,
textarea,
select {
outline: none;
font-family: ${typography.type.primary};
}
Expand Down Expand Up @@ -122,4 +121,9 @@ export const GlobalStyle = createGlobalStyle`
body {
${bodyStyles}
}
// prevent mouse-clicks from focusing elements
// this removes the ugly blue outline
:focus:not(:focus-visible) {
outline: none;
}
`;

0 comments on commit 1f60429

Please sign in to comment.