Commit 289d7c47 authored by Alex Danilo's avatar Alex Danilo Committed by Commit Bot

Make menu button take focus from cr-input

CL:1935567 changed the focus behavior to take focus on mousedown if some
other button was currently focussed.

Make the menu button take focus on mousedown for the case where a
<cr-input> element is currently focussed.

Extend unit test to cover the 'cr-input' case.

Bug: 1028461
Tests: browser_test --gtest_filter="*MultiMenu"
Change-Id: I89b067d2eafd547363bbcf289124f0253a87b9c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1937948
Commit-Queue: Alex Danilo <adanilo@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719457}
parent ad457125
...@@ -322,9 +322,10 @@ cr.define('cr.ui', () => { ...@@ -322,9 +322,10 @@ cr.define('cr.ui', () => {
// mouse button. // mouse button.
this.showMenu(false, {x: e.screenX, y: e.screenY}); this.showMenu(false, {x: e.screenX, y: e.screenY});
// Prevent the button from stealing focus on mousedown unless // Prevent the button from stealing focus on mousedown unless
// focus is on another button. // focus is on another button or cr-input element.
if (!(document.hasFocus() && if (!(document.hasFocus() &&
document.activeElement.tagName === 'BUTTON')) { (document.activeElement.tagName === 'BUTTON' ||
document.activeElement.tagName === 'CR-INPUT'))) {
e.preventDefault(); e.preventDefault();
} }
} }
......
...@@ -49,6 +49,8 @@ function setUp() { ...@@ -49,6 +49,8 @@ function setUp() {
'</cr-menu>', '</cr-menu>',
'<div id="focus-div" tabindex="1"/>', '<div id="focus-div" tabindex="1"/>',
'<button id="focus-button" tabindex="2"/>', '<button id="focus-button" tabindex="2"/>',
'<cr-input id="focus-input" tabindex="3">',
'</cr-input>',
].join(''); ].join('');
// Initialize cr.ui.Command with the <command>s. // Initialize cr.ui.Command with the <command>s.
...@@ -393,4 +395,18 @@ function testFocusMenuButtonWithMouse() { ...@@ -393,4 +395,18 @@ function testFocusMenuButtonWithMouse() {
// Verify the menu button has taken focus. // Verify the menu button has taken focus.
assertTrue(document.hasFocus() && document.activeElement === menubutton); assertTrue(document.hasFocus() && document.activeElement === menubutton);
// Set focus on a cr-input element.
//* @type {HTMLElement} */
const inputElement = document.querySelector('#focus-input');
inputElement.focus();
// Send mousedown event to the menu button.
sendMouseDown('#test-menu-button');
// Verify the cr-input element has lost focus.
assertFalse(document.hasFocus() && document.activeElement === inputElement);
// Verify the menu button has taken focus.
assertTrue(document.hasFocus() && document.activeElement === menubutton);
} }
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