Skip to content

Commit

Permalink
Accessibility: Enable filter removal using keyboard input.
Browse files Browse the repository at this point in the history
  • Loading branch information
diamondap committed Mar 19, 2024
1 parent dd63f85 commit 5fa88e4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion views/shared/_filter_chips.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div class="filters-grid-clear">
{{ range $index, $chip := .filterChips }}
<button class="badge filter-chip mb-3">
<button class="badge filter-chip mb-3" data-filter-index="{{ $index }}">
<strong class="mr-1">{{ $chip.ChipLabel }}:</strong> {{ $chip.ChipValue }}
<span class="icon material-icons md-16" aria-hidden="true" onclick="removeFilter({{ $index }})">cancel</span>
</button>
Expand Down Expand Up @@ -69,5 +69,15 @@
let newUrl = url + '?' + newParams.toString()
window.location = newUrl
}

// Accessibility: Let user remove filters with keyboard navigation.
document.querySelectorAll('[data-filter-index]').forEach((el) => {
el.addEventListener("keydown", function(event){
if(event.keyCode == 13) {
let filterIndex = el.getAttribute("data-filter-index")
removeFilter(filterIndex)
}
})
})
</script>
{{ end }}

0 comments on commit 5fa88e4

Please sign in to comment.