Skip to content

Commit

Permalink
Accessibility: have focus styles without having them too for those wh…
Browse files Browse the repository at this point in the history
…o don't use keyboards. (#1153)
  • Loading branch information
nisarhassan12 authored Apr 26, 2020
1 parent 876780b commit 997d9c2
Show file tree
Hide file tree
Showing 22 changed files with 127 additions and 50 deletions.
3 changes: 1 addition & 2 deletions config/postcss/mixins.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ const { customMedia } = require('./media')

const focus = {
'&:focus': {
color: 'var(--color-orange)',
outline: 'none'
color: 'var(--color-orange)'
}
}

Expand Down
1 change: 0 additions & 1 deletion src/components/Blog/Feed/Item/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

&:hover,
&:focus {
outline: none;
opacity: 0.7;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Blog/Post/Markdown/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@

&:hover,
&:focus {
outline: none;
opacity: 0.7;
color: var(--color-blue);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/components/Blog/Post/Share/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
}

&:focus {
outline: none;
opacity: 0.7;
}
}
4 changes: 3 additions & 1 deletion src/components/Community/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@
color: #999;
background-color: #ddd;

&:hover {
&:hover,
&:focus {
outline: none;
opacity: 0.7;
}
}
3 changes: 2 additions & 1 deletion src/components/Documentation/Layout/SidebarMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ const SidebarMenuItem: React.FC<ISidebarMenuItemProps> = ({
className={cn(
styles.sectionLink,
isActive && styles.active,
isRootParent && 'docSearch-lvl0'
isRootParent && 'docSearch-lvl0',
'link-with-focus'
)}
onClick={onClick}
>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Documentation/RightPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ const RightPanel: React.FC<IRightPanelProps> = ({
<Link
className={cn(
styles.headingLink,
current === slug && styles.current
current === slug && styles.current,
'link-with-focus'
)}
key={`link-${slug}`}
href={`#${slug}`}
Expand Down
4 changes: 3 additions & 1 deletion src/components/Documentation/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
cursor: pointer;
transition: 0.2s background-color ease-out;

&:hover {
&:hover,
&:focus {
outline: none;
background-color: var(--color-light-blue);
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/components/DownloadButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ const DownloadButtonDropdownItems: React.FC<IDownloadButtonDropdownItemsProps> =
<Link
download={item.download}
key={os}
className={cn(styles.dropdownItem, os === userOS && styles.active)}
className={cn(
styles.dropdownItem,
os === userOS && styles.active,
'link-with-focus'
)}
href={item.url}
onClick={(): void => onClick(os)}
>
Expand Down Expand Up @@ -151,7 +155,10 @@ const DownloadButton: React.FC<IDownloadButtonProps> = ({ openTop }) => {
<span className={styles.container} ref={containerRef}>
<TwoRowsButton
mode="purple"
className={cn(styles.button, isOpened && styles.opened)}
className={`${cn(
styles.button,
isOpened && styles.opened
)} btn-with-focus`}
title="Download"
active={isOpened}
description={`(${currentOS.title})`}
Expand Down
5 changes: 4 additions & 1 deletion src/components/Home/LandingHero/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ const LandingHero: React.FC<ILandingHeroProps> = ({ scrollToRef }) => {
</ShowOnly>
<TwoRowsButton
mode="outline"
className={cn(styles.actionButton, styles.watchVideo)}
className={`${cn(
styles.actionButton,
styles.watchVideo
)} btn-with-focus btn-with-focus--white`}
title="Watch video"
description="How it works"
icon={
Expand Down
2 changes: 1 addition & 1 deletion src/components/Home/LearnMore/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const LearnMore: React.FC<ILearnMoreProps> = ({ scrollToRef }) => {
}, [scrollToRef?.current])

return (
<button className={styles.button} onClick={onClick}>
<button className={`${styles.button} link-with-focus`} onClick={onClick}>
<span className={styles.icon}>
<img src="/img/learn-more.svg" alt="Learn More" />
</span>
Expand Down
2 changes: 1 addition & 1 deletion src/components/LayoutHeader/Nav/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const Nav: React.FC = () => (
</li>
</ul>
<PseudoButton
className={styles.getStartedButton}
className={`${styles.getStartedButton} btn-with-focus`}
href="/doc/tutorials/get-started"
onClick={(): void => logEvent('menu', 'get-started')}
>
Expand Down
1 change: 0 additions & 1 deletion src/components/LayoutHeader/Nav/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
}

&:focus {
outline: none;
color: var(--color-orange);
border-color: currentColor;
}
Expand Down
13 changes: 10 additions & 3 deletions src/components/MainLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IPageProps } from '../Page'
import LayoutHeader from '../LayoutHeader'
import HamburgerMenu from '../HamburgerMenu'
import LayoutFooter from '../LayoutFooter'
import { handleFirstTab } from '../../utils/front/accessibility'

import styles from './styles.module.css'

Expand All @@ -29,9 +30,6 @@ const MainLayout: LayoutComponent = ({
children,
modifiers = []
}) => {
useEffect(() => {
document.body.classList.add(styles.mainLayout)
}, [])
useEffect(() => {
if (className) {
document.body.classList.add(className)
Expand All @@ -42,6 +40,15 @@ const MainLayout: LayoutComponent = ({
}
}, [className])

useEffect(() => {
document.body.classList.add(styles.mainLayout)
window.addEventListener('keydown', handleFirstTab)

return (): void => {
window.removeEventListener('keydown', handleFirstTab)
}
}, [])

return (
<>
<LayoutHeader modifiers={modifiers} />
Expand Down
53 changes: 49 additions & 4 deletions src/components/Page/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,57 @@ body {
color: var(--color-black);
}

/* Focus state styles for interactive elements */

button:focus,
input:focus,
select:focus,
textarea:focus,
a:focus {
outline: 2px dotted var(--color-gray-hover);
outline-offset: 5px;
}

*::-moz-focus-inner {
border: 0;
}

body:not(.user-is-tabbing) button:focus,
body:not(.user-is-tabbing) input:focus,
body:not(.user-is-tabbing) select:focus,
body:not(.user-is-tabbing) textarea:focus,
body:not(.user-is-tabbing) a:focus {
outline: none;
}

body.user-is-tabbing .btn-with-focus {
&:focus {
color: #fff;
background-color: var(--color-orange);
border-color: var(--color-orange);
outline: none;
}

&--white:focus {
color: var(--color-black);
background: #fff;
border-color: #fff;
}
}

.link-with-focus {
border: 2px dotted transparent;
}

body.user-is-tabbing .link-with-focus {
&:focus {
outline: none;
border: 2px dotted;
}
}

/* Prevent mobile browsers from changing font-size */
* {
-webkit-text-size-adjust: none;
text-size-adjust: none;

&:focus {
outline: 0;
}
}
4 changes: 2 additions & 2 deletions src/components/Paginator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const Paginator: React.FC<IPaginatorProps> = ({
{previousPage && (
<>
<Link
className={cn(styles.link, styles.linkPrevious)}
className={cn(styles.link, styles.linkPrevious, 'link-with-focus')}
href={previousPage}
state={{ fromPaginator: true }}
>
Expand All @@ -74,7 +74,7 @@ const Paginator: React.FC<IPaginatorProps> = ({
{nextPage && (
<>
<Link
className={cn(styles.link, styles.linkNext)}
className={cn(styles.link, styles.linkNext, 'link-with-focus')}
href={nextPage}
state={{ fromPaginator: true }}
>
Expand Down
15 changes: 15 additions & 0 deletions src/components/PromoSection/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@
background-position-x: 147px;
transition: 0.2s background-color ease-out;

&:focus {
background-color: var(--color-orange);
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.21);
color: #fff;
outline: none;
}

& + & {
margin-left: 14px;

Expand All @@ -96,6 +103,14 @@
&:hover {
background-color: #f5f5f5;
}

&:focus {
background: var(--color-orange) url('/img/arrow_right_white.svg') right
center no-repeat;
background-position-x: 147px;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.21);
color: #fff;
}
}

@media (--xs-scr) {
Expand Down
15 changes: 0 additions & 15 deletions src/components/PseudoButton/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
font-weight: 700;
transition: 0.2s background-color ease-out;

&:focus {
outline: none;
}

&.small {
@mixin button-small;

Expand All @@ -37,12 +33,6 @@
&:hover {
background-color: #13a3bd;
}

&:focus {
border-color: var(--color-orange);
background: var(--color-orange);
color: #fff;
}
}

&.secondary {
Expand All @@ -54,10 +44,5 @@
border-color: var(--color-gray);
color: var(--color-gray-hover);
}

&:focus {
border-color: var(--color-orange);
color: var(--color-orange);
}
}
}
2 changes: 1 addition & 1 deletion src/components/SubscribeSection/Form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const Form: React.FC = () => {
</div>

<button
className={styles.button}
className={`${styles.button} btn-with-focus`}
type="submit"
name="subscribe"
id="mc-embedded-subscribe"
Expand Down
6 changes: 0 additions & 6 deletions src/components/SubscribeSection/Form/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
font-weight: 500;

&:focus {
outline: none;
background: var(--color-light-blue);
}

Expand All @@ -41,11 +40,6 @@
color: #13adc7;
cursor: pointer;

&:focus {
outline: none;
background-color: #daf1f5;
}

&:hover {
background-color: #daf1f5;
}
Expand Down
13 changes: 9 additions & 4 deletions src/components/Support/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
border-color: var(--color-purple);
color: var(--color-purple);

&:hover {
&:hover,
&:focus {
background-color: var(--color-purple);
}
}
Expand Down Expand Up @@ -94,7 +95,8 @@
border-color: var(--color-azure);
color: var(--color-azure);

&:hover {
&:hover,
&:focus {
background-color: var(--color-azure);
}
}
Expand All @@ -118,7 +120,8 @@
border-color: var(--color-orange-bright);
color: var(--color-orange-bright);

&:hover {
&:hover,
&:focus {
background-color: var(--color-orange-bright);
}
}
Expand Down Expand Up @@ -190,8 +193,10 @@
transition: 0.2s background-color ease-out;
cursor: pointer;

&.featureButton:hover {
&.featureButton:hover,
&.featureButton:focus {
color: #fff;
outline: none;
}
}

Expand Down
Loading

0 comments on commit 997d9c2

Please sign in to comment.