summaryrefslogtreecommitdiff
path: root/chromium/ui/webui/resources/cr_elements/cr_searchable_drop_down/cr_searchable_drop_down.js
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/webui/resources/cr_elements/cr_searchable_drop_down/cr_searchable_drop_down.js')
-rw-r--r--chromium/ui/webui/resources/cr_elements/cr_searchable_drop_down/cr_searchable_drop_down.js26
1 files changed, 24 insertions, 2 deletions
diff --git a/chromium/ui/webui/resources/cr_elements/cr_searchable_drop_down/cr_searchable_drop_down.js b/chromium/ui/webui/resources/cr_elements/cr_searchable_drop_down/cr_searchable_drop_down.js
index 06823f7b8f6..ff4fc193902 100644
--- a/chromium/ui/webui/resources/cr_elements/cr_searchable_drop_down/cr_searchable_drop_down.js
+++ b/chromium/ui/webui/resources/cr_elements/cr_searchable_drop_down/cr_searchable_drop_down.js
@@ -119,15 +119,23 @@ Polymer({
/** @private {number} */
openDropdownTimeoutId_: 0,
+ /** @private {?ResizeObserver} */
+ resizeObserver_: null,
+
/** @override */
attached() {
this.pointerDownListener_ = this.onPointerDown_.bind(this);
document.addEventListener('pointerdown', this.pointerDownListener_);
+ this.resizeObserver_ = new ResizeObserver(() => {
+ this.resizeDropdown_();
+ });
+ this.resizeObserver_.observe(this.$.search);
},
/** @override */
detached() {
document.removeEventListener('pointerdown', this.pointerDownListener_);
+ this.resizeObserver_.unobserve(this.$.search);
},
/**
@@ -145,6 +153,19 @@ Polymer({
}
},
+ /**
+ * Keeps the dropdown from expanding beyond the width of the search input when
+ * its width is specified as a percentage.
+ * @private
+ */
+ resizeDropdown_() {
+ const dropdown = this.$$('iron-dropdown').containedElement;
+ const dropdownWidth =
+ Math.max(dropdown.offsetWidth, this.$.search.offsetWidth);
+ dropdown.style.width = `${dropdownWidth}px`;
+ this.enqueueDropdownRefit_();
+ },
+
/** @private */
openDropdown_() {
this.$$('iron-dropdown').open();
@@ -439,7 +460,7 @@ Polymer({
* leave the user's text in the dropdown search bar when focus is changed.
* @private
*/
- onBlur_ : function () {
+ onBlur_() {
if (!this.updateValueOnInput) {
this.$.search.value = this.value;
}
@@ -453,8 +474,9 @@ Polymer({
* |invalid| to false.
* @private
*/
- updateInvalid_: function () {
+ updateInvalid_() {
this.invalid =
!this.updateValueOnInput && (this.value !== this.$.search.value);
},
});
+/* #ignore */ console.warn('crbug/1173575, non-JS module files deprecated.');