16959 fix filter reset button

This commit is contained in:
Arthur Hanson 2024-08-14 20:17:10 +07:00
parent 09d36469dd
commit 233173c225
3 changed files with 18 additions and 1 deletions

Binary file not shown.

Binary file not shown.

View File

@ -7,7 +7,7 @@ import { DynamicParamsMap } from './dynamicParamsMap';
// Transitional
import { QueryFilter, PathFilter } from '../types'
import { getElement, replaceAll } from '../../util';
import { findFirstAdjacent, getElement, replaceAll } from '../../util';
// Extends TomSelect to provide enhanced fetching of options via the REST API
@ -68,6 +68,9 @@ export class DynamicTomSelect extends TomSelect {
this.updatePathValues(filter);
}
// Initialize controlling elements.
this.initResetButton();
// Add dependency event listeners.
this.addEventListeners();
}
@ -311,6 +314,20 @@ export class DynamicTomSelect extends TomSelect {
}
}
/**
* Initialize any adjacent reset buttons so that when clicked, the page is reloaded without
* query parameters.
*/
private initResetButton(): void {
const resetButton = document.querySelector<HTMLButtonElement>('button[data-reset-select]');
if (resetButton !== null) {
resetButton.addEventListener('click', () => {
window.location.assign(window.location.origin + window.location.pathname);
});
}
}
/**
* Events
*/