Skip to content

Commit

Permalink
Combobox Examples with listbox popups: scroll item referenced by aria…
Browse files Browse the repository at this point in the history
…-activedescendant into view (pull #2055)

* If pressing arrow keys moves focus to an item that is not visible, scroll the item into view.
* Add accessibility features documentation.

Co-authored-by: Matt King <a11yThinker@gmail.com>
  • Loading branch information
jongund and mcking65 committed Oct 31, 2021
1 parent 15fcc41 commit a10518c
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 109 deletions.
47 changes: 38 additions & 9 deletions examples/combobox/combobox-autocomplete-both.html
Expand Up @@ -57,12 +57,9 @@ <h2 id="ex_label">Example</h2>
<input id="cb1-input" class="cb_edit" type="text" role="combobox" aria-autocomplete="both"
aria-expanded="false" aria-controls="cb1-listbox">
<button type="button" id="cb1-button" aria-label="States" aria-expanded="false" aria-controls="cb1-listbox" tabindex="-1">
<span class="arrow">
<svg width="18" height="16" aria-hidden="true" focusable="false">
<polygon class="outline" points="1,4 17,4 9,15"></polygon>
<polygon class="arrow" points="3,5 15,5 9,13"></polygon>
</svg>
</span>
<svg width="18" height="16" aria-hidden="true" focusable="false" style="forced-color-adjust: auto">
<polygon class="arrow" stroke-width="0" fill-opacity="0.75" fill="currentColor" points="3,6 15,6 9,14"></polygon>
</svg>
</button>
</div>
<ul id="cb1-listbox" role="listbox" aria-label="States">
Expand Down Expand Up @@ -128,6 +125,38 @@ <h2 id="ex_label">Example</h2>
<div role="separator" id="ex_end_sep" aria-labelledby="ex_end_sep ex_label" aria-label="End of"></div>
</section>

<section>
<h2>Accessibility Features</h2>
<ul>
<li>
Browsers do not manage visibility of elements referenced by aria-activedescendant like they do for elements with focus.
When a keyboard event changes the active option in the listbox, the JavaScript scrolls the option referenced by aria-activedescendant into view.
Managing aria-activedescendant visibility is essential to accessibility for people who use a browser's zoom feature to increase the size of content.
</li>
<li>
To enhance perceivability when operating the combobox, visual keyboard focus and hover are styled using the CSS <code>:hover</code> pseudo-class, and <code>focus</code> and <code>blur</code> event handlers:
<ul>
<li>To make it easier to perceive when the combobox receives focus, focus creates a 2 pixel focus ring around both the <code>input</code> and <code>button</code> elements with 2 pixels of space between the focus ring and the combobox.</li>
<li>To make it easier to perceive that either the input or button can be clicked to open the listbox, hover causes the same styling as focus.</li>
<li>To help people with visual impairments identify the combobox as an interactive element, the cursor is changed to a pointer when hovering over the combobox or list.</li>
<li>To make it easier to distinguish the selected listbox option from other options, selection creates a 2 pixel border above and below the option.</li>
<li>
Note: 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 zero to two pixels and padding is reduced by two pixels.
When an element loses focus, its border changes from two pixels to two and padding is increased by two pixels.
</li>
</ul>
<li>
To ensure the inline SVG graphic used for the arrow in the open button has sufficient contrast with the background when high contrast settings change the color of text content,
CSS <code>forced-color-adjust</code> is set to <code>auto</code> on the <code>svg</code> element and and the <code>fill</code> attribute of the <code>polygon</code> element is set to <code>currentColor</code>.
This causes the colors of the <code>fill</code> of the polygon elements to be overridden by the high contrast color setting.
If <code>forced-color-adjust</code> were not used to override the colors specified for the <code>fill</code> property, the color would remain the same in high contrast mode, which could lead to insufficient contrast between the arrow and the background or even make it invisible if the color matched the high contrast mode background.<br>
Note: The explicit setting of <code>forced-color-adjust</code> is necessary because some browsers do not use <code>auto</code> as the default value for SVG graphics.
</li>
</ul>
</section>

<section>
<h2 id="kbd_label">Keyboard Support</h2>
<p>
Expand Down Expand Up @@ -325,7 +354,7 @@ <h3 id="rps_label_textbox">Textbox</h3>
<tr data-test-id="combobox-aria-controls">
<td></td>
<th scope="row">
<code>aria-controls="#IDREF"</code>
<code>aria-controls="ID_REF"</code>
</th>
<td><code>input[type="text"]</code></td>
<td>Identifies the element that serves as the popup.</td>
Expand Down Expand Up @@ -362,7 +391,7 @@ <h3 id="rps_label_textbox">Textbox</h3>
<tr data-test-id="combobox-aria-activedescendant">
<td></td>
<th scope="row">
<code>aria-activedescendant="IDREF"</code>
<code>aria-activedescendant="ID_REF"</code>
</th>
<td><code>input[type="text"]</code></td>
<td>
Expand Down Expand Up @@ -467,7 +496,7 @@ <h3 id="rps_label_button">Button</h3>
<tr data-test-id="button-aria-controls">
<td></td>
<th scope="row">
<code>aria-controls="#IDREF"</code>
<code>aria-controls="ID_REF"</code>
</th>
<td><code>button</code></td>
<td>Identifies the element that serves as the popup.</td>
Expand Down
47 changes: 38 additions & 9 deletions examples/combobox/combobox-autocomplete-list.html
Expand Up @@ -58,12 +58,9 @@ <h2 id="ex_label">Example</h2>
<input id="cb1-input" class="cb_edit" type="text" role="combobox" aria-autocomplete="list"
aria-expanded="false" aria-controls="cb1-listbox">
<button id="cb1-button" tabindex="-1" aria-label="States" aria-expanded="false" aria-controls="cb1-listbox">
<span class="arrow">
<svg width="18" height="16" aria-hidden="true" focusable="false">
<polygon class="outline" points="1,4 17,4 9,15"></polygon>
<polygon class="arrow" points="3,5 15,5 9,13"></polygon>
</svg>
</span>
<svg width="18" height="16" aria-hidden="true" focusable="false" style="forced-color-adjust: auto">
<polygon class="arrow" stroke-width="0" fill-opacity="0.75" fill="currentColor" points="3,6 15,6 9,14"></polygon>
</svg>
</button>
</div>
<ul id="cb1-listbox" role="listbox" aria-label="States">
Expand Down Expand Up @@ -129,6 +126,38 @@ <h2 id="ex_label">Example</h2>
<div role="separator" id="ex_end_sep" aria-labelledby="ex_end_sep ex_label" aria-label="End of"></div>
</section>

<section>
<h2>Accessibility Features</h2>
<ul>
<li>
Browsers do not manage visibility of elements referenced by aria-activedescendant like they do for elements with focus.
When a keyboard event changes the active option in the listbox, the JavaScript scrolls the option referenced by aria-activedescendant into view.
Managing aria-activedescendant visibility is essential to accessibility for people who use a browser's zoom feature to increase the size of content.
</li>
<li>
To enhance perceivability when operating the combobox, visual keyboard focus and hover are styled using the CSS <code>:hover</code> pseudo-class, and <code>focus</code> and <code>blur</code> event handlers:
<ul>
<li>To make it easier to perceive when the combobox receives focus, focus creates a 2 pixel focus ring around both the <code>input</code> and <code>button</code> elements with 2 pixels of space between the focus ring and the combobox.</li>
<li>To make it easier to perceive that either the input or button can be clicked to open the listbox, hover causes the same styling as focus.</li>
<li>To help people with visual impairments identify the combobox as an interactive element, the cursor is changed to a pointer when hovering over the combobox or list.</li>
<li>To make it easier to distinguish the selected listbox option from other options, selection creates a 2 pixel border above and below the option.</li>
<li>
Note: 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 zero to two pixels and padding is reduced by two pixels.
When an element loses focus, its border changes from two pixels to two and padding is increased by two pixels.
</li>
</ul>
<li>
To ensure the inline SVG graphic used for the arrow in the open button has sufficient contrast with the background when high contrast settings change the color of text content,
CSS <code>forced-color-adjust</code> is set to <code>auto</code> on the <code>svg</code> element and and the <code>fill</code> attribute of the <code>polygon</code> element is set to <code>currentColor</code>.
This causes the colors of the <code>fill</code> of the polygon elements to be overridden by the high contrast color setting.
If <code>forced-color-adjust</code> were not used to override the colors specified for the <code>fill</code> property, the color would remain the same in high contrast mode, which could lead to insufficient contrast between the arrow and the background or even make it invisible if the color matched the high contrast mode background.<br>
Note: The explicit setting of <code>forced-color-adjust</code> is necessary because some browsers do not use <code>auto</code> as the default value for SVG graphics.
</li>
</ul>
</section>

<section>
<h2 id="kbd_label">Keyboard Support</h2>
<p>
Expand Down Expand Up @@ -320,7 +349,7 @@ <h3 id="rps_label_textbox">Textbox</h3>
<tr data-test-id="combobox-aria-controls">
<td></td>
<th scope="row">
<code>aria-controls="#IDREF"</code>
<code>aria-controls="ID_REF"</code>
</th>
<td><code>input[type="text"]</code></td>
<td>Identifies the element that serves as the popup.</td>
Expand Down Expand Up @@ -357,7 +386,7 @@ <h3 id="rps_label_textbox">Textbox</h3>
<tr data-test-id="combobox-aria-activedescendant">
<td></td>
<th scope="row">
<code>aria-activedescendant="IDREF"</code>
<code>aria-activedescendant="ID_REF"</code>
</th>
<td><code>input[type="text"]</code></td>
<td>
Expand Down Expand Up @@ -462,7 +491,7 @@ <h3 id="rps_label_button">Button</h3>
<tr data-test-id="button-aria-controls">
<td></td>
<th scope="row">
<code>aria-controls="#IDREF"</code>
<code>aria-controls="ID_REF"</code>
</th>
<td><code>button</code></td>
<td>Identifies the element that serves as the popup.</td>
Expand Down
47 changes: 38 additions & 9 deletions examples/combobox/combobox-autocomplete-none.html
Expand Up @@ -58,12 +58,9 @@ <h2 id="ex_label">Example</h2>
aria-expanded="false"
aria-controls="cb1-listbox">
<button type="button" id="cb1-button" tabindex="-1" aria-label="Previous Searches" aria-expanded="false" aria-controls="cb1-listbox" >
<span class="arrow">
<svg width="18" height="16" aria-hidden="true" focusable="false">
<polygon class="outline" points="1,4 17,4 9,15"></polygon>
<polygon class="arrow" points="3,5 15,5 9,13"></polygon>
</svg>
</span>
<svg width="18" height="16" aria-hidden="true" focusable="false" style="forced-color-adjust: auto">
<polygon class="arrow" stroke-width="0" fill-opacity="0.75" fill="currentColor" points="3,6 15,6 9,14"></polygon>
</svg>
</button>
</div>
<ul id="cb1-listbox" role="listbox" aria-label="Previous Searches">
Expand All @@ -84,6 +81,38 @@ <h2 id="ex_label">Example</h2>
<div role="separator" id="ex_end_sep" aria-labelledby="ex_end_sep ex_label" aria-label="End of"></div>
</section>

<section>
<h2>Accessibility Features</h2>
<ul>
<li>
Browsers do not manage visibility of elements referenced by aria-activedescendant like they do for elements with focus.
When a keyboard event changes the active option in the listbox, the JavaScript scrolls the option referenced by aria-activedescendant into view.
Managing aria-activedescendant visibility is essential to accessibility for people who use a browser's zoom feature to increase the size of content.
</li>
<li>
To enhance perceivability when operating the combobox, visual keyboard focus and hover are styled using the CSS <code>:hover</code> pseudo-class, and <code>focus</code> and <code>blur</code> event handlers:
<ul>
<li>To make it easier to perceive when the combobox receives focus, focus creates a 2 pixel focus ring around both the <code>input</code> and <code>button</code> elements with 2 pixels of space between the focus ring and the combobox.</li>
<li>To make it easier to perceive that either the input or button can be clicked to open the listbox, hover causes the same styling as focus.</li>
<li>To help people with visual impairments identify the combobox as an interactive element, the cursor is changed to a pointer when hovering over the combobox or list.</li>
<li>To make it easier to distinguish the selected listbox option from other options, selection creates a 2 pixel border above and below the option.</li>
<li>
Note: 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 zero to two pixels and padding is reduced by two pixels.
When an element loses focus, its border changes from two pixels to two and padding is increased by two pixels.
</li>
</ul>
<li>
To ensure the inline SVG graphic used for the arrow in the open button has sufficient contrast with the background when high contrast settings change the color of text content,
CSS <code>forced-color-adjust</code> is set to <code>auto</code> on the <code>svg</code> element and and the <code>fill</code> attribute of the <code>polygon</code> element is set to <code>currentColor</code>.
This causes the colors of the <code>fill</code> of the polygon elements to be overridden by the high contrast color setting.
If <code>forced-color-adjust</code> were not used to override the colors specified for the <code>fill</code> property, the color would remain the same in high contrast mode, which could lead to insufficient contrast between the arrow and the background or even make it invisible if the color matched the high contrast mode background.<br>
Note: The explicit setting of <code>forced-color-adjust</code> is necessary because some browsers do not use <code>auto</code> as the default value for SVG graphics.
</li>
</ul>
</section>

<section>
<h2 id="kbd_label">Keyboard Support</h2>
<p>
Expand Down Expand Up @@ -269,7 +298,7 @@ <h3 id="rps_label_textbox">Textbox</h3>
<tr data-test-id="combobox-aria-controls">
<td></td>
<th scope="row">
<code>aria-controls="#IDREF"</code>
<code>aria-controls="ID_REF"</code>
</th>
<td><code>input[type="text"]</code></td>
<td>Identifies the element that serves as the popup.</td>
Expand Down Expand Up @@ -306,7 +335,7 @@ <h3 id="rps_label_textbox">Textbox</h3>
<tr data-test-id="combobox-aria-activedescendant">
<td></td>
<th scope="row">
<code>aria-activedescendant="IDREF"</code>
<code>aria-activedescendant="ID_REF"</code>
</th>
<td><code>input[type="text"]</code></td>
<td>
Expand Down Expand Up @@ -410,7 +439,7 @@ <h3 id="rps_label_button">Button</h3>
<tr data-test-id="button-aria-controls">
<td></td>
<th scope="row">
<code>aria-controls="#IDREF"</code>
<code>aria-controls="ID_REF"</code>
</th>
<td><code>button</code></td>
<td>Identifies the element that serves as the popup.</td>
Expand Down

0 comments on commit a10518c

Please sign in to comment.