Commit 7c0d5728 authored by Kristi Park's avatar Kristi Park Committed by Commit Bot

[NTP] Improve keyboard navigation for richer picker

- Move order of menu header items (e.g. back button and daily toggle) so
  that they follow the submenu nav buttons using keyboard navigation.
- Support selection on SPACE for color/background tiles.
- Like backgrounds/colors, use arrowkeys instead of TAB to navigate the
  shortcut options (i.e. TAB to focus the shortcuts menu, then use
  arrowkeys to move between the shortcut options).
- Add role=button to upload & default background tiles for screenreader
  support.

Bug: 953822
Change-Id: Iae8c1b8390d917f1513e234b46f0b75cc9bae3ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1737743
Commit-Queue: Kristi Park <kristipark@chromium.org>
Reviewed-by: default avatarGayane Petrosyan <gayane@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684407}
parent 201cafdd
...@@ -704,7 +704,8 @@ customize.getNextTile = function(deltaX, deltaY, currentElem) { ...@@ -704,7 +704,8 @@ customize.getNextTile = function(deltaX, deltaY, currentElem) {
*/ */
customize.tileOnKeyDownInteraction = function(event) { customize.tileOnKeyDownInteraction = function(event) {
const tile = event.currentTarget; const tile = event.currentTarget;
if (event.keyCode === customize.KEYCODES.ENTER) { if (event.keyCode === customize.KEYCODES.ENTER ||
event.keyCode === customize.KEYCODES.SPACE) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
if (tile.onClickOverride) { if (tile.onClickOverride) {
...@@ -1995,6 +1996,14 @@ customize.initCustomBackgrounds = function(showErrorNotification) { ...@@ -1995,6 +1996,14 @@ customize.initCustomBackgrounds = function(showErrorNotification) {
}; };
const clOption = $(customize.IDS.SHORTCUTS_OPTION_CUSTOM_LINKS); const clOption = $(customize.IDS.SHORTCUTS_OPTION_CUSTOM_LINKS);
const mvOption = $(customize.IDS.SHORTCUTS_OPTION_MOST_VISITED);
const hideToggle = $(customize.IDS.SHORTCUTS_HIDE_TOGGLE);
$(customize.IDS.SHORTCUTS_MENU).onkeydown = function(event) {
if (customize.arrowKeys.includes(event.keyCode)) {
clOption.focus();
}
};
clOption.onclick = function() { clOption.onclick = function() {
if (customize.selectedOptions.shortcutType !== clOption) { if (customize.selectedOptions.shortcutType !== clOption) {
ntpApiHandle.logEvent( ntpApiHandle.logEvent(
...@@ -2006,10 +2015,18 @@ customize.initCustomBackgrounds = function(showErrorNotification) { ...@@ -2006,10 +2015,18 @@ customize.initCustomBackgrounds = function(showErrorNotification) {
if (event.keyCode === customize.KEYCODES.ENTER || if (event.keyCode === customize.KEYCODES.ENTER ||
event.keyCode === customize.KEYCODES.SPACE) { event.keyCode === customize.KEYCODES.SPACE) {
clOption.click(); clOption.click();
} else if (customize.arrowKeys.includes(event.keyCode)) {
// Handle arrow key navigation.
event.preventDefault();
event.stopPropagation();
if (event.keyCode === customize.KEYCODES.RIGHT) {
mvOption.focus();
} else if (event.keyCode === customize.KEYCODES.DOWN) {
hideToggle.focus();
}
} }
}; };
const mvOption = $(customize.IDS.SHORTCUTS_OPTION_MOST_VISITED);
mvOption.onclick = function() { mvOption.onclick = function() {
if (customize.selectedOptions.shortcutType !== mvOption) { if (customize.selectedOptions.shortcutType !== mvOption) {
ntpApiHandle.logEvent( ntpApiHandle.logEvent(
...@@ -2021,10 +2038,20 @@ customize.initCustomBackgrounds = function(showErrorNotification) { ...@@ -2021,10 +2038,20 @@ customize.initCustomBackgrounds = function(showErrorNotification) {
if (event.keyCode === customize.KEYCODES.ENTER || if (event.keyCode === customize.KEYCODES.ENTER ||
event.keyCode === customize.KEYCODES.SPACE) { event.keyCode === customize.KEYCODES.SPACE) {
mvOption.click(); mvOption.click();
} else if (customize.arrowKeys.includes(event.keyCode)) {
// Handle arrow key navigation.
event.preventDefault();
event.stopPropagation();
if (event.keyCode === customize.KEYCODES.LEFT) {
clOption.focus();
} else if (
event.keyCode === customize.KEYCODES.RIGHT ||
event.keyCode === customize.KEYCODES.DOWN) {
hideToggle.focus();
}
} }
}; };
const hideToggle = $(customize.IDS.SHORTCUTS_HIDE_TOGGLE);
hideToggle.onchange = function(event) { hideToggle.onchange = function(event) {
customize.richerPicker_toggleShortcutHide(hideToggle.checked); customize.richerPicker_toggleShortcutHide(hideToggle.checked);
ntpApiHandle.logEvent( ntpApiHandle.logEvent(
...@@ -2034,6 +2061,14 @@ customize.initCustomBackgrounds = function(showErrorNotification) { ...@@ -2034,6 +2061,14 @@ customize.initCustomBackgrounds = function(showErrorNotification) {
if (event.keyCode === customize.KEYCODES.ENTER || if (event.keyCode === customize.KEYCODES.ENTER ||
event.keyCode === customize.KEYCODES.SPACE) { event.keyCode === customize.KEYCODES.SPACE) {
hideToggle.onchange(event); hideToggle.onchange(event);
} else if (customize.arrowKeys.includes(event.keyCode)) {
// Handle arrow key navigation.
event.preventDefault();
event.stopPropagation();
if (event.keyCode === customize.KEYCODES.LEFT ||
event.keyCode === customize.KEYCODES.UP) {
mvOption.focus();
}
} }
}; };
hideToggle.onclick = function(event) { hideToggle.onclick = function(event) {
......
...@@ -723,6 +723,7 @@ html[dir=rtl] #error-notice.has-link #error-notice-msg { ...@@ -723,6 +723,7 @@ html[dir=rtl] #error-notice.has-link #error-notice-msg {
display: inline-block; display: inline-block;
height: 384px; height: 384px;
left: 0; left: 0;
margin-top: 80px;
vertical-align: top; vertical-align: top;
width: 192px; width: 192px;
} }
...@@ -843,7 +844,6 @@ html[dir=rtl] .menu-option { ...@@ -843,7 +844,6 @@ html[dir=rtl] .menu-option {
height: 80px; height: 80px;
line-height: 80px; line-height: 80px;
padding-inline-end: 24px; padding-inline-end: 24px;
padding-inline-start: 232px;
} }
#menu-title { #menu-title {
...@@ -889,14 +889,14 @@ html[dir=rtl] .menu-option { ...@@ -889,14 +889,14 @@ html[dir=rtl] .menu-option {
#menu-contents { #menu-contents {
display: inline-block; display: inline-block;
height: 384px; height: 464px;
margin-inline-start: 40px; margin-inline-start: 40px;
position: relative; position: relative;
width: 568px; width: 568px;
} }
.menu-panel { .menu-panel {
height: 100%; height: 384px;
left: 0; left: 0;
/* Pad the content by 5px top/left. This will prevent the focus outline on /* Pad the content by 5px top/left. This will prevent the focus outline on
* tiles from being cut off by overflow-y. */ * tiles from being cut off by overflow-y. */
...@@ -906,7 +906,7 @@ html[dir=rtl] .menu-option { ...@@ -906,7 +906,7 @@ html[dir=rtl] .menu-option {
padding-inline-start: 5px; padding-inline-start: 5px;
padding-top: 5px; padding-top: 5px;
position: absolute; position: absolute;
top: 0; top: 80px;
visibility: hidden; visibility: hidden;
width: 100%; width: 100%;
} }
......
...@@ -170,26 +170,6 @@ ...@@ -170,26 +170,6 @@
</dialog> </dialog>
<dialog id="customization-menu" class="customize-dialog"> <dialog id="customization-menu" class="customize-dialog">
<div id="menu-header">
<div id="menu-back-circle" tabindex="0" role="button"
aria-label="$i18n{backLabel}" title="$i18n{backLabel}">
<div id="menu-back"></div>
</div>
<div id="menu-title">$i18n{customizeMenu}</div>
<div id="refresh-daily-wrapper">
<div id="refresh-toggle-wrapper" title="$i18n{refreshDaily}">
<label class="switch">
<input id="refresh-daily-toggle" type="checkbox"
aria-labelledby="refresh-text"></input>
<span class="toggle">
<div class="knob"></div>
<div class="highlight"></div>
</span>
</label>
</div>
<div id="refresh-text">$i18n{refreshDaily}</div>
</div>
</div>
<div id="menu-nav-panel" role="tablist" aria-label="$i18n{customizeMenu}"> <div id="menu-nav-panel" role="tablist" aria-label="$i18n{customizeMenu}">
<button id="backgrounds-button" class="menu-option" tabindex="0" <button id="backgrounds-button" class="menu-option" tabindex="0"
role="tab" aria-controls="backgrounds-menu backgrounds-image-menu" role="tab" aria-controls="backgrounds-menu backgrounds-image-menu"
...@@ -225,18 +205,40 @@ ...@@ -225,18 +205,40 @@
</button> </button>
</div> </div>
<div id="menu-contents"> <div id="menu-contents">
<div id="menu-header">
<div id="menu-back-circle" tabindex="0" role="button"
aria-label="$i18n{backLabel}" title="$i18n{backLabel}">
<div id="menu-back"></div>
</div>
<div id="menu-title">$i18n{customizeMenu}</div>
<div id="refresh-daily-wrapper">
<div id="refresh-toggle-wrapper" title="$i18n{refreshDaily}">
<label class="switch">
<input id="refresh-daily-toggle" type="checkbox"
aria-labelledby="refresh-text"></input>
<span class="toggle">
<div class="knob"></div>
<div class="highlight"></div>
</span>
</label>
</div>
<div id="refresh-text">$i18n{refreshDaily}</div>
</div>
</div>
<div id="backgrounds-menu" class="menu-panel" tabindex="0" <div id="backgrounds-menu" class="menu-panel" tabindex="0"
role="tabpanel" aria-label="$i18n{backgroundsOption}"> role="tabpanel" aria-label="$i18n{backgroundsOption}">
<div id="backgrounds-upload" class="bg-sel-tile-bg"> <div id="backgrounds-upload" class="bg-sel-tile-bg">
<div id="backgrounds-upload-icon" class="bg-sel-tile" tabindex="-1" <div id="backgrounds-upload-icon" class="bg-sel-tile" tabindex="-1"
aria-label="$i18n{uploadImage}" title="$i18n{uploadImage}"> role="button" aria-label="$i18n{uploadImage}"
title="$i18n{uploadImage}">
<div id="backgrounds-upload-arrow"></div> <div id="backgrounds-upload-arrow"></div>
<div id="backgrounds-upload-text">$i18n{uploadImage}</div> <div id="backgrounds-upload-text">$i18n{uploadImage}</div>
</div> </div>
</div> </div>
<div id="backgrounds-default" class="bg-sel-tile-bg"> <div id="backgrounds-default" class="bg-sel-tile-bg">
<div id="backgrounds-default-icon" class="bg-sel-tile" tabindex="-1" <div id="backgrounds-default-icon" class="bg-sel-tile" tabindex="-1"
aria-label="$i18n{noBackground}" title="$i18n{noBackground}"> role="button" aria-label="$i18n{noBackground}"
title="$i18n{noBackground}">
<div class="mini-page"> <div class="mini-page">
<div class="mini-header-colorful"></div> <div class="mini-header-colorful"></div>
<div class="mini-shortcuts"></div> <div class="mini-shortcuts"></div>
...@@ -251,7 +253,7 @@ ...@@ -251,7 +253,7 @@
aria-label="$i18n{shortcutsOption}"> aria-label="$i18n{shortcutsOption}">
<div id="sh-options"> <div id="sh-options">
<div class="sh-option"> <div class="sh-option">
<div id="sh-option-cl" class="sh-option-image" tabindex="0" <div id="sh-option-cl" class="sh-option-image" tabindex="-1"
role="button" aria-pressed="false" role="button" aria-pressed="false"
aria-labelledby="sh-option-cl-title" title="$i18n{myShortcuts}"> aria-labelledby="sh-option-cl-title" title="$i18n{myShortcuts}">
<div class="sh-option-icon"></div> <div class="sh-option-icon"></div>
...@@ -268,7 +270,7 @@ ...@@ -268,7 +270,7 @@
$i18n{shortcutsCurated} $i18n{shortcutsCurated}
</div> </div>
<div class="sh-option"> <div class="sh-option">
<div id="sh-option-mv" class="sh-option-image" tabindex="0" <div id="sh-option-mv" class="sh-option-image" tabindex="-1"
role="button" aria-pressed="false" role="button" aria-pressed="false"
aria-labelledby="sh-option-mv-title" title="$i18n{mostVisited}"> aria-labelledby="sh-option-mv-title" title="$i18n{mostVisited}">
<div class="sh-option-icon"></div> <div class="sh-option-icon"></div>
...@@ -293,7 +295,7 @@ ...@@ -293,7 +295,7 @@
</div> </div>
<div id="sh-hide-toggle-wrapper" title="$i18n{hideShortcuts}"> <div id="sh-hide-toggle-wrapper" title="$i18n{hideShortcuts}">
<label class="switch"> <label class="switch">
<input id="sh-hide-toggle" type="checkbox" <input id="sh-hide-toggle" type="checkbox" tabindex="-1"
aria-labelledby="sh-hide-title"></input> aria-labelledby="sh-hide-title"></input>
<span class="toggle"> <span class="toggle">
<div class="knob"></div> <div class="knob"></div>
...@@ -319,7 +321,8 @@ ...@@ -319,7 +321,8 @@
</button> </button>
</div> </div>
<div id="color-picker-container" class="bg-sel-tile-bg" <div id="color-picker-container" class="bg-sel-tile-bg"
aria-label="$i18n{colorPickerLabel}" title="$i18n{colorPickerLabel}"> aria-label="$i18n{colorPickerLabel}"
title="$i18n{colorPickerLabel}">
<div id="color-picker-tile" class="bg-sel-tile" tabindex="-1"> <div id="color-picker-tile" class="bg-sel-tile" tabindex="-1">
<div id="left-semicircle"></div> <div id="left-semicircle"></div>
<div id="color-picker-icon"></div> <div id="color-picker-icon"></div>
...@@ -328,8 +331,8 @@ ...@@ -328,8 +331,8 @@
</div> </div>
</div> </div>
<div id="colors-default" class="bg-sel-tile-bg" <div id="colors-default" class="bg-sel-tile-bg"
aria-label="$i18n{defaultThemeLabel}" aria-label="$i18n{defaultThemeLabel}"
title="$i18n{defaultThemeLabel}"> title="$i18n{defaultThemeLabel}">
<div id="colors-default-icon" class="bg-sel-tile" tabindex="-1"></div> <div id="colors-default-icon" class="bg-sel-tile" tabindex="-1"></div>
</div> </div>
</div> </div>
......
...@@ -160,26 +160,6 @@ ...@@ -160,26 +160,6 @@
</dialog> </dialog>
<dialog id="customization-menu" class="customize-dialog"> <dialog id="customization-menu" class="customize-dialog">
<div id="menu-header">
<div id="menu-back-circle" tabindex="0" role="button"
aria-label="$i18n{backLabel}" title="$i18n{backLabel}">
<div id="menu-back"></div>
</div>
<div id="menu-title">$i18n{customizeMenu}</div>
<div id="refresh-daily-wrapper">
<div id="refresh-toggle-wrapper" title="$i18n{refreshDaily}">
<label class="switch">
<input id="refresh-daily-toggle" type="checkbox"
aria-labelledby="refresh-text"></input>
<span class="toggle">
<div class="knob"></div>
<div class="highlight"></div>
</span>
</label>
</div>
<div id="refresh-text">$i18n{refreshDaily}</div>
</div>
</div>
<div id="menu-nav-panel" role="tablist" aria-label="$i18n{customizeMenu}"> <div id="menu-nav-panel" role="tablist" aria-label="$i18n{customizeMenu}">
<button id="backgrounds-button" class="menu-option" tabindex="0" <button id="backgrounds-button" class="menu-option" tabindex="0"
role="tab" aria-controls="backgrounds-menu backgrounds-image-menu" role="tab" aria-controls="backgrounds-menu backgrounds-image-menu"
...@@ -215,18 +195,40 @@ ...@@ -215,18 +195,40 @@
</button> </button>
</div> </div>
<div id="menu-contents"> <div id="menu-contents">
<div id="menu-header">
<div id="menu-back-circle" tabindex="0" role="button"
aria-label="$i18n{backLabel}" title="$i18n{backLabel}">
<div id="menu-back"></div>
</div>
<div id="menu-title">$i18n{customizeMenu}</div>
<div id="refresh-daily-wrapper">
<div id="refresh-toggle-wrapper" title="$i18n{refreshDaily}">
<label class="switch">
<input id="refresh-daily-toggle" type="checkbox"
aria-labelledby="refresh-text"></input>
<span class="toggle">
<div class="knob"></div>
<div class="highlight"></div>
</span>
</label>
</div>
<div id="refresh-text">$i18n{refreshDaily}</div>
</div>
</div>
<div id="backgrounds-menu" class="menu-panel" tabindex="0" <div id="backgrounds-menu" class="menu-panel" tabindex="0"
role="tabpanel" aria-label="$i18n{backgroundsOption}"> role="tabpanel" aria-label="$i18n{backgroundsOption}">
<div id="backgrounds-upload" class="bg-sel-tile-bg"> <div id="backgrounds-upload" class="bg-sel-tile-bg">
<div id="backgrounds-upload-icon" class="bg-sel-tile" tabindex="-1" <div id="backgrounds-upload-icon" class="bg-sel-tile" tabindex="-1"
aria-label="$i18n{uploadImage}" title="$i18n{uploadImage}"> role="button" aria-label="$i18n{uploadImage}"
title="$i18n{uploadImage}">
<div id="backgrounds-upload-arrow"></div> <div id="backgrounds-upload-arrow"></div>
<div id="backgrounds-upload-text">$i18n{uploadImage}</div> <div id="backgrounds-upload-text">$i18n{uploadImage}</div>
</div> </div>
</div> </div>
<div id="backgrounds-default" class="bg-sel-tile-bg"> <div id="backgrounds-default" class="bg-sel-tile-bg">
<div id="backgrounds-default-icon" class="bg-sel-tile" tabindex="-1" <div id="backgrounds-default-icon" class="bg-sel-tile" tabindex="-1"
aria-label="$i18n{noBackground}" title="$i18n{noBackground}"> role="button" aria-label="$i18n{noBackground}"
title="$i18n{noBackground}">
<div class="mini-page"> <div class="mini-page">
<div class="mini-header-colorful"></div> <div class="mini-header-colorful"></div>
<div class="mini-shortcuts"></div> <div class="mini-shortcuts"></div>
...@@ -241,7 +243,7 @@ ...@@ -241,7 +243,7 @@
aria-label="$i18n{shortcutsOption}"> aria-label="$i18n{shortcutsOption}">
<div id="sh-options"> <div id="sh-options">
<div class="sh-option"> <div class="sh-option">
<div id="sh-option-cl" class="sh-option-image" tabindex="0" <div id="sh-option-cl" class="sh-option-image" tabindex="-1"
role="button" aria-pressed="false" role="button" aria-pressed="false"
aria-labelledby="sh-option-cl-title" aria-labelledby="sh-option-cl-title"
title="$i18n{myShortcuts}"> title="$i18n{myShortcuts}">
...@@ -259,7 +261,7 @@ ...@@ -259,7 +261,7 @@
$i18n{shortcutsCurated} $i18n{shortcutsCurated}
</div> </div>
<div class="sh-option"> <div class="sh-option">
<div id="sh-option-mv" class="sh-option-image" tabindex="0" <div id="sh-option-mv" class="sh-option-image" tabindex="-1"
role="button" aria-pressed="false" role="button" aria-pressed="false"
aria-labelledby="sh-option-mv-title" aria-labelledby="sh-option-mv-title"
title="$i18n{mostVisited}"> title="$i18n{mostVisited}">
...@@ -285,7 +287,7 @@ ...@@ -285,7 +287,7 @@
</div> </div>
<div id="sh-hide-toggle-wrapper" title="$i18n{hideShortcuts}"> <div id="sh-hide-toggle-wrapper" title="$i18n{hideShortcuts}">
<label class="switch"> <label class="switch">
<input id="sh-hide-toggle" type="checkbox" <input id="sh-hide-toggle" type="checkbox" tabindex="-1"
aria-labelledby="sh-hide-title"></input> aria-labelledby="sh-hide-title"></input>
<span class="toggle"> <span class="toggle">
<div class="knob"></div> <div class="knob"></div>
...@@ -323,7 +325,8 @@ ...@@ -323,7 +325,8 @@
<div id="colors-default" class="bg-sel-tile-bg" <div id="colors-default" class="bg-sel-tile-bg"
aria-label="$i18n{defaultThemeLabel}" aria-label="$i18n{defaultThemeLabel}"
title="$i18n{defaultThemeLabel}"> title="$i18n{defaultThemeLabel}">
<div id="colors-default-icon" class="bg-sel-tile" tabindex="-1"></div> <div id="colors-default-icon" class="bg-sel-tile" tabindex="-1">
</div>
</div> </div>
</div> </div>
</div> </div>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment