Commit e8902701 authored by Alex Danilo's avatar Alex Danilo Committed by Commit Bot

[footer] Add support for left/right arrow keys

CL:2201336 swaps a native <select> control for a <div> that emulates
select behavior and allows it to be styled with CSS.

Add support for using the left and right arrow keys which behave the
same as up and down in a real <select> control.

Bug: 1097454, 1002410
Change-Id: I854b794e8bb34200a83cf3a3f11ff4ed007808bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2282831
Commit-Queue: Alex Danilo <adanilo@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786177}
parent bf3bd23a
...@@ -198,7 +198,7 @@ class DialogFooter { ...@@ -198,7 +198,7 @@ class DialogFooter {
evt.stopPropagation(); evt.stopPropagation();
evt.preventDefault(); evt.preventDefault();
} }
// Drop through. // fall through
case 'Tab': case 'Tab':
this.selectHideDropDown(options); this.selectHideDropDown(options);
break; break;
...@@ -213,27 +213,43 @@ class DialogFooter { ...@@ -213,27 +213,43 @@ class DialogFooter {
} }
break; break;
case 'ArrowDown': case 'ArrowDown':
case 'ArrowLeft':
case 'ArrowRight':
case 'ArrowUp': case 'ArrowUp':
const selectedItem = options.querySelector('.selected'); const selectedItem = options.querySelector('.selected');
const isCollapsed = options.getAttribute('expanded') !== 'expanded';
let selectionChanged = false; let selectionChanged = false;
if (selectedItem) { if (selectedItem) {
if (evt.key === 'ArrowDown') { switch (evt.key) {
if (selectedItem.nextSibling) { case 'ArrowRight':
this.setOptionSelected( if (!isCollapsed) {
/** @type {HTMLOptionElement} */ (selectedItem.nextSibling)); break;
selectionChanged = true; }
} // fall through
} else { // ArrowUp. case 'ArrowDown':
if (selectedItem.previousSibling) { if (selectedItem.nextSibling) {
this.setOptionSelected( this.setOptionSelected(
/** @type {HTMLOptionElement} */ ( /** @type {HTMLOptionElement} */ (
selectedItem.previousSibling)); selectedItem.nextSibling));
selectionChanged = true; selectionChanged = true;
} }
break;
case 'ArrowLeft':
if (!isCollapsed) {
break;
}
// fall through
case 'ArrowUp':
if (selectedItem.previousSibling) {
this.setOptionSelected(
/** @type {HTMLOptionElement} */ (
selectedItem.previousSibling));
selectionChanged = true;
}
break;
} }
} }
if (selectionChanged && if (selectionChanged && isCollapsed) {
options.getAttribute('expanded') !== 'expanded') {
const changeEvent = new Event('change'); const changeEvent = new Event('change');
this.fileTypeSelector.dispatchEvent(changeEvent); this.fileTypeSelector.dispatchEvent(changeEvent);
} }
......
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