Skip to content
Snippets Groups Projects
Unverified Commit 75f73f35 authored by Olivia Simonet's avatar Olivia Simonet Committed by GitHub
Browse files

Merge pull request #113 from noesya/features/focus-trap

Features/focus trap
parents 23766d12 26ae3d6c
No related branches found
No related tags found
No related merge requests found
...@@ -29,15 +29,16 @@ class Modal { ...@@ -29,15 +29,16 @@ class Modal {
this.closeButtons.forEach(button => { this.closeButtons.forEach(button => {
button.addEventListener('click', () => { button.addEventListener('click', () => {
this.toggle(false); this.toggle(false);
this.button.focus()
}); });
}); });
window.addEventListener('keydown', (event) => { window.addEventListener('keydown', (event) => {
if (event.keyCode === 27 || event.key === 'Escape') { if (event.keyCode === 27 || event.key === 'Escape') {
this.toggle(false); this.toggle(false);
} else if (event.key === "Tab") { } else if (event.key === "Tab" && this.state.isOpened) {
// TODO fix a11y inner focus this.innerFocus(event);
// this.innerFocus(event); event.preventDefault();
} }
}); });
...@@ -66,8 +67,7 @@ class Modal { ...@@ -66,8 +67,7 @@ class Modal {
else if (!this.element.contains(event.target)) { else if (!this.element.contains(event.target)) {
firstFocusable.focus(); firstFocusable.focus();
} }
firstFocusable.focus();
this.closeButtons[0].focus();
} }
toggle(open = !this.state.isOpened) { toggle(open = !this.state.isOpened) {
...@@ -76,10 +76,6 @@ class Modal { ...@@ -76,10 +76,6 @@ class Modal {
this.element.setAttribute('aria-hidden', !this.state.isOpened); this.element.setAttribute('aria-hidden', !this.state.isOpened);
document.documentElement.classList[classAction](CLASSES.modalOpened); document.documentElement.classList[classAction](CLASSES.modalOpened);
if (!this.state.isOpened) {
this.button.focus();
}
} }
} }
......
<article class="volume"> <article class="volume" itemscope itemtype="https://schema.org/Book https://schema.org/PublicationVolume">
<hgroup> <hgroup>
<p class="suptitle">{{ i18n "volumes.volume_number" (dict "Number" .Params.Number) }}</p> <p class="suptitle" itemprop="volumeNumber">{{ i18n "volumes.volume_number" (dict "Number" .Params.Number) }}</p>
<h2><a href="{{ .Permalink }}" title="{{ i18n "commons.more_aria" (dict "Title" .Title) }}">{{ partial "PrepareHTML" .Title }}</a></h2> <h2><a href="{{ .Permalink }}" title="{{ i18n "commons.more_aria" (dict "Title" .Title) }}" itemprop="name">{{ partial "PrepareHTML" .Title }}</a></h2>
</hgroup> </hgroup>
<div class="media"> <div class="media">
{{- if .Params.image -}} {{- if .Params.image -}}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment