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: Dialogs: If no focusable elements in container, make content container focusable [GAUD-7001] #4994

Merged
merged 10 commits into from
Sep 23, 2024

Conversation

margaree
Copy link
Contributor

Jira ticket

Deque context

Dialogs have a potential axe violation where if there are no focusable elements in dialog content but the content overflowed, then focus should go to the content container, which was not happening.

Copy link
Contributor

Thanks for the PR! 🎉

We've deployed an automatic preview for this PR - you can see your changes here:

URL https://live.d2l.dev/prs/BrightspaceUI/core/pr-4994/

Note

The build needs to finish before your changes are deployed.
Changes to the PR will automatically update the instance.

@margaree margaree marked this pull request as ready for review September 20, 2024 14:36
@margaree margaree requested a review from a team as a code owner September 20, 2024 14:36
@@ -43,6 +43,7 @@ export const DialogMixin = superclass => class extends RtlMixin(superclass) {
*/
titleText: { type: String, attribute: 'title-text' },
_autoSize: { state: true },
_focusableContentElem: { state: true },
Copy link
Contributor

@dbatiste dbatiste Sep 20, 2024

Choose a reason for hiding this comment

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

Nit: I'd probably name this _hasFocusableContentElement or something along those lines. Currently, it sounds like it would be reference to a DOM node. I think we sorta try to avoid prefixes like that though, so it could also be named more along the lines of _focusContentContainer (which unfortunately also sounds like a method, not a property). 🤷‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wondered about that - I also thought _has would be more appropriate but left it out since we avoid those. I'll think a bit more on it.

@dbatiste
Copy link
Contributor

It looks like it's getting the default outline in the diffs. I'm guessing we probably want to apply our preferred focus styles?

margaree and others added 2 commits September 20, 2024 11:29
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
margaree and others added 2 commits September 20, 2024 15:41
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@@ -476,6 +481,9 @@ export const DialogMixin = superclass => class extends RtlMixin(superclass) {
styles.top = `${iframeTopOverride}px`;
}

if (!this._focusableContentElemPresent) this.shadowRoot.querySelector('.d2l-dialog-content')?.setAttribute('tabindex', '0');
else this.shadowRoot.querySelector('.d2l-dialog-content')?.removeAttribute('tabindex');
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to avoid manipulating DOM nodes inside of render() here? I guess the mixin isn't responsible for rendering the dialog content, but maybe the places that are could either be passed the value of focusableContenteElemPresent or they could access it themselves?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup I think we can do that. The disadvantage is that it becomes another thing that consumers of DialogMixin would have to do, and we'd want to update places that use DialogMixin (but outside of core there are only 2 so that's not too bad).

Copy link
Member

Choose a reason for hiding this comment

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

Cool. I think I'd personally prefer that... it feels weird that the mixin even knows about an element with that CSS class, let alone reaching in to manipulate it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed - I'll make that change.

@@ -22,7 +22,7 @@ <h2>Confirm Dialog</h2>
<d2l-demo-snippet>
<template>
<d2l-button id="openConfirm">Show Confirm</d2l-button>
<d2l-dialog-confirm id="confirm" text="Are you sure you want more cookies?">
<d2l-dialog-confirm id="confirm" title-text="Confirm Title" text="Are you sure you want more cookies?">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This had been removed in a previous PR but there's another example on the page that's specifically for this case so I re-added this.

Copy link
Member

@dlockhart dlockhart left a comment

Choose a reason for hiding this comment

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

Even with the slight duplication, this feels much better to me.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@margaree margaree merged commit 1efe733 into main Sep 23, 2024
6 checks passed
@margaree margaree deleted the dialog-focusable-container branch September 23, 2024 18:44
Copy link

🎉 This PR is included in version 3.42.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

3 participants