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

[A11Y] Make checkboxes focusable #3014

Merged
merged 5 commits into from
Aug 16, 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
4 changes: 3 additions & 1 deletion js/src/common/components/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export default class Checkbox extends Component {
return (
<label className={className}>
<input type="checkbox" checked={this.attrs.state} disabled={this.attrs.disabled} onchange={withAttr('checked', this.onchange.bind(this))} />
<div className="Checkbox-display">{this.getDisplay()}</div>
<div className="Checkbox-display" aria-hidden="true">
{this.getDisplay()}
</div>
{vnode.children}
</label>
);
Expand Down
32 changes: 28 additions & 4 deletions less/common/Checkbox.less
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,42 @@
display: block;
cursor: pointer;
margin: 0;
position: relative;

input[type="checkbox"] {
SychO9 marked this conversation as resolved.
Show resolved Hide resolved
position: absolute;
z-index: 1;

opacity: 0;

top: 0;
bottom: 0;
left: 0;
right: 0;

& input[type="checkbox"] {
display: none;
width: 100%;
height: 100%;

cursor: pointer;

.add-keyboard-focus-ring-nearby("+ .Checkbox-display");
}
}
.Checkbox--switch {
padding-left: 65px;
@left-pad: 65px;

padding-left: @left-pad;
margin: 5px 0;

input[type="checkbox"] {
top: -4px;
width: 50px;
height: 28px;
}

.Checkbox-display {
float: left;
margin-left: -65px;
margin-left: -@left-pad;
margin-top: -4px;
}
}
Expand Down
36 changes: 34 additions & 2 deletions less/common/mixins/accessibility.less
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
*
* For example...
*
*? button { .addKeyboardFocusRing(":focus-within") }
*? button { .add-keyboard-focus-ring(":focus-within") }
* becomes
*? button:focus-within { <styles> }
*
* AND
*
*? button { .addKeyboardFocusRing(" :focus-within") }
*? button { .add-keyboard-focus-ring(" :focus-within") }
* becomes
*? button :focus-within { <styles> }
*/
Expand All @@ -57,6 +57,38 @@
}
}

/**
* This mixin allows support for a custom element nearby the focused one
* to have a focus style applied to it
*
* For example...
*
*? button { .add-keyboard-focus-ring-nearby("+ .myOtherElement") }
* becomes
*? button:-moz-focusring + .myOtherElement { <styles> }
*? button:focus-within + .myOtherElement { <styles> }
*/
.add-keyboard-focus-ring-nearby(@nearbySelector) {
@realNearbySelector: ~"@{nearbySelector}";

// We need to declare these separately, otherwise
// browsers will ignore `:focus-visible` as they
// don't understand `:-moz-focusring`

// These are the keyboard-only versions of :focus
&:-moz-focusring {
@{realNearbySelector} {
#private.__focus-ring-styles();
}
}

&:focus-visible {
@{realNearbySelector} {
#private.__focus-ring-styles();
}
}
}

/**
* Allows an offset to be supplied for an a11y
* outline.
Expand Down
10 changes: 10 additions & 0 deletions less/common/scaffolding.less
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,13 @@ blockquote ol:last-child {
font-size: 18px;
color: @muted-more-color;
}

.visually-hidden {
clip: rect(0 0 0 0);
clip-path: inset(50%);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}
davwheat marked this conversation as resolved.
Show resolved Hide resolved