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

319 overlay accessibility reworked #391

Merged
merged 3 commits into from
Oct 17, 2023

Conversation

chriswilty
Copy link
Member

@chriswilty chriswilty commented Oct 12, 2023

Description
Based on work by @heatherlogan-scottlogic and @gsproston-scottlogic, this PR tackles some accessibility issues with the overlay.

Highlights:

  • click-outside-to-close on overlay (in a React stylee)
  • tabs in handbook (from level 2 onwards) moved inside the dialog, else click-outside-to-close would close the popup when changing tab by click
  • Removed some global styles at element level that were polluting the entire stylesheet

image

Supersedes PR #362

Closes #319

@chriswilty chriswilty self-assigned this Oct 12, 2023
@chriswilty chriswilty added this to the MVP milestone Oct 12, 2023
Base automatically changed from 334-move-info-message-to-handbook to dev October 12, 2023 14:14
@chriswilty chriswilty force-pushed the 319-overlay-accessibility-reworked branch from 3003a3f to 5efb0cb Compare October 12, 2023 14:15
) : (
""
);
) : null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: if you don't want to render anything, return null or undefined, not empty string.

button {
height: 100%;
width: 100%;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was being applied to all buttons because the css selector is non-specific. Nest styles in top-level classes wherever possible, e.g. this could've been

.export-chat-link > button {

@media (min-width: 768px) {
body {
font-size: 1.125rem;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this was being applied universally to the body, and affecting all our content. Always exercise caution when applying styles to an element without any preceding selectors.


return () => {
window.removeEventListener("keydown", handleEscape);
window.removeEventListener("click", handleOverlayClick);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gsproston-scottlogic Adding event listeners to the window means we don't get linter warnings about clicks bound to a non-interactive element. We just need to remember to remove them on unmount.

(event: MouseEvent) => {
contentRef.current &&
!event.composedPath().includes(contentRef.current) &&
closeOverlay();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice modern way to check if an event was triggered by an element or any of its children. If the click was within the content element then we ignore it, else we close the overlay.

@chriswilty chriswilty removed this from the MVP milestone Oct 13, 2023
@chriswilty chriswilty force-pushed the 319-overlay-accessibility-reworked branch from 5efb0cb to 8ee06ec Compare October 13, 2023 14:34
Copy link
Contributor

@heatherlogan-scottlogic heatherlogan-scottlogic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me - yes we can remove the Tools tab for now

Copy link
Contributor

@gsproston-scottlogic gsproston-scottlogic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff! Just one small thing from me.

}, []);

useEffect(() => {
window.addEventListener("keydown", handleEscape);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, we shouldn't need to listen for escape presses to close the modal, the dialog element should handle that for us!

Copy link
Member Author

@chriswilty chriswilty Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, but we need our state to update, and when the dialog closes itself without us intercepting the keypress, we don't get that state update so the code still thinks the dialog is open. And our event listeners are still bound.

This is a good example of a controlled react component. We tell the dialog what state to be in, rather than listening for changes and reacting after the fact.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah right makes sense!

@chriswilty
Copy link
Member Author

@heatherlogan-scottlogic I've removed the Tools tab. Note that if we also remove the Mission Info, we'll only have Attacks remaining in the handbook... Just saying!

@chriswilty chriswilty force-pushed the 319-overlay-accessibility-reworked branch from ef3d80d to c9e6f37 Compare October 17, 2023 11:44
@chriswilty chriswilty merged commit 028f29f into dev Oct 17, 2023
2 checks passed
@chriswilty chriswilty deleted the 319-overlay-accessibility-reworked branch October 17, 2023 12:24
@gsproston-scottlogic
Copy link
Contributor

@heatherlogan-scottlogic I've removed the Tools tab. Note that if we also remove the Mission Info, we'll only have Attacks remaining in the handbook... Just saying!

I remember there being talk about having a handbook section on the architecture of the backend (what LLMs are being used and how), and also a glossary page for certain terms. So we can fill up the handbook with more stuff if we like.

chriswilty added a commit that referenced this pull request Apr 8, 2024
* Make overlay and handbook accessible
* Add click-outside handling to overlay

---------
Co-authored-by: Chris Wilton-Magras <[email protected]>
Co-authored-by: George Sproston <[email protected]>
Co-authored-by: Heather Logan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

accessibility and narrator issues for overlay
3 participants