- Horizontal Slider Examples:
- Demonstrates using three horizontally aligned single-thumb sliders to make a color picker.
+ Horizontal Slider Examples:
+ Demonstrates using three horizontally aligned single-thumb sliders to make a color viewer.
- Following is an example of a color picker that demonstrates the
- slider design pattern.
- Change the background color of the box below the picker by adjusting the sliders for red, green, and blue values.
- The HEX and RGB values of the chosen color are displayed by the color box.
-
Slider Examples with aria-orientation and aria-valuetext
- The following example of a hypothetical online thermostat demonstrates the
+ The following example of a hypothetical online thermostat demonstrates the
slider design pattern.
The desired temperature is set with the first slider, which is vertically oriented.
Two horizontal sliders set fan speed and mode.
@@ -36,9 +36,9 @@
Slider Examples with aria-orientation and aria-valuetext
Similar examples include:
-
Horizontal Slider Examples: Demonstrates using three horizontally aligned sliders to make a color picker.
+
Horizontal Slider Examples: Demonstrates using three horizontally aligned sliders to make a color viewer.
+ Following is an example of a color viewer that demonstrates the
+ slider design pattern.
+ Change the background of the color view box by adjusting the sliders for red, green, and blue values.
+ The HEX and RGB values of the chosen color are displayed by the color view box.
+
+
Similar examples include:
+
+
+ Slider Example with increment and decrement buttons:
+ Color viewer with three sliders to choose RGB colors with additional buttons to support setting the slider value on mobile devices without a keyboard.
+
+ The three sliders are wrapped in a group to help assistive technology users understand that all three elements together represent a color viewer.
+
+
+ The placement of the slider value above the thumb supports users with low vision by making it easier for them to view the value as they change the slider position.
+
+
+ Use of SVG enables high contrast support by providing a means for text and rect element to adapt to high contrast colors using the currentColor value for the stroke and fill properties.
+
+
+
+
+
+
Keyboard Support
+
+
+
+
Key
+
Function
+
+
+
+
+
Right Arrow
+
Increases slider value one step.
+
+
+
Up Arrow
+
Increases slider value one step.
+
+
+
Left Arrow
+
Decreases slider value one step.
+
+
+
Down Arrow
+
Decreases slider value one step.
+
+
+
Page Up
+
Increases slider value multiple steps. In this slider, jumps ten steps.
+
+
+
Page Down
+
Decreases slider value multiple steps. In this slider, jumps ten steps.
+
+
+
Home
+
Sets slider to its minimum value.
+
+
+
End
+
Sets slider to its maximum value.
+
+
+
+
+
+
+
+
Role, Property, State, and Tabindex Attributes
+
+
+
+
Role
+
Attribute
+
Element
+
Usage
+
+
+
+
+
group
+
+
div
+
+
+
Identifies the div as a group of sliders.
+
The group provides a means to inform assistive technology users that the three sliders are all related to the single purpose of choosing a color.
+
+
+
+
+
+
aria-labelledby="IDREF"
+
div
+
+
+
Contains the ID that reference the div element that provide the accessible name for the group.
+
One ID refers to the visible label Color Viewer.
+
+
+
+
+
+ slider
+
+
+
+ div
+
+
+
+
Identifies the element as a slider.
+
Set on the div that represents as the movable thumb because it is the operable element that represents the slider value.
+
+
+
+
+
+
+ tabindex=0
+
+
+ div
+
+
Includes the slider thumb in the page tab sequence.
+
+
+
+
+ aria-valuemax=255
+
+
+ div
+
+
Specifies the maximum value of the slider.
+
+
+
+
+ aria-valuemin=0
+
+
+ div
+
+
Specifies the minimum value of the slider.
+
+
+
+
+ aria-valuenow=NUMBER
+
+
+ div
+
+
Indicates the current value of the slider.
+
+
+
+
+ aria-labelledby=IDREF
+
+
+ div
+
+
Refers to the element containing the name of the slider.
+
+
+
+
aria-label="NAME_STRING"
+
button
+
Defines the accessible name for each increase and decrease button (-10, -1, +1, and +10).
+
+
+
+
tabindex="-1"
+
button
+
Removes the decrease and increase buttons from the page Tab sequence while keeping them focusable so they can be accessed with touch-based assistive technologies.
+
+
+
+
+
+
+
+
diff --git a/test/tests/slider_slider-1.js b/test/tests/slider_slider-color-viewer.js
similarity index 86%
rename from test/tests/slider_slider-1.js
rename to test/tests/slider_slider-color-viewer.js
index da4399249f..ba5fa8a0d9 100644
--- a/test/tests/slider_slider-1.js
+++ b/test/tests/slider_slider-color-viewer.js
@@ -4,13 +4,14 @@ const assertAttributeValues = require('../util/assertAttributeValues');
const assertAriaLabelledby = require('../util/assertAriaLabelledby');
const assertAriaRoles = require('../util/assertAriaRoles');
-const exampleFile = 'slider/slider-1.html';
+const exampleFile = 'slider/slider-color-viewer.html';
const ex = {
+ groupSelector: '#ex1 [role="group"]',
sliderSelector: '#ex1 [role="slider"]',
- hexTextInput: '#idColorValueHex',
- rgbTextInput: '#idColorValueRGB',
- colorBox: '#idColorBox',
+ hexTextInput: '#ex1 .color-info .color-value-hex',
+ rgbTextInput: '#ex1 .color-info .color-value-rgb',
+ colorBox: '#ex1 .color-info .color-box',
};
const testDisplayMatchesValue = async function (t, rgbString) {
@@ -72,8 +73,34 @@ const sendAllSlidersToEnd = async function (t) {
}
};
+const sendAllSlidersToBeginning = async function (t) {
+ const sliders = await t.context.queryElements(t, ex.sliderSelector);
+
+ for (let slider of sliders) {
+ await slider.sendKeys(Key.HOME);
+ }
+};
+
// Attributes
+ariaTest(
+ 'role="group" on div element',
+ exampleFile,
+ 'group-role',
+ async (t) => {
+ await assertAriaRoles(t, 'ex1', 'group', '1', 'div');
+ }
+);
+
+ariaTest(
+ '"aria-labelledby" set on group',
+ exampleFile,
+ 'aria-labelledby',
+ async (t) => {
+ await assertAriaLabelledby(t, ex.groupSelector);
+ }
+);
+
ariaTest(
'role="slider" on div element',
exampleFile,
@@ -115,7 +142,7 @@ ariaTest(
exampleFile,
'aria-valuenow',
async (t) => {
- await assertAttributeValues(t, ex.sliderSelector, 'aria-valuenow', '0');
+ await assertAttributeValues(t, ex.sliderSelector, 'aria-valuenow', '128');
}
);
@@ -143,12 +170,12 @@ ariaTest(
t.is(
await redSlider.getAttribute('aria-valuenow'),
- '1',
- 'After sending 1 arrow right key to the red slider, the value of the red slider should be 1'
+ '129',
+ 'After sending 1 arrow right key to the red slider, the value of the red slider should be 129'
);
t.true(
- await testDisplayMatchesValue(t, '1, 0, 0'),
- 'Display should match rgb(1, 0, 0)'
+ await testDisplayMatchesValue(t, '129, 128, 128'),
+ 'Display should match rgb(129, 128, 128)'
);
// Send more than 255 keys to red slider
@@ -162,8 +189,8 @@ ariaTest(
'After sending 260 arrow right key, the value of the red slider should be 255'
);
t.true(
- await testDisplayMatchesValue(t, '255, 0, 0'),
- 'Display should match rgb(255, 0, 0)'
+ await testDisplayMatchesValue(t, '255, 128, 128'),
+ 'Display should match rgb(255, 128, 128)'
);
// Send 1 key to green slider
@@ -172,12 +199,12 @@ ariaTest(
t.is(
await greenSlider.getAttribute('aria-valuenow'),
- '1',
- 'After sending 1 arrow right key to the blue slider, the value of the green slider should be 1'
+ '129',
+ 'After sending 1 arrow right key to the green slider, the value of the green slider should be 129'
);
t.true(
- await testDisplayMatchesValue(t, '255, 1, 0'),
- 'Display should match rgb(255, 1, 0)'
+ await testDisplayMatchesValue(t, '255, 129, 128'),
+ 'Display should match rgb(255, 129, 128)'
);
// Send more than 255 keys to green slider
@@ -191,8 +218,8 @@ ariaTest(
'After sending 260 arrow right key, the value of the green slider should be 255'
);
t.true(
- await testDisplayMatchesValue(t, '255, 255, 0'),
- 'Display should match rgb(255, 255, 0)'
+ await testDisplayMatchesValue(t, '255, 255, 128'),
+ 'Display should match rgb(255, 255, 128)'
);
// Send 1 key to blue slider
@@ -201,12 +228,12 @@ ariaTest(
t.is(
await blueSlider.getAttribute('aria-valuenow'),
- '1',
- 'After sending 1 arrow right key to the blue slider, the value of the blue slider should be 1'
+ '129',
+ 'After sending 1 arrow right key to the blue slider, the value of the blue slider should be 129'
);
t.true(
- await testDisplayMatchesValue(t, '255, 255, 1'),
- 'Display should match rgb(255, 255, 1)'
+ await testDisplayMatchesValue(t, '255, 255, 129'),
+ 'Display should match rgb(255, 255, 129)'
);
// Send more than 255 keys to blue slider
@@ -239,15 +266,15 @@ ariaTest(
t.is(
await redSlider.getAttribute('aria-valuenow'),
- '1',
- 'After sending 1 arrow up key to the red slider, the value of the red slider should be 1'
+ '129',
+ 'After sending 1 arrow up key to the red slider, the value of the red slider should be 129'
);
t.true(
- await testDisplayMatchesValue(t, '1, 0, 0'),
- 'Display should match rgb(1, 0, 0)'
+ await testDisplayMatchesValue(t, '129, 128, 128'),
+ 'Display should match rgb(129, 128, 128)'
);
- // Send more than 255 keys to red slider
+ // Sen over 255 arrow up keys to the red slider
for (let i = 0; i < 260; i++) {
await redSlider.sendKeys(Key.ARROW_UP);
}
@@ -258,8 +285,8 @@ ariaTest(
'After sending 260 arrow up key, the value of the red slider should be 255'
);
t.true(
- await testDisplayMatchesValue(t, '255, 0, 0'),
- 'Display should match rgb(255, 0, 0)'
+ await testDisplayMatchesValue(t, '255, 128, 128'),
+ 'Display should match rgb(255, 128, 128)'
);
// Send 1 key to green slider
@@ -268,12 +295,12 @@ ariaTest(
t.is(
await greenSlider.getAttribute('aria-valuenow'),
- '1',
- 'After sending 1 arrow up key to the blue slider, the value of the green slider should be 1'
+ '129',
+ 'After sending 1 arrow up key to the blue slider, the value of the green slider should be 129'
);
t.true(
- await testDisplayMatchesValue(t, '255, 1, 0'),
- 'Display should match rgb(255, 1, 0)'
+ await testDisplayMatchesValue(t, '255, 129, 128'),
+ 'Display should match rgb(255, 129, 128)'
);
// Send more than 255 keys to green slider
@@ -287,8 +314,8 @@ ariaTest(
'After sending 260 arrow up key, the value of the green slider should be 255'
);
t.true(
- await testDisplayMatchesValue(t, '255, 255, 0'),
- 'Display should match rgb(255, 255, 0)'
+ await testDisplayMatchesValue(t, '255, 255, 128'),
+ 'Display should match rgb(255, 255, 128)'
);
// Send 1 key to blue slider
@@ -297,12 +324,12 @@ ariaTest(
t.is(
await blueSlider.getAttribute('aria-valuenow'),
- '1',
- 'After sending 1 arrow up key to the blue slider, the value of the blue slider should be 1'
+ '129',
+ 'After sending 1 arrow up key to the blue slider, the value of the blue slider should be 129'
);
t.true(
- await testDisplayMatchesValue(t, '255, 255, 1'),
- 'Display should match rgb(255, 255, 1)'
+ await testDisplayMatchesValue(t, '255, 255, 129'),
+ 'Display should match rgb(255, 255, 129)'
);
// Send more than 255 keys to blue slider
@@ -335,15 +362,15 @@ ariaTest(
t.is(
await redSlider.getAttribute('aria-valuenow'),
- '10',
- 'After sending 1 page up key to the red slider, the value of the red slider should be 10'
+ '138',
+ 'After sending 1 page up key to the red slider, the value of the red slider should be 138'
);
t.true(
- await testDisplayMatchesValue(t, '10, 0, 0'),
- 'Display should match rgb(10, 0, 0)'
+ await testDisplayMatchesValue(t, '138, 128, 128'),
+ 'Display should match rgb(138, 128, 128)'
);
- // Send more than 26 keys to red slider
+ // Send over 26 page up keys to the red slider
for (let i = 0; i < 26; i++) {
await redSlider.sendKeys(Key.PAGE_UP);
}
@@ -354,8 +381,8 @@ ariaTest(
'After sending 26 page up key, the value of the red slider should be 255'
);
t.true(
- await testDisplayMatchesValue(t, '255, 0, 0'),
- 'Display should match rgb(255, 0, 0)'
+ await testDisplayMatchesValue(t, '255, 128, 128'),
+ 'Display should match rgb(255, 128, 128)'
);
// Send 1 key to green slider
@@ -364,12 +391,12 @@ ariaTest(
t.is(
await greenSlider.getAttribute('aria-valuenow'),
- '10',
- 'After sending 1 page up key to the blue slider, the value of the green slider should be 10'
+ '138',
+ 'After sending 1 page up key to the blue slider, the value of the green slider should be 138'
);
t.true(
- await testDisplayMatchesValue(t, '255, 10, 0'),
- 'Display should match rgb(255, 10, 0)'
+ await testDisplayMatchesValue(t, '255, 138, 128'),
+ 'Display should match rgb(255, 138, 128)'
);
// Send more than 26 keys to green slider
@@ -383,8 +410,8 @@ ariaTest(
'After sending 260 page up key, the value of the green slider should be 255'
);
t.true(
- await testDisplayMatchesValue(t, '255, 255, 0'),
- 'Display should match rgb(255, 255, 0)'
+ await testDisplayMatchesValue(t, '255, 255, 128'),
+ 'Display should match rgb(255, 255, 128)'
);
// Send 1 key to blue slider
@@ -393,12 +420,12 @@ ariaTest(
t.is(
await blueSlider.getAttribute('aria-valuenow'),
- '10',
- 'After sending 1 page up key to the blue slider, the value of the blue slider should be 10'
+ '138',
+ 'After sending 1 page up key to the blue slider, the value of the blue slider should be 138'
);
t.true(
- await testDisplayMatchesValue(t, '255, 255, 10'),
- 'Display should match rgb(255, 255, 10)'
+ await testDisplayMatchesValue(t, '255, 255, 138'),
+ 'Display should match rgb(255, 255, 138)'
);
// Send more than 26 keys to blue slider
@@ -423,6 +450,8 @@ ariaTest(
exampleFile,
'key-end',
async (t) => {
+ sendAllSlidersToBeginning(t);
+
const sliders = await t.context.queryElements(t, ex.sliderSelector);
// Send key end to red slider
@@ -432,7 +461,7 @@ ariaTest(
t.is(
await redSlider.getAttribute('aria-valuenow'),
'255',
- 'After sending 1 end key to the red slider, the value of the red slider should be 255'
+ 'After sending end key to the red slider, the value of the red slider should be 255'
);
t.true(
await testDisplayMatchesValue(t, '255, 0, 0'),
@@ -735,31 +764,6 @@ ariaTest(
// Send 1 key to blue slider
const blueSlider = sliders[2];
await blueSlider.sendKeys(Key.PAGE_DOWN);
-
- t.is(
- await blueSlider.getAttribute('aria-valuenow'),
- '245',
- 'After sending 1 page down key to the blue slider, the value of the blue slider should be 245'
- );
- t.true(
- await testDisplayMatchesValue(t, '0, 0, 245'),
- 'Display should match rgb(0, 0, 245)'
- );
-
- // Send more than 25 keys to blue slider
- for (let i = 0; i < 26; i++) {
- await blueSlider.sendKeys(Key.PAGE_DOWN);
- }
-
- t.is(
- await blueSlider.getAttribute('aria-valuenow'),
- '0',
- 'After sending 26 page down key, the value of the blue slider should be 0'
- );
- t.true(
- await testDisplayMatchesValue(t, '0, 0, 0'),
- 'Display should match rgb(0, 0, 0)'
- );
}
);