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

Checkbox Example: Restore focus styling, add accessibility features documentation, and implement current code guide practices #1802

Merged
merged 24 commits into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5f9fbf4
updated JS to current coding practices and restored visual focus styl…
jongund Mar 4, 2021
9fefc77
updated border styling for focus
jongund Mar 4, 2021
76a6472
updated accessibility documentation
jongund Mar 8, 2021
7aa2b88
updated JS to current coding practices and restored visual focus styl…
jongund Mar 4, 2021
08226df
updated border styling for focus
jongund Mar 4, 2021
8bacc48
updated accessibility documentation
jongund Mar 8, 2021
a0e3a91
updated index file
jongund Jul 28, 2021
cd636f9
Merge branch 'main' into update-checkbox
jongund Jul 28, 2021
782e248
added pointer cursor
jongund Jul 28, 2021
384d868
updated hover styling and documentation
jongund Jul 28, 2021
4372458
updated reference table
jongund Sep 21, 2021
b05cace
Merge branch 'main' of github.com:w3c/aria-practices
jongund Sep 28, 2021
6044a71
Merge branch 'main' of github.com:w3c/aria-practices
jongund Oct 5, 2021
18d05a5
Merge branch 'main' into update-checkbox
jongund Oct 11, 2021
3749562
updated example to use SVG to make focus and hover styling simipler a…
jongund Oct 11, 2021
2f51958
updated regression test to remove CSS checking for state
jongund Oct 11, 2021
84959d9
fixed spelling mistake
jongund Oct 11, 2021
4809fa1
fixed spelling
jongund Oct 11, 2021
11d016a
updated accessibility features documentation
jongund Oct 11, 2021
79f7b48
updated documentation
jongund Oct 11, 2021
83abe6f
Update with latest from main
mcking65 Oct 17, 2021
6bfd2ab
Editorial revisions to accessibility features
mcking65 Oct 17, 2021
75a779a
Editorial revisions to state abnd props documentation
mcking65 Oct 17, 2021
99d0a9b
white space consistency
mcking65 Oct 17, 2021
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
80 changes: 0 additions & 80 deletions examples/checkbox/checkbox-1/js/checkbox.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

<!-- Core js and css shared by all examples; do not modify when using this template. -->
<link rel="stylesheet" href="https://www.w3.org/StyleSheets/TR/2016/base.css">
<link rel="stylesheet" href="../../css/core.css">
<script src="../../js/examples.js"></script>
<script src="../../js/highlight.pack.js"></script>
<script src="../../js/app.js"></script>
<link rel="stylesheet" href="../css/core.css">
<script src="../js/examples.js"></script>
<script src="../js/highlight.pack.js"></script>
<script src="../js/app.js"></script>

<link href="../css/checkbox.css" rel="stylesheet">
<link href="css/checkbox.css" rel="stylesheet">
<script src="js/checkbox.js" type="text/javascript"></script>
</head>
<body>
Expand Down Expand Up @@ -42,31 +42,27 @@ <h2 id="ex_label">Example</h2>
<h3 id="id-group-label">Sandwich Condiments</h3>
<div role="group" aria-labelledby="id-group-label">
<ul class="checkboxes">
<li><div role="checkbox" aria-checked="false" tabindex= "0">Lettuce</div></li>
<li><div role="checkbox" aria-checked="true" tabindex= "0">Tomato</div></li>
<li><div role="checkbox" aria-checked="false" tabindex= "0">Mustard</div></li>
<li><div role="checkbox" aria-checked="false" tabindex= "0">Sprouts</div></li>
<li><div role="checkbox" aria-checked="false" tabindex="0">Lettuce</div></li>
<li><div role="checkbox" aria-checked="true" tabindex="0">Tomato</div></li>
<li><div role="checkbox" aria-checked="false" tabindex="0">Mustard</div></li>
<li><div role="checkbox" aria-checked="false" tabindex="0">Sprouts</div></li>
</ul>
</div>

<script type="text/javascript">
window.onload = function () {

var checkboxes = document.querySelectorAll('[role="checkbox"]');

for (var i = 0; i < checkboxes.length; i++) {
var cb = new Checkbox(checkboxes[i]);
cb.init();
}

};
</script>

</div>

<div role="separator" id="ex_end_sep" aria-labelledby="ex_end_sep ex_label" aria-label="End of"></div>

</section>
</section>

<section>
<h2>Accessibility Features</h2>
<ul>
<li>To help assistive technology users understand that the Sandwich Condiment options is made of a group of four checkboxes, the checkboxes are wrapped in a <code>group</code> labeled by the heading that labels the sandwich options.</li>
<li>Because transparent borders are visible on some systems with operating system high contrast settings enabled, transparency cannot be used to create a visual difference between the element that is focused an other elements. Instead of using transparency, the focused element has a thicker border and less padding. When an element receives focus, its border changes from 0 to 2 pixels and padding is reduced by 2 pixels. When an element loses focus, its border changes from 2 pixels to 0 and padding is increased by 2 pixels.</li>
<li>To provide a visual indication the labels can also be used to change the state of a checkbox, the background color is changed when the pointer moves over the checkbox or the label.</li>
</ul>
</section>

<section>
<h2 id="kbd_label">Keyboard Support</h2>
Expand Down Expand Up @@ -181,7 +177,7 @@ <h2 id="rps_label">Role, Property, State, and Tabindex Attributes</h2>
<h2>Javascript and CSS Source Code</h2>
<ul id="css_js_files">
<li>
CSS: <a href="../css/checkbox.css" type="text/css">checkbox.css</a>
CSS: <a href="css/checkbox.css" type="text/css">checkbox.css</a>
</li>
<li>
Javascript: <a href="js/checkbox.js" type="text/javascript">checkbox.js</a>
Expand Down
30 changes: 17 additions & 13 deletions examples/checkbox/css/checkbox.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ ul.checkboxes {
[role="checkbox"] {
display: inline-block;
position: relative;
padding-left: 1.4em;
padding: 4px;
padding-left: 28px;
cursor: default;
}

[role="checkbox"]::before,
[role="checkbox"]::after {
position: absolute;
top: 50%;
left: 7px;
left: calc(28px - 14px);
transform: translate(-50%, -50%);
content: "";
}
Expand All @@ -36,7 +37,6 @@ ul.checkboxes {
);
}

[role="checkbox"][aria-checked="mixed"]::before,
[role="checkbox"][aria-checked="true"]::before {
border-color: hsl(216, 80%, 50%);
background: hsl(217, 95%, 68%);
Expand All @@ -47,15 +47,6 @@ ul.checkboxes {
);
}

[role="checkbox"][aria-checked="mixed"]::after {
display: block;
width: 8px;
border-bottom: 0.125em solid #fff;
transform: translate(-50%, -50%) rotateZ(45deg);
transform-origin: center center;
}

[role="checkbox"][aria-checked="mixed"]:active::after,
[role="checkbox"][aria-checked="true"]::after {
display: block;
width: 0.25em;
Expand All @@ -65,7 +56,6 @@ ul.checkboxes {
transform: translateY(-65%) translateX(-50%) rotate(45deg);
}

[role="checkbox"][aria-checked="mixed"]:active::before,
[role="checkbox"][aria-checked="true"]:active::before {
background-image: linear-gradient(
to bottom,
Expand All @@ -75,9 +65,23 @@ ul.checkboxes {
}

[role="checkbox"]:focus {
padding: 2px;
padding-left: calc(28px - 2px);
border: 2px solid #765;
border-radius: 5px;
background-color: #def;
outline: none;
}

[role="checkbox"]:focus::before,
[role="checkbox"]:focus::after {
left: calc(28px - 16px);
}

[role="checkbox"]:hover {
background-color: #def;
}

[role="checkbox"]:focus::before {
width: 16px;
height: 16px;
Expand Down
65 changes: 65 additions & 0 deletions examples/checkbox/js/checkbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* This content is licensed according to the W3C Software License at
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*
* File: Checkbox.js
*
* Desc: Checkbox widget that implements ARIA Authoring Practices
*/

'use strict';

class Checkbox {
constructor(domNode) {
this.domNode = domNode;
this.domNode.tabIndex = 0;

if (!this.domNode.getAttribute('aria-checked')) {
this.domNode.setAttribute('aria-checked', 'false');
}

this.domNode.addEventListener('keydown', this.onKeydown.bind(this));
this.domNode.addEventListener('click', this.onClick.bind(this));
}

toggleCheckbox() {
if (this.domNode.getAttribute('aria-checked') === 'true') {
this.domNode.setAttribute('aria-checked', 'false');
} else {
this.domNode.setAttribute('aria-checked', 'true');
}
}

/* EVENT HANDLERS */

onKeydown(event) {
var flag = false;

switch (event.key) {
case ' ':
this.toggleCheckbox();
flag = true;
break;

default:
break;
}

if (flag) {
event.stopPropagation();
event.preventDefault();
}
}

onClick() {
this.toggleCheckbox();
}
}

// Initialize checkboxes on the page
window.addEventListener('load', function () {
let checkboxes = document.querySelectorAll('.checkboxes [role="checkbox"]');
for (let i = 0; i < checkboxes.length; i++) {
new Checkbox(checkboxes[i]);
}
});
10 changes: 5 additions & 5 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ <h2 id="examples_by_role_label">Examples by Role</h2>
<td><code>checkbox</code></td>
<td>
<ul>
<li><a href="checkbox/checkbox-1/checkbox-1.html">Checkbox (Two State)</a></li>
<li><a href="checkbox/checkbox-2/checkbox-2.html">Checkbox (Mixed-State)</a></li>
<li><a href="checkbox/checkbox.html">Checkbox (Two State)</a></li>
</ul>
</td>
</tr>
Expand Down Expand Up @@ -144,7 +144,7 @@ <h2 id="examples_by_role_label">Examples by Role</h2>
<td>
<ul>
<li><a href="carousel/carousel-1-prev-next.html">Auto-Rotating Image Carousel with Buttons for Slide Control</a></li>
<li><a href="checkbox/checkbox-1/checkbox-1.html">Checkbox (Two State)</a></li>
<li><a href="checkbox/checkbox.html">Checkbox (Two State)</a></li>
<li><a href="menubar/menubar-editor.html">Editor Menubar</a></li>
<li><a href="slider/slider-color-viewer.html">Color Viewer Slider</a></li>
<li><a href="spinbutton/datepicker-spinbuttons.html">Date Picker Spin Button</a></li>
Expand Down Expand Up @@ -429,8 +429,8 @@ <h2 id="examples_by_props_label">Examples By Properties and States</h2>
<td><code>aria-checked</code></td>
<td>
<ul>
<li><a href="checkbox/checkbox-1/checkbox-1.html">Checkbox (Two State)</a></li>
<li><a href="checkbox/checkbox-2/checkbox-2.html">Checkbox (Mixed-State)</a></li>
<li><a href="checkbox/checkbox.html">Checkbox (Two State)</a></li>
<li><a href="menubar/menubar-editor.html">Editor Menubar</a></li>
<li><a href="radio/radio-activedescendant.html">Radio Group Using aria-activedescendant</a></li>
<li><a href="radio/radio.html">Radio Group Using Roving tabindex</a></li>
Expand Down Expand Up @@ -563,7 +563,7 @@ <h2 id="examples_by_props_label">Examples By Properties and States</h2>
<ul>
<li><a href="carousel/carousel-1-prev-next.html">Auto-Rotating Image Carousel with Buttons for Slide Control</a></li>
<li><a href="carousel/carousel-2-tablist.html">Auto-Rotating Image Carousel with Tabs for Slide Control</a></li>
<li><a href="checkbox/checkbox-1/checkbox-1.html">Checkbox (Two State)</a></li>
<li><a href="checkbox/checkbox.html">Checkbox (Two State)</a></li>
<li><a href="combobox/combobox-autocomplete-both.html">Editable Combobox With Both List and Inline Autocomplete</a></li>
<li><a href="combobox/combobox-autocomplete-list.html">Editable Combobox With List Autocomplete</a></li>
<li><a href="combobox/combobox-autocomplete-none.html">Editable Combobox without Autocomplete</a></li>
Expand Down Expand Up @@ -604,7 +604,7 @@ <h2 id="examples_by_props_label">Examples By Properties and States</h2>
<td><code>aria-labelledby</code></td>
<td>
<ul>
<li><a href="checkbox/checkbox-1/checkbox-1.html">Checkbox (Two State)</a></li>
<li><a href="checkbox/checkbox.html">Checkbox (Two State)</a></li>
<li><a href="combobox/combobox-datepicker.html">Date Picker Combobox</a></li>
<li><a href="combobox/combobox-select-only.html">Select-Only Combobox</a></li>
<li><a href="combobox/grid-combo.html">Editable Combobox with Grid Popup</a></li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { ariaTest } = require('..');
const { By, Key } = require('selenium-webdriver');
const { By } = require('selenium-webdriver');
const assertAttributeValues = require('../util/assertAttributeValues');
const assertAriaLabelledby = require('../util/assertAriaLabelledby');
const assertAriaRoles = require('../util/assertAriaRoles');
const assertTabOrder = require('../util/assertTabOrder');

const exampleFile = 'checkbox/checkbox-1/checkbox-1.html';
const exampleFile = 'checkbox/checkbox.html';

const ex = {
groupSelector: '#ex1 [role="group"]',
Expand Down Expand Up @@ -184,7 +184,7 @@ ariaTest(
// Send SPACE key to check box to select
await t.context.session
.findElement(By.css(checkboxSelector))
.sendKeys(Key.SPACE);
.sendKeys(' ');

t.true(
await waitAndCheckAriaChecked(t, checkboxSelector, 'true'),
Expand All @@ -201,7 +201,7 @@ ariaTest(
// Send SPACE key to check box to unselect
await t.context.session
.findElement(By.css(checkboxSelector))
.sendKeys(Key.SPACE);
.sendKeys(' ');

t.true(
await waitAndCheckAriaChecked(t, checkboxSelector, 'false'),
Expand Down