-
Notifications
You must be signed in to change notification settings - Fork 12
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
319 accessibility and narrator issues for overlay #362
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
/* eslint-disable jsx-a11y/no-static-element-interactions */ | ||
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */ | ||
/* eslint-disable jsx-a11y/click-events-have-key-events */ | ||
// The above eslint rules are disabled to allow the user to click outside of the dialog to close it. | ||
// Keyboard users are able to close the dialog by pressing the escape key, or tabbing to the close icon. | ||
|
||
import { LEVEL_NAMES } from "../../models/level"; | ||
import { OVERLAY_TYPE } from "../../models/overlay"; | ||
import HandbookAttacks from "./HandbookAttacks"; | ||
|
@@ -24,18 +30,23 @@ function HandbookOverlay({ | |
} | ||
|
||
return ( | ||
<div className="handbook-overlay-screen"> | ||
<div className="handbook-overlay"> | ||
<button | ||
className="prompt-injection-min-button close-button" | ||
onClick={closeOverlay} | ||
aria-label="close handbook overlay" | ||
> | ||
X | ||
</button> | ||
<div className="handbook-overlay-content">{showOverlayByType()}</div> | ||
<dialog className="handbook-overlay" onClick={closeOverlay}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do wonder if we should be binding the click to the window, instead of directly to the dialog element, and then determining from the click event whether the click was outside the content box. Then you'd likely not need to disable those linter rules. I'm going to check out your branch and see... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that works 🎉 |
||
<button | ||
className="prompt-injection-min-button close-button" | ||
onClick={closeOverlay} | ||
aria-label="close handbook overlay" | ||
> | ||
X | ||
</button> | ||
<div | ||
className="handbook-overlay-content" | ||
onClick={(event) => { | ||
event.stopPropagation(); | ||
}} | ||
> | ||
{showOverlayByType()} | ||
</div> | ||
</div> | ||
</dialog> | ||
); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As before, if you find yourself querying elements from
document
, you're not doing it React style.In this case, you could use a forward ref on the HandbookOverlay component. However, it's probably far simpler to pass a prop to HandbookOverlay telling it whether we want it to be open or not, and then use a state var in this App component to store and update that state on clicking the icon.
That's not the end of the story though, as you'll need to use the dialog.showModal() function inside HandbookOverlay component, in order to get a modal popup on-demand. So you'll still need a standard React ref to grab a DOM reference to the dialog element. You'll need to use that ref in a useEffect, to fire showModal or closeModal whenever isOpen changes its value.