Skip to content

Commit

Permalink
Playground block: A11Y: Add link to skip preview (#308)
Browse files Browse the repository at this point in the history
## What and Why?

Offer a skip link so users using assistive technology and
keyboard-driven workflows have an opportunity to skip over the
Playground preview iframe.

Fixes #293

## How?

This PR adds a number of items that are hidden visually but shown if
they receive focus.
- Text noting the "Beginning of Playground Preview"
- A link "Skip Playground Preview Iframe"
- Test noting "End of Playground Preview"

The "Skip Playground Preview Iframe" link is shown when focused.
![Screenshot 2024-06-14 at 2 02
55 PM](https://github.com/WordPress/playground-tools/assets/530877/7820b51c-a3d1-4a2c-b6d3-07d29b36bd3b)

When the skip-link is clicked, it focuses "End of Playground Preview"
which is revealed at the bottom of the preview pane when focused.
![Screenshot 2024-06-14 at 2 03
18 PM](https://github.com/WordPress/playground-tools/assets/530877/09baa829-8891-4888-ae91-4502948ec321)

## Testing Instructions

In both the editor and front end, test working with an instance of the
block by focusing the "Run" button, tab to the next link which is "Skip
Playground Preview", click it, and confirm focus is moved to "End of
Playground Preview".
  • Loading branch information
brandonpayton committed Jun 18, 2024
1 parent e7c9636 commit 1a47ce4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export default function PlaygroundPreview({
});

const iframeRef = useRef<HTMLIFrameElement>(null);
const afterPreviewRef = useRef<HTMLSpanElement>(null);
const playgroundClientRef = useRef<PlaygroundClient | null>(null);
const fileMgrRef = useRef<FileManagerRef>(null);
const codeMirrorRef = useRef<any>(null);
Expand Down Expand Up @@ -517,6 +518,21 @@ export default function PlaygroundPreview({
</div>
)}
<div className="playground-container">
<span className="screen-reader-text">
Beginning of Playground Preview
</span>
<a
href="#"
className="screen-reader-text"
onClick={(event) => {
event.preventDefault();
if (afterPreviewRef.current) {
afterPreviewRef.current.focus();
}
}}
>
Skip Playground Preview
</a>
{!isLivePreviewActivated && (
<div className="playground-activation-placeholder">
<Button
Expand Down Expand Up @@ -556,6 +572,13 @@ export default function PlaygroundPreview({
className="playground-iframe"
></iframe>
)}
<span
className="screen-reader-text wordpress-playground-end-of-preview"
tabIndex={-1}
ref={afterPreviewRef}
>
End of Playground Preview
</span>
</div>
</section>
<footer className="demo-footer">
Expand Down
6 changes: 6 additions & 0 deletions packages/wordpress-playground-block/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
cursor: pointer;
}

.screen-reader-text.wordpress-playground-end-of-preview,
.screen-reader-text.wordpress-playground-end-of-preview:focus {
top: initial;
bottom: 5px;
}

.demo-container {
display: flex;
box-shadow: #03254b47 0px 12px 50px 0px;
Expand Down

0 comments on commit 1a47ce4

Please sign in to comment.