header click updates button

This commit is contained in:
David Kennedy 2024-12-23 09:41:14 -05:00
parent f817dbdf18
commit ebe8aa7f78
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B

View file

@ -495,10 +495,7 @@ export class BaseTable {
// Add event listeners to table headers for sorting // Add event listeners to table headers for sorting
initializeTableHeaders() { initializeTableHeaders() {
this.tableHeaders.forEach(header => { this.tableHeaders.forEach(header => {
header.addEventListener('click', event => {
// add event listener to respond to clicks on the button
header.addEventListener('click', function(event) {
let button = header.querySelector('.usa-table__header__button') let button = header.querySelector('.usa-table__header__button')
const sortBy = header.getAttribute('data-sortable'); const sortBy = header.getAttribute('data-sortable');
let order = 'asc'; let order = 'asc';
@ -509,7 +506,9 @@ export class BaseTable {
} }
// load the results with the updated sort // load the results with the updated sort
this.loadTable(1, sortBy, order); this.loadTable(1, sortBy, order);
// Check if the click occurred outside the button // If the click occurs outside of the button, need to simulate a button click in order
// for USWDS listener on the button to execute.
// Check first to see if click occurs outside of the button
if (!button.contains(event.target)) { if (!button.contains(event.target)) {
// Simulate a button click // Simulate a button click
button.click(); button.click();