Commit b60b21b0 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Files app: Search box hide when clicking out of it

Change the search box to not hide until mouse up event, when focus is
moved due to a user click.

This fixes the issue where user clicks in a button and the search box is
hiding, which can cause the click event to not be dispatched to the
button that user intended.

Bug: 1061894
Change-Id: I3dc1fb1eb2a3d4bcc6c55de7470f065dfd3b7a70
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2108411Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarAlex Danilo <adanilo@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751626}
parent 489e4293
...@@ -61,6 +61,12 @@ class SearchBox extends cr.EventTarget { ...@@ -61,6 +61,12 @@ class SearchBox extends cr.EventTarget {
*/ */
this.clearButton_ = assert(element.querySelector('.clear')); this.clearButton_ = assert(element.querySelector('.clear'));
/** @private {boolean} */
this.collapsed_ = true;
/** @private {boolean} */
this.isClicking_ = false;
// Register events. // Register events.
this.inputElement.addEventListener('input', this.onInput_.bind(this)); this.inputElement.addEventListener('input', this.onInput_.bind(this));
this.inputElement.addEventListener('keydown', this.onKeyDown_.bind(this)); this.inputElement.addEventListener('keydown', this.onKeyDown_.bind(this));
...@@ -79,6 +85,21 @@ class SearchBox extends cr.EventTarget { ...@@ -79,6 +85,21 @@ class SearchBox extends cr.EventTarget {
this.autocompleteList.handleEnterKeydown = dispatchItemSelect; this.autocompleteList.handleEnterKeydown = dispatchItemSelect;
this.autocompleteList.addEventListener('mousedown', dispatchItemSelect); this.autocompleteList.addEventListener('mousedown', dispatchItemSelect);
document.addEventListener('mousedown', () => {
if (this.collapsed_) {
return;
}
this.isClicking_ = true;
}, {capture: true, passive: true});
document.addEventListener('mouseup', () => {
if (this.collapsed_) {
return;
}
this.isClicking_ = false;
this.removeHidePending();
}, {passive: true});
this.searchWrapper.addEventListener( this.searchWrapper.addEventListener(
'focusout', this.onFocusOut_.bind(this)); 'focusout', this.onFocusOut_.bind(this));
...@@ -115,6 +136,14 @@ class SearchBox extends cr.EventTarget { ...@@ -115,6 +136,14 @@ class SearchBox extends cr.EventTarget {
return; return;
} }
// If the focus is moved due to a user click, we don't collapse the searc
// box here. We wait until "mouseup" to let the mouse events be processed
// by the button user is clickinkg, which might change position due to the
// search box collapse.
if (this.isClicking_) {
return;
}
if (this.element.classList.contains('hide-pending')) { if (this.element.classList.contains('hide-pending')) {
this.removeHidePending(); this.removeHidePending();
} }
...@@ -139,6 +168,9 @@ class SearchBox extends cr.EventTarget { ...@@ -139,6 +168,9 @@ class SearchBox extends cr.EventTarget {
if (this.element.classList.contains('hide-pending')) { if (this.element.classList.contains('hide-pending')) {
return; return;
} }
this.collapsed_ = false;
this.isClicking_ = false;
this.element.classList.toggle('has-cursor', true); this.element.classList.toggle('has-cursor', true);
this.searchWrapper.classList.toggle('has-cursor', true); this.searchWrapper.classList.toggle('has-cursor', true);
this.autocompleteList.attachToInput(this.inputElement); this.autocompleteList.attachToInput(this.inputElement);
...@@ -168,6 +200,7 @@ class SearchBox extends cr.EventTarget { ...@@ -168,6 +200,7 @@ class SearchBox extends cr.EventTarget {
this.inputElement.disabled = this.inputElement.value.length == 0; this.inputElement.disabled = this.inputElement.value.length == 0;
this.element.classList.toggle('hide-pending', false); this.element.classList.toggle('hide-pending', false);
this.searchWrapper.classList.toggle('hide-pending', false); this.searchWrapper.classList.toggle('hide-pending', false);
this.collapsed_ = true;
} }
/** /**
......
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