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

Radio Group: Rating Example #1870

Merged
merged 26 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d063b4b
an initial draft of using radio buttons for a rating widget
jongund Apr 23, 2021
0dbfcba
added draft of radio group used for a rating
jongund Apr 23, 2021
d71e88c
updated rating radio group to add test for role=none on SVG element
jongund Apr 23, 2021
dd23664
removed unused selectors
jongund Apr 23, 2021
3ab7687
Update radio-rating.css
jongund Apr 23, 2021
6776f34
fixed linting issues
jongund Apr 24, 2021
30c5756
fixed linting issues
jongund Apr 24, 2021
47b7b66
fixed linting issues
jongund Apr 24, 2021
a5f54da
added touch-action: pan-y;
jongund Apr 25, 2021
1991a26
removed zero rating example
jongund Jun 29, 2021
0bc07e2
updated regression tests
jongund Jul 1, 2021
c52185b
updated .vnurc and examples/index.html
jongund Jul 15, 2021
973e853
added pointer on hover and changed label
jongund Jul 27, 2021
adf15fa
added hover effect to change the number of stars filled
jongund Jul 28, 2021
6c9084b
updated documentation
jongund Jul 28, 2021
7e50c51
Merge in changes from main
mcking65 Nov 8, 2021
28221a2
updated rating radio example documentation and added test for aria-label
jongund Nov 8, 2021
9ae91e9
updated documentation on accessibility features
jongund Nov 8, 2021
4258b8d
updated accessibility documentation
jongund Nov 9, 2021
538c15a
removed hover styling
jongund Nov 9, 2021
8f3d606
updated documentation
jongund Nov 9, 2021
7b4cdbb
mnor editorial revisions plus white space
mcking65 Nov 10, 2021
11ce6ee
Minor editorial revisions to accessibility features documentation
mcking65 Nov 10, 2021
bd6a53b
Props documentation: change IDREF to ID_REFERENCE
mcking65 Nov 10, 2021
6c54c12
Props documentation: Remove incorrect statement that radio label prov…
mcking65 Nov 10, 2021
7f051eb
Add links from main doc, other radio examples, and rating slider
mcking65 Nov 10, 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
6 changes: 6 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ <h2 id="examples_by_role_label">Examples by Role</h2>
<ul>
<li><a href="menu-button/menu-button-links.html">Navigation Menu Button</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="menubar/menubar-navigation.html">Navigation Menubar</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="radio/radio-rating.html">Rating Radio Group</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="slider/slider-multithumb.html">Horizontal Multi-Thumb Slider</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="slider/slider-seek.html">Media Seek Slider</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="slider/slider-temperature.html">Vertical Temperature Slider</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
Expand Down Expand Up @@ -290,6 +291,7 @@ <h2 id="examples_by_role_label">Examples by Role</h2>
<td>
<ul>
<li><a href="radio/radio-activedescendant.html">Radio Group Using aria-activedescendant</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="radio/radio-rating.html">Rating Radio Group</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="radio/radio.html">Radio Group Using Roving tabindex</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="toolbar/toolbar.html">Toolbar</a></li>
</ul>
Expand All @@ -300,6 +302,7 @@ <h2 id="examples_by_role_label">Examples by Role</h2>
<td>
<ul>
<li><a href="radio/radio-activedescendant.html">Radio Group Using aria-activedescendant</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="radio/radio-rating.html">Rating Radio Group</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="radio/radio.html">Radio Group Using Roving tabindex</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="toolbar/toolbar.html">Toolbar</a></li>
</ul>
Expand Down Expand Up @@ -492,6 +495,7 @@ <h2 id="examples_by_props_label">Examples By Properties and States</h2>
<li><a href="checkbox/checkbox.html">Checkbox (Two State)</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="menubar/menubar-editor.html">Editor Menubar</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="radio/radio-activedescendant.html">Radio Group Using aria-activedescendant</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="radio/radio-rating.html">Rating Radio Group</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="radio/radio.html">Radio Group Using Roving tabindex</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="switch/switch-button.html">Switch Using HTML Button</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="switch/switch.html">Switch</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
Expand Down Expand Up @@ -644,6 +648,7 @@ <h2 id="examples_by_props_label">Examples By Properties and States</h2>
<li><a href="link/link.html">Link</a></li>
<li><a href="menubar/menubar-editor.html">Editor Menubar</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="menubar/menubar-navigation.html">Navigation Menubar</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="radio/radio-rating.html">Rating Radio Group</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="slider/slider-multithumb.html">Horizontal Multi-Thumb Slider</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="spinbutton/datepicker-spinbuttons.html">Date Picker Spin Button</a></li>
<li><a href="table/table.html">Table</a></li>
Expand Down Expand Up @@ -679,6 +684,7 @@ <h2 id="examples_by_props_label">Examples By Properties and States</h2>
<li><a href="menubar/menubar-navigation.html">Navigation Menubar</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="meter/meter.html">Meter</a></li>
<li><a href="radio/radio-activedescendant.html">Radio Group Using aria-activedescendant</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="radio/radio-rating.html">Rating Radio Group</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="radio/radio.html">Radio Group Using Roving tabindex</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="slider/slider-color-viewer.html">Color Viewer Slider</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="slider/slider-rating.html">Rating Slider</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
Expand Down
76 changes: 76 additions & 0 deletions examples/radio/css/radio-rating.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* CSS Document */

.rating-radio label {
display: block;
}

.rating-radio svg g[role="radio"] {
color: #005a9c;
}

.rating-radio svg {
forced-color-adjust: auto;
touch-action: pan-y;
}

.rating-radio svg .focus-ring,
.rating-radio svg .focus-ring-none {
stroke-width: 0;
fill-opacity: 0;
}

.rating-radio svg .star {
stroke-width: 2px;
stroke: currentColor;
fill-opacity: 0;
}

.rating-radio svg .star-none {
stroke-width: 3px;
stroke: currentColor;
fill-opacity: 0;
}

.rating-radio[data-rating-value="5"] svg .star {
fill: currentColor;
fill-opacity: 1;
}

.rating-radio[data-rating-value="1"] svg .star-1 .star {
fill: currentColor;
fill-opacity: 1;
}

.rating-radio[data-rating-value="2"] svg .star-2 .star {
fill: currentColor;
fill-opacity: 1;
}

.rating-radio[data-rating-value="3"] svg .star-3 .star {
fill: currentColor;
fill-opacity: 1;
}

.rating-radio[data-rating-value="4"] svg .star-4 .star {
fill: currentColor;
fill-opacity: 1;
}

/* focus styling */

.rating-radio:focus {
outline: none;
}

.rating-radio svg g:focus {
outline: none;
}

.rating-radio svg g:focus .focus-ring {
stroke-width: 2px;
stroke: currentColor;
}

.rating-radio:hover {
cursor: pointer;
}
140 changes: 140 additions & 0 deletions examples/radio/js/radio-rating.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
* This content is licensed according to the W3C Software License at
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*
* File: radio-rating.js
*
* Desc: Radio group widget that implements ARIA Authoring Practices
*/

'use strict';

class RatingRadioGroup {
constructor(groupNode) {
this.groupNode = groupNode;

this.radioButtons = [];

this.firstRadioButton = null;
this.lastRadioButton = null;

var rbs = this.groupNode.querySelectorAll('[role=radio]');

for (var i = 0; i < rbs.length; i++) {
var rb = rbs[i];

rb.tabIndex = -1;
rb.setAttribute('aria-checked', 'false');

rb.addEventListener('keydown', this.handleKeydown.bind(this));
rb.addEventListener('click', this.handleClick.bind(this));

this.radioButtons.push(rb);

if (!this.firstRadioButton) {
this.firstRadioButton = rb;
}
this.lastRadioButton = rb;
}

var value = groupNode.getAttribute('data-rating-value');
var index = parseInt(value);

if (value && index >= 0 && index < this.radioButtons.length) {
this.radioButtons[index].tabIndex = 0;
} else {
value = this.firstRadioButton.getAttribute('data-rating-value');
groupNode.getAttribute('data-rating-value', value);
this.firstRadioButton.tabIndex = 0;
}
}

setChecked(currentItem) {
this.groupNode.tabIndex = -1;
for (var i = 0; i < this.radioButtons.length; i++) {
var rb = this.radioButtons[i];
rb.setAttribute('aria-checked', 'false');
rb.tabIndex = -1;
}
this.currentValue = currentItem.getAttribute('data-rating');
this.groupNode.setAttribute('data-rating-value', this.currentValue);

currentItem.setAttribute('aria-checked', 'true');
currentItem.tabIndex = 0;
currentItem.focus();
}

setCheckedToPreviousItem(currentItem) {
var index;

if (currentItem === this.firstRadioButton) {
this.setChecked(this.lastRadioButton);
} else {
index = this.radioButtons.indexOf(currentItem);
this.setChecked(this.radioButtons[index - 1]);
}
}

setCheckedToNextItem(currentItem) {
var index;

if (currentItem === this.lastRadioButton) {
this.setChecked(this.firstRadioButton);
} else {
index = this.radioButtons.indexOf(currentItem);
this.setChecked(this.radioButtons[index + 1]);
}
}

/* EVENT HANDLERS */

handleKeydown(event) {
var tgt = event.currentTarget,
flag = false;

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

case 'Up':
case 'ArrowUp':
case 'Left':
case 'ArrowLeft':
this.setCheckedToPreviousItem(tgt);
flag = true;
break;

case 'Down':
case 'ArrowDown':
case 'Right':
case 'ArrowRight':
this.setCheckedToNextItem(tgt);
flag = true;
break;

default:
break;
}

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

handleClick(event) {
this.setChecked(event.currentTarget);
}
}

// Initialize radio button group

window.addEventListener('load', function () {
var radios = document.querySelectorAll('.rating-radio');
for (var i = 0; i < radios.length; i++) {
new RatingRadioGroup(radios[i]);
}
});
Loading