Skip to content

Commit

Permalink
fix(a11y): prevent duplicate global a11y selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristiaanScheermeijer authored and AntonLantukh committed Feb 22, 2024
1 parent 6444282 commit b3ccaff
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 52 deletions.
2 changes: 0 additions & 2 deletions packages/ui-react/src/components/Account/Account.module.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@use '@jwp/ott-ui-react/src/styles/accessibility';

.textWithButtonContainer {
display: flex;
flex-direction: column;
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-react/src/components/Account/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ const Account = ({ panelClassName, panelHeaderClassName, canUpdateEmail = true }

return (
<>
<h1 className={styles.hideUntilFocus}>{t('nav.account')}</h1>
<h1 className="hideUntilFocus">{t('nav.account')}</h1>

<Form initialValues={initialValues}>
{[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`<Account> > renders and matches snapshot 1`] = `
<div>
<h1
class="_hideUntilFocus_c968f7"
class="hideUntilFocus"
>
nav.account
</h1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,3 @@
color: theme.$form-feedback-success-color;
background-color: theme.$form-feedback-success-bg-color;
}

.hidden {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
border: 0;
clip: rect(0, 0, 0, 0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const FormFeedback: React.FC<Props> = ({ children, variant = 'error', visible =
[styles.warning]: variant === 'warning',
[styles.success]: variant === 'success',
[styles.info]: variant === 'info',
[styles.hidden]: !visible,
hidden: !visible,
});

const ariaLive = variantAriaMap[variant];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ exports[`User Component tests > Account Page 1`] = `
class="_mainColumn_e9c5ca"
>
<h1
class="_hideUntilFocus_c968f7"
class="hideUntilFocus"
>
nav.account
</h1>
Expand Down
71 changes: 37 additions & 34 deletions packages/ui-react/src/styles/accessibility.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,52 @@ $focus-box-shadow: 0 0 1px 5px var(--highlight-color, variables.$white),
}
}

.hidden {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
border: 0;
clip: rect(0, 0, 0, 0);
}

.hideUntilFocus {
position: absolute;
width: 0;
height: 0;
overflow: hidden;
clip: rect(0 0 0 0);

&:focus {
position: static;
height: auto;
overflow: visible;
clip: auto;
}
}

@mixin accessibleOutline {
outline: 2px solid var(--highlight-color, #fff);
box-shadow: 0 0 2px 3px var(--highlight-contrast-color, #000);
}

@mixin accessibleOutlineContrast {
outline: 2px solid var(--highlight-contrast-color, #fff);
box-shadow: 0 0 2px 3px var(--highlight-color, #000);
}

/* Clearly visible focus rectangle (WCAG guidelines). */
@media (hover: hover) and (pointer: fine) {
a,
[role='button'],
button,
input {
@mixin globalClassNames {
/* Clearly visible focus rectangle (WCAG guidelines). */
@media (hover: hover) and (pointer: fine) {
a,
[role='button'],
button,
input {
&:focus {
@include accessibleOutline;
}
}
}

.hidden {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
border: 0;
clip: rect(0, 0, 0, 0);
}

.hideUntilFocus {
position: absolute;
width: 0;
height: 0;
overflow: hidden;
clip: rect(0 0 0 0);

&:focus {
@include accessibleOutline;
position: static;
height: auto;
overflow: visible;
clip: auto;
}
}
}
}
4 changes: 3 additions & 1 deletion platforms/web/src/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
--card-tag-bg: #{theme.$card-tag-bg};
}

@include accessibility.globalClassNames;

body {
margin: 0;
padding: 0;
Expand Down Expand Up @@ -78,4 +80,4 @@ h6 {

input {
font-family: var(--body-font-family);
}
}

0 comments on commit b3ccaff

Please sign in to comment.