UX: Resize dmenu width for filter on window resize (#34091)

Since we don't have native floatkit/dmenu functionality (yet) to
make the menu stick to the width of the element, this is a
stopgap solution to make sure the menu stays the same width
as the filter input whether resizing the window or hiding/showing
the menu.
This commit is contained in:
Martin Brennan
2025-08-05 17:44:06 +10:00
committed by GitHub
parent c61a6f83e7
commit 37d1849de6
@@ -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";
}
}
@action
handleKeydown(event) {
if (