A platform for community discussion. Free, open, simple.
UX: Resize dmenu width for filter on window resize (#34091)
Martin Brennan37d1849de66e
diff --git a/app/assets/javascripts/discourse/app/components/discovery/filter-navigation-menu.gjs b/app/assets/javascripts/discourse/app/components/discovery/filter-navigation-menu.gjsindex babbcc06486..ade375ea64a 100644--- a/app/assets/javascripts/discourse/app/components/discovery/filter-navigation-menu.gjs+++ b/app/assets/javascripts/discourse/app/components/discovery/filter-navigation-menu.gjs@@ -15,6 +15,7 @@ import concatClass from "discourse/helpers/concat-class";import icon from "discourse/helpers/d-icon";import withEventValue from "discourse/helpers/with-event-value";import discourseDebounce from "discourse/lib/debounce";+import { bind } from "discourse/lib/decorators";import FilterSuggestions from "discourse/lib/filter-suggestions";import { resettableTracked } from "discourse/lib/tracked-tools";import { i18n } from "discourse-i18n";@@ -86,6 +87,16 @@ export default class FilterNavigationMenu extends Component {@tracked _selectedIndex = -1;+ constructor() {+ super(...arguments);+ window.addEventListener("resize", this.resizeDMenu);+ }++ willDestroy() {+ super.willDestroy(...arguments);+ window.removeEventListener("resize", this.resizeDMenu);+ }+get selectedIndex() {return this._selectedIndex;}@@ -377,6 +388,12 @@ export default class FilterNavigationMenu extends Component {async openFilterMenu() {if (this.dMenuInstance) {this.dMenuInstance.show();++ // HACK: We don't have a nice way for DMenu to be the same width as+ // the input element, so we set it manually.+ schedule("afterRender", () => {+ this.resizeDMenu();+ });return;}@@ -390,13 +407,22 @@ export default class FilterNavigationMenu extends Component {// HACK: We don't have a nice way for DMenu to be the same width as// the input element, so we set it manually.schedule("afterRender", () => {- if (this.dMenuInstance?.content) {- this.dMenuInstance.content.style.width =- this.inputElement.offsetWidth + "px";- }+ this.resizeDMenu();});}+ @bind+ resizeDMenu() {+ if (!this.inputElement || !this.dMenuInstance) {+ return;+ }++ if (this.dMenuInstance.content) {+ this.dMenuInstance.content.style.width =+ this.inputElement.offsetWidth + "px";+ }+ }+@actionhandleKeydown(event) {if (