Skip to content

Commit

Permalink
simulate button click outside button
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-kennedy-ecs committed Dec 23, 2024
1 parent 1b813ca commit f817dbd
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/registrar/assets/src/js/getgov/table-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,12 @@ export class BaseTable {
// Add event listeners to table headers for sorting
initializeTableHeaders() {
this.tableHeaders.forEach(header => {
const sortBy = header.getAttribute('data-sortable');

// add event listener to respond to clicks on the button
let button = header.querySelector('.usa-table__header__button')
button.addEventListener('click', () => {

header.addEventListener('click', function(event) {
let button = header.querySelector('.usa-table__header__button')
const sortBy = header.getAttribute('data-sortable');
let order = 'asc';
// sort order will be ascending, unless the currently sorted column is ascending, and the user
// is selecting the same column to sort in descending order
Expand All @@ -507,6 +509,11 @@ export class BaseTable {
}
// load the results with the updated sort
this.loadTable(1, sortBy, order);
// Check if the click occurred outside the button
if (!button.contains(event.target)) {
// Simulate a button click
button.click();
}
});
});
}
Expand Down

0 comments on commit f817dbd

Please sign in to comment.