[TASK] add filter and change aria-pressed style button

This commit is contained in:
Marie Birner
2023-04-07 21:59:25 +02:00
parent e8799e5766
commit f2df222f89
3 changed files with 31 additions and 3 deletions

View File

@ -33,6 +33,30 @@ function initToggle() {
});
});
}
const monthToggle = <HTMLInputElement>document.querySelector('#filtermonth-js');
const months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
if(monthToggle) {
monthToggle.addEventListener('click', () => {
monthToggle.ariaPressed = (monthToggle.ariaPressed === 'true') ? 'false' : 'true';
const currentMonth = monthToggle.dataset.month;
if(currentMonth) {
const index = months.indexOf(currentMonth);
if (index > -1) { // only splice array when item is found
months.splice(index, 1); // 2nd parameter means remove one item only
}
Array.prototype.forEach.call(months, (month: HTMLElement) => {
const notThisMonth = document.querySelectorAll('div[data-month="' + month + '"]');
Array.prototype.forEach.call(notThisMonth, (notThisMonth: HTMLElement) => {
notThisMonth.classList.toggle('hidden');
});
});
}
});
}
}
function initSearch() {

View File

@ -22,6 +22,6 @@
}
&[aria-pressed='true'] {
@apply outline outline-2 outline-offset-2 outline-primary-600;
@apply outline outline-2 outline-offset-2 outline-primary-600 bg-primary-100 text-primary-950;
}
}