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

feat(Drawer): added focustrap functionality #9469

Merged
merged 4 commits into from
Sep 1, 2023

Conversation

thatblindgeye
Copy link
Contributor

@thatblindgeye thatblindgeye commented Aug 7, 2023

What: Closes #5354

Drawer with focus trap example

Additional issues:

@thatblindgeye thatblindgeye requested a review from edonehoo August 7, 2023 19:51
@patternfly-build
Copy link
Contributor

patternfly-build commented Aug 7, 2023

@thatblindgeye thatblindgeye force-pushed the iss5354_drawerFocustrap branch from 86fd02f to 2c428c0 Compare August 8, 2023 12:43

### With focus trap

Use the `focusTrap` property to enable and customize a focus trap on the `<DrawerPanelContent>`. Enabling a focus trap with `focusTrap.enabled` will also automatically place focus on the first focusable element when the drawer panel expands, and return focus to the previously focused element when it collapses.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Use the `focusTrap` property to enable and customize a focus trap on the `<DrawerPanelContent>`. Enabling a focus trap with `focusTrap.enabled` will also automatically place focus on the first focusable element when the drawer panel expands, and return focus to the previously focused element when it collapses.
A focus trap contains focus within an overlay element. When a focus trap is enabled on an element, a user can only interact with elements inside of the focused area until the focus trap is closed or deactivated.
To enable and customize a focus trap on a drawer panel, apply the `focusTrap` property to the `<DrawerPanelContent>` component. Enabling a focus trap with `focusTrap.enabled` will also automatically place focus on the first focusable element when the drawer panel expands, and return focus to the previously focused element when it collapses.

Does this addition sound accurate and useful? Thought it may be good to briefly describe what a focus trap is, but lmk if not (I scrapped together an understanding from a little googling).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might be worth mentioning. Considering other components use a focus trap, would it be better to have it in a single place that can be referenced? We do have content on trapping focus on the PF site, though it's a bit more specific to Modal and Popover.

For the example description, what do you think about, "When a focus trap is enabled on an element, a user will only be able to interact with the contents of that element until the focus trap is closed or deactivated." as the first line (followed by the "To enable and customize a focus trap..." content)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh thanks for the extra info! Since we have that section on trapping focus in the accessibility docs, what if we just link to that doc on the first instance of "focus trap"? If that trapping focus info would benefit from being expanded we could always do that in a followup issue (doing a content review/audit of the accessibility docs is already on my to-do list as part of the wider site content audit)?

I like your suggestion for reframing the content!

@thatblindgeye
Copy link
Contributor Author

@edonehoo updated per convo above, let me know what you think! Would you want to open a followup in org for updating the "trapping focus" docs?

@edonehoo
Copy link
Contributor

edonehoo commented Aug 8, 2023

Looks great to me! I made a note to include trapping focus updates in this issue.

Copy link
Contributor

@edonehoo edonehoo 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 on the content side 👍

@tlabaj tlabaj added the A11y label Aug 14, 2023
Copy link
Contributor

@kmcfaul kmcfaul left a comment

Choose a reason for hiding this comment

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

lgtm on the code side

@thatblindgeye thatblindgeye force-pushed the iss5354_drawerFocustrap branch from fc7c7f0 to 0a3e2b1 Compare August 21, 2023 18:59
@thatblindgeye thatblindgeye force-pushed the iss5354_drawerFocustrap branch from 0a3e2b1 to eceebd6 Compare August 23, 2023 12:57
*/
elementToFocusOnExpand?: HTMLElement | SVGElement | string;
/** One or more id's to use for the drawer panel content's accessible label. */
'aria-labelledby'?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this only needed when we have focus trap enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the focus trap enabled we're adding a role="dialog" to the panel content. MDN has some context on labelling a dialog. For the non-focus trap Drawer, we just have a plain div which typically doesn't do well with aria labelling.

Copy link
Contributor

@nicolethoen nicolethoen left a comment

Choose a reason for hiding this comment

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

Voice over and keyboard interactions all look great!

@tlabaj tlabaj merged commit 41fedc5 into patternfly:main Sep 1, 2023
@patternfly-build
Copy link
Contributor

Your changes have been released in:

  • @patternfly/react-code-editor@5.1.1-prerelease.4
  • @patternfly/react-core@5.1.1-prerelease.4
  • @patternfly/react-docs@6.1.1-prerelease.4
  • @patternfly/react-integration@5.1.1-prerelease.5
  • demo-app-ts@5.1.1-prerelease.3
  • @patternfly/react-table@5.1.1-prerelease.4

Thanks for your contribution! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow drawer to use focus trap
6 participants