-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (accessibility filter) : improvements (#6)
- Loading branch information
1 parent
af3694d
commit 56777dc
Showing
3 changed files
with
52 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,40 @@ | ||
// IDENTITFICATION DE L'OPTION CHOISIE | ||
// AFFICHE NOM OPTION PAR DEFAUT | ||
document.querySelector('.filter__selected').setAttribute('value', 'Popularité'); | ||
|
||
// IDENTITFIE OPTION CHOISIE | ||
// ouvre la box au click | ||
document.querySelector('.filter').addEventListener('click', function () { | ||
this.querySelector('.filter__box').classList.toggle('open'); | ||
}); | ||
|
||
// iteration sur les options : affecte "selected" à celle qui est choisie | ||
// itere sur les options | ||
for (const option of document.querySelectorAll('.filter__option')) { | ||
option.addEventListener('click', function () { | ||
if (!option.classList.contains('selected')) { | ||
option.parentNode | ||
// retire "selected" sur ancienne option | ||
.querySelector('.filter__option.selected') | ||
.classList.remove('selected'); | ||
// affecte "selected" sur nouvelle option | ||
option.classList.add('selected'); | ||
option | ||
.closest('.filter__box') | ||
.querySelector('.filter__selected li').textContent = this.textContent; | ||
.querySelector('.filter__selected') | ||
// affecte classe "button" sur input | ||
.classList.add('btn'); | ||
option | ||
.closest('.filter__box') | ||
.querySelector('.filter__selected') | ||
// affecte nom option choisie dans input | ||
.setAttribute('value', this.textContent); | ||
} | ||
}); | ||
|
||
// ferme la liste d'option si click en dehors de la box | ||
// ferme listbox si click hors box | ||
window.addEventListener('click', function (e) { | ||
const select = document.querySelector('.filter__box'); | ||
if (!select.contains(e.target)) { | ||
select.classList.remove('open'); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters