mirror of
https://github.com/flarum/core.git
synced 2025-06-10 16:44:59 +02:00
[A11Y] Make checkboxes focusable (#3014)
* Add extra feature to a11y focusring mixin * Add visually hidden CSS class and mixin * Visually hide checkboxes (keep in focus/a11y tree) * Place checkbox focus ring around display element * Improve mobile checkbox/switch accessibility
This commit is contained in:
@ -33,7 +33,9 @@ export default class Checkbox extends Component {
|
|||||||
return (
|
return (
|
||||||
<label className={className}>
|
<label className={className}>
|
||||||
<input type="checkbox" checked={this.attrs.state} disabled={this.attrs.disabled} onchange={withAttr('checked', this.onchange.bind(this))} />
|
<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}
|
{vnode.children}
|
||||||
</label>
|
</label>
|
||||||
);
|
);
|
||||||
|
@ -2,18 +2,42 @@
|
|||||||
display: block;
|
display: block;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
& input[type="checkbox"] {
|
input[type="checkbox"] {
|
||||||
display: none;
|
position: absolute;
|
||||||
|
z-index: 1;
|
||||||
|
|
||||||
|
opacity: 0;
|
||||||
|
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
.add-keyboard-focus-ring-nearby("+ .Checkbox-display");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.Checkbox--switch {
|
.Checkbox--switch {
|
||||||
padding-left: 65px;
|
@left-pad: 65px;
|
||||||
|
|
||||||
|
padding-left: @left-pad;
|
||||||
margin: 5px 0;
|
margin: 5px 0;
|
||||||
|
|
||||||
|
input[type="checkbox"] {
|
||||||
|
top: -4px;
|
||||||
|
width: 50px;
|
||||||
|
height: 28px;
|
||||||
|
}
|
||||||
|
|
||||||
.Checkbox-display {
|
.Checkbox-display {
|
||||||
float: left;
|
float: left;
|
||||||
margin-left: -65px;
|
margin-left: -@left-pad;
|
||||||
margin-top: -4px;
|
margin-top: -4px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,13 +39,13 @@
|
|||||||
*
|
*
|
||||||
* For example...
|
* For example...
|
||||||
*
|
*
|
||||||
*? button { .addKeyboardFocusRing(":focus-within") }
|
*? button { .add-keyboard-focus-ring(":focus-within") }
|
||||||
* becomes
|
* becomes
|
||||||
*? button:focus-within { <styles> }
|
*? button:focus-within { <styles> }
|
||||||
*
|
*
|
||||||
* AND
|
* AND
|
||||||
*
|
*
|
||||||
*? button { .addKeyboardFocusRing(" :focus-within") }
|
*? button { .add-keyboard-focus-ring(" :focus-within") }
|
||||||
* becomes
|
* becomes
|
||||||
*? button :focus-within { <styles> }
|
*? button :focus-within { <styles> }
|
||||||
*/
|
*/
|
||||||
@ -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
|
* Allows an offset to be supplied for an a11y
|
||||||
* outline.
|
* outline.
|
||||||
|
@ -148,3 +148,13 @@ blockquote ol:last-child {
|
|||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
color: @muted-more-color;
|
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;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user