Skip to content

Commit

Permalink
WebUI: cr-radio-group, wrap selections when using keyboard input
Browse files Browse the repository at this point in the history
Bug: 949080
Change-Id: Ibe39efccf103abc627efbdee8b892720a4c265ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1595301
Reviewed-by: Hector Carmona <hcarmona@chromium.org>
Commit-Queue: Esmael El-Moslimany <aee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#656628}
  • Loading branch information
Esmael El-Moslimany authored and Commit Bot committed May 4, 2019
1 parent 76b4857 commit 178ac1b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions chrome/test/data/webui/cr_elements/cr_radio_group_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,15 @@ suite('cr-radio-group', () => {
// Check for decrement.
checkPressed(['Home', 'PageUp', 'ArrowUp', 'ArrowLeft'], 2, 1);
// No change when reached first selected.
checkPressed(['Home', 'PageUp', 'ArrowUp', 'ArrowLeft'], 1, 1);
checkPressed(['Home'], 1, 1);
// Wraps when decrementing when first selected.
checkPressed(['PageUp', 'ArrowUp', 'ArrowLeft'], 1, 3);
// Check for increment.
checkPressed(['End', 'ArrowRight', 'PageDown', 'ArrowDown'], 2, 3);
// No change when reached last selected.
checkPressed(['End', 'ArrowRight', 'PageDown', 'ArrowDown'], 3, 3);
checkPressed(['End'], 3, 3);
// Wraps when incrementing when last selected.
checkPressed(['ArrowRight', 'PageDown', 'ArrowDown'], 3, 1);
});

test('mouse event', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@
// If nothing selected, start from the first radio then add |delta|.
const lastSelection = enabledRadios.findIndex(radio => radio.checked);
selectedIndex = Math.max(0, lastSelection) + delta;
selectedIndex = Math.min(max, Math.max(0, selectedIndex));
// Wrap the selection, if needed.
if (selectedIndex > max) {
selectedIndex = 0;
} else if (selectedIndex < 0) {
selectedIndex = max;
}
} else {
return;
}
Expand Down

0 comments on commit 178ac1b

Please sign in to comment.