Skip to content

Commit

Permalink
fix (accessibility) : MODALS > escape event (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
codexarama committed May 25, 2021
1 parent aea1aff commit d7f5304
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 29 deletions.
27 changes: 5 additions & 22 deletions js/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ modalOpenBtn.addEventListener('click', () => {
openModal();
});

// close modal(s)
// close modal(s) ("click" event)
const closeModal = () => {
mainContent.setAttribute('arias-hidden', 'false');
modal.setAttribute('aria-hidden', 'true');
Expand All @@ -51,21 +51,10 @@ modalCloseBtn.forEach((btn) =>
})
);

// close modal when escape key is pressed
// -------------------------------------------------------------------------------
// Failed to execute 'addEventListener' on 'EventTarget':
// 2 arguments required, but only 1 present
// form.addEventListener(
// ('keydown',
// (e) => {
// const keyCode = e.keyCode ? e.keyCode : e.which;

// if (modal.hasAttributes('aria-hidden') == 'false' && keyCode === 27) {
// closeModal();
// }
// })
// );
// -------------------------------------------------------------------------------
// close modal(s) ("escape" event)
document.addEventListener('keydown', (keyboardEvent) => {
if (keyboardEvent.keyCode == 27) closeModal();
});

// VERIFICATION DES SAISIES
const inputs = document.querySelectorAll('.formData input');
Expand Down Expand Up @@ -101,11 +90,6 @@ const checkValidity = () => {

checkValidity();

// -------------------------------------------------------------------------------
// ---------- CHECKVALIDITY NE FONCTIONNE PAS sur TEXTAREA ---------- //
// ---------- POURQUOI ?! ---------- //
// -------------------------------------------------------------------------------

// MESSAGES
// Error
const dataError = (input, message) => {
Expand All @@ -131,7 +115,6 @@ form.addEventListener('submit', function (e) {
// -------------------------------------------------------------------------------
// form.reset(); // is not a function
// -------------------------------------------------------------------------------
// closeModal();
}

console.log(`Prénom : ${firstName.value}`);
Expand Down
16 changes: 9 additions & 7 deletions js/lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ const displayLightbox = () => {
// -------------------------------------------------------------------------
// "fleche gauche" au clavier = "click" sur btn
// if (event.keycode == 37) prev.click(); // NE FONCTIONNE PAS
// retire 'selected' du media choisi
// console.log(event.keycode);
// -------------------------------------------------------------------------
// retire 'selected' du media choisi
selectedMedia.classList.remove('selected');
// ---------- console.log(selectedMedia);
// lui affecte index -1
Expand Down Expand Up @@ -101,9 +102,7 @@ const displayLightbox = () => {
// btn "next" visible quand index media < nb total medias
if (selectedMediaIndex < medias.length) next.style.display = 'block';
// btn "next" invisible si dernier media choisi
if (selectedMediaIndex == medias.length - 1)
// if (selectedMediaIndex == mediaLink.length - 1)
next.style.display = 'none';
if (selectedMediaIndex == medias.length - 1) next.style.display = 'none';
};

// AFFICHE MEDIA CHOISI DANS LIGHTBOX
Expand Down Expand Up @@ -132,10 +131,8 @@ const displayLightbox = () => {
}
};

// CLOSE LIGHTBOX
// CLOSE LIGHTBOX ("clik" event)
const closeLightbox = () => {
// const closeLightbox = (event) => {
// if (event.keycode == 27) closeLightbox.onclick(); // NE FONCTIONNE PAS
lightbox.style.display = 'none';
lightboxShow.classList.remove('active');
const medias = document.querySelectorAll('.currentMedia');
Expand All @@ -144,3 +141,8 @@ const closeLightbox = () => {
selectedMedia.classList.remove('selected');
}
};

// CLOSE LIGHTBOX ("escape" event)
document.addEventListener('keydown', (keyboardEvent) => {
if (keyboardEvent.keyCode == 27) closeLightbox();
});

0 comments on commit d7f5304

Please sign in to comment.