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

Add Switch Example using HTML button Element #1893

Merged
merged 58 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
e8278c9
initial switch example using button
jongund May 5, 2021
fe5d0a1
fixed button type issue
jongund May 5, 2021
49e56c1
fixed spelling issues
jongund May 5, 2021
c944f36
updated documenation and hover styling
jongund May 6, 2021
eac87ca
fixed spelling error and update cspell
jongund May 6, 2021
270e588
fixed spelling issue
jongund May 6, 2021
785033f
updated focus and hover styling for container rect
jongund May 6, 2021
cc5a247
updated documentation
jongund May 7, 2021
2bfbe7e
updated documentation
jongund May 7, 2021
5cdf2f8
updated width for label for Safari
jongund May 7, 2021
576ec83
added screen shot for list of landmarks for Orca
jongund May 11, 2021
c5c0b37
removed uwanted changes
jongund May 11, 2021
c96434f
updated examples for on/off labels to be in content and not CSS
jongund May 27, 2021
d7827ac
updated code to include DIV with class example-header for code pen sp…
jongund Jul 15, 2021
c59ded0
fixed code pen issue and added pointer cursor on hover
jongund Jul 27, 2021
af21f03
added place holder for focus styling
jongund Sep 14, 2021
0fc895d
added place holder for focus styling
jongund Sep 14, 2021
4372458
updated reference table
jongund Sep 21, 2021
3c99b94
updated switch button example
jongund Sep 21, 2021
86c9c32
updated accessibility documentation
jongund Sep 21, 2021
b16f2b3
updated documentation
jongund Sep 22, 2021
a1a977b
updated documentation
jongund Sep 22, 2021
6356087
Merge branch 'main' into switch-button
jongund Sep 22, 2021
b794a71
updated documentation
jongund Sep 22, 2021
1650613
initial switch example using button
jongund May 5, 2021
117cabc
fixed button type issue
jongund May 5, 2021
a393f12
fixed spelling issues
jongund May 5, 2021
7858793
updated documenation and hover styling
jongund May 6, 2021
bb5dab8
fixed spelling error and update cspell
jongund May 6, 2021
be1e660
fixed spelling issue
jongund May 6, 2021
4c9f477
updated focus and hover styling for container rect
jongund May 6, 2021
4af880b
updated documentation
jongund May 7, 2021
c3d2795
updated documentation
jongund May 7, 2021
0fafcb1
updated width for label for Safari
jongund May 7, 2021
fab7ea5
added screen shot for list of landmarks for Orca
jongund May 11, 2021
4d01157
removed uwanted changes
jongund May 11, 2021
e1c238c
updated examples for on/off labels to be in content and not CSS
jongund May 27, 2021
28ea6e1
updated code to include DIV with class example-header for code pen sp…
jongund Jul 15, 2021
ecb288b
fixed code pen issue and added pointer cursor on hover
jongund Jul 27, 2021
260e024
added place holder for focus styling
jongund Sep 14, 2021
4b7b65d
added place holder for focus styling
jongund Sep 14, 2021
91de552
updated switch button example
jongund Sep 21, 2021
40650b4
updated accessibility documentation
jongund Sep 21, 2021
9d02e9e
updated documentation
jongund Sep 22, 2021
1cb1614
updated documentation
jongund Sep 22, 2021
dfe145e
updated documentation
jongund Sep 22, 2021
0fdb708
Revise title
mcking65 Oct 3, 2021
b975a36
Minor editorial revisions to intro for consistency
mcking65 Oct 3, 2021
4790872
Remove excess section container
mcking65 Oct 3, 2021
d18cc06
Editorial revisions to roles, states, and props documentation for cla…
mcking65 Oct 3, 2021
dc88351
White space consistency
mcking65 Oct 3, 2021
13d6d2e
Merge and resolve conflicts with main
mcking65 Oct 4, 2021
b70f65d
updated index
jongund Oct 5, 2021
97ebd33
updated accessibility features documentation
jongund Oct 5, 2021
14edf15
fixed linting bug
jongund Oct 26, 2021
3edf83d
fixed regression test error messages
jongund Oct 26, 2021
1679639
Merge remote-tracking branch 'origin/main' into switch-button
mcking65 Oct 29, 2021
ecc4adc
Add links from main doc and other example
mcking65 Oct 29, 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
10 changes: 9 additions & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ <h2 id="examples_by_role_label">Examples by Role</h2>
<li><a href="menubar/menubar-editor.html">Editor Menubar</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="spinbutton/datepicker-spinbuttons.html">Date Picker Spin Button</a></li>
<li><a href="switch/switch-button.html">Switch Using HTML Button</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
<li><a href="treeview/treeview-1/treeview-1a.html">File Directory Treeview Using Computed Properties</a></li>
<li><a href="treeview/treeview-1/treeview-1b.html">File Directory Treeview Using Declared Properties</a></li>
<li><a href="treeview/treeview-navigation.html">Navigation Treeview</a> (<abbr title="High Contrast Support">HC</abbr>)</li>
Expand Down Expand Up @@ -361,7 +362,12 @@ <h2 id="examples_by_role_label">Examples by Role</h2>
</tr>
<tr>
<td><code>switch</code></td>
<td><a href="switch/switch.html">Switch</a></td>
<td>
<ul>
<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>
</ul>
</td>
</tr>
<tr>
<td><code>tab</code></td>
Expand Down Expand Up @@ -485,6 +491,7 @@ <h2 id="examples_by_props_label">Examples By Properties and States</h2>
<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.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>
<li><a href="toolbar/toolbar.html">Toolbar</a></li>
</ul>
Expand Down Expand Up @@ -613,6 +620,7 @@ <h2 id="examples_by_props_label">Examples By Properties and States</h2>
<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>
<li><a href="spinbutton/datepicker-spinbuttons.html">Date Picker Spin Button</a></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>
<li><a href="toolbar/toolbar.html">Toolbar</a></li>
</ul>
Expand Down
80 changes: 80 additions & 0 deletions examples/switch/css/switch-button.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
button[role="switch"] {
display: block;
margin: 2px;
padding: 4px 4px 8px 8px;
border: 0 solid #005a9c;
border-radius: 5px;
width: 17em;
text-align: left;
background-color: white;
}

button[role="switch"] .label {
position: relative;
top: -3px;
display: inline-block;
padding: 0;
margin: 0;
width: 10em;
vertical-align: middle;
}

button[role="switch"] svg {
forced-color-adjust: auto;
position: relative;
top: 4px;
}

button[role="switch"] svg rect {
fill-opacity: 0;
stroke-width: 2;
stroke: currentColor;
}

button[role="switch"] svg rect.off {
display: block;
stroke: currentColor;
fill: currentColor;
fill-opacity: 1;
}

button[role="switch"][aria-checked="true"] svg rect.off {
display: none;
}

button[role="switch"] svg rect.on {
display: none;
}

button[role="switch"][aria-checked="true"] svg rect.on {
color: green;
display: block;
stroke-color: currentColor;
fill: currentColor;
fill-opacity: 1;
}

button[role="switch"] span.off {
display: inline;
}

button[role="switch"] span.on {
display: none;
}

button[role="switch"][aria-checked="true"] span.off {
display: none;
}

button[role="switch"][aria-checked="true"] span.on {
display: inline;
}

button[role="switch"]:focus,
button[role="switch"]:hover {
padding: 2px 2px 6px 6px;
border-width: 2px;
outline: none;
background-color: #def;
cursor: pointer;
}
41 changes: 41 additions & 0 deletions examples/switch/js/switch-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This content is licensed according to the W3C Software License at
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*
* File: switch.js
*
* Desc: Switch widget that implements ARIA Authoring Practices
*/

'use strict';

class ButtonSwitch {
constructor(domNode) {
this.switchNode = domNode;
this.switchNode.addEventListener('click', () => this.toggleStatus());

// Set background color for the SVG container Rect
var color = getComputedStyle(this.switchNode).getPropertyValue(
'background-color'
);
var containerNode = this.switchNode.querySelector('rect.container');
containerNode.setAttribute('fill', color);
}

// Switch state of a switch
toggleStatus() {
const currentState =
this.switchNode.getAttribute('aria-checked') === 'true';
const newState = String(!currentState);

this.switchNode.setAttribute('aria-checked', newState);
}
}

// Initialize switches
window.addEventListener('load', function () {
// Initialize the Switch component on all matching DOM nodes
Array.from(document.querySelectorAll('button[role^=switch]')).forEach(
(element) => new ButtonSwitch(element)
);
});
Loading