Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set focus to modal usage instructions #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ <h2>Features</h2>
</li>
</ol>
</div>
<div id="modal" aria-hidden="true" aria-labelledby="modalTitle" aria-describedby="modalDescription" role="dialog">
<div id="modal" aria-hidden="true" aria-labelledby="modalTitle" aria-describedby="modalUsage" role="dialog">
<div role="document"> <!-- Optional role if you want screen reader users to be able to interact with objects other than focusable elements and their labels. -->
<div id="modalDescription" class="screen-reader-offscreen">Beginning of dialog window. It begins with a heading 1 called &quot;Registration Form&quot;. Escape will cancel and close the window. This form does not collect any actual information.</div>
<div id="modalUsage" tabindex="-1" class="screen-reader-offscreen">Escape key will cancel and close this dialog window.</div>
<h1 id="modalTitle">Registration Form</h1>
<p>These are the onscreen instructions that are not attached explicitly to a focusable element. Can screen reader users read this text with the virtual cursor?</p>
<form name="form1" method="post" action="">
Expand Down
9 changes: 3 additions & 6 deletions modal-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,11 @@ function showModal(obj) {
// save current focus
focusedElementBeforeModal = jQuery(':focus');

// get list of all children elements in given object
var o = obj.find('*');

// Safari and VoiceOver shim
// if VoiceOver in Safari is used, set the initial focus to the modal window itself instead of the first keyboard focusable item. This causes VoiceOver to announce the aria-labelled attributes. Otherwise, Safari and VoiceOver will not announce the labels attached to the modal window.

// set the focus to the first keyboard focusable item
o.filter(focusableElementsString).filter(':visible').first().focus();
// set the focus to the modal usage instructions.
$('#modalUsage').focus();


}
Expand All @@ -187,4 +184,4 @@ function hideModal() {

// set focus back to element that had it before the modal was opened
focusedElementBeforeModal.focus();
}
}