Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use focus-visible to hide outlines when using mouse #241

Merged
merged 2 commits into from
Jan 5, 2021
Merged
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
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;
}
Comment on lines -73 to -79
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like you added these styles back anywhere. Do I have that right? Was that the intent?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. I removed them all because we now have a better way to detect whether something if focused via mouse and via keyboard. If it's via mouse, there's no focus UI. If it's via keyboard, we should use the system default focus UI.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Cool. Makes sense.

`}

${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;
}
`;