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(dialog): add focusTrapDisabled property for non-modal dialogs #11362

Open
wants to merge 20 commits into
base: dev
Choose a base branch
from

Conversation

Elijbet
Copy link
Contributor

@Elijbet Elijbet commented Jan 22, 2025

Related Issue: #10685

Summary

Add focusTrapDisabled attribute to for non-modal dialogs.

@github-actions github-actions bot added the enhancement Issues tied to a new feature or request. label Jan 22, 2025
@Elijbet Elijbet force-pushed the elijbet/10685-focusTrapDisabled-attribute-for-non-modal-dialogs branch from 3a1913a to 702b4c8 Compare January 22, 2025 22:04
@@ -366,6 +369,19 @@ export class Dialog
// #endregion

// #region Private Methods

private handleFocusTrapDisabled(focusTrapDisabled: boolean): void {
if (!this.open) {
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't it deactivate if not open?

Copy link
Member

@driskull driskull Jan 22, 2025

Choose a reason for hiding this comment

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

The logic needs to handle changes to open, modal and focusTrapDisabled.

  • if open is false => do nothing
  • modal is true or focusTrapDisabled is false => activateFocusTrap
  • if focusTrapDisabled is true and modal is false => deactivateFocusTrap
  • else deactivateFocusTrap

Copy link
Member

Choose a reason for hiding this comment

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

I think this hasn't been resolved yet.

Copy link
Member

Choose a reason for hiding this comment

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

I think the onOpen/onClose handles the deactivation part. We may not need this check at all. We can probably remove this function and call activateFocusTrap in its place

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha. Sounds like focusTrapDisabled is intended for use at "open" time. Maybe we can clarify this in the docs. cc @geospatialem @DitwanP

Copy link
Contributor Author

@Elijbet Elijbet Feb 1, 2025

Choose a reason for hiding this comment

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

Yeah, I think we handle that in multiple places. onClose takes care of deactivateFocusTrap, and the rest happens in
focusTrapDisabledOverride(): boolean { return !this.modal && this.focusTrapDisabled; }

@@ -366,6 +369,19 @@ export class Dialog
// #endregion

// #region Private Methods

private handleFocusTrapDisabled(focusTrapDisabled: boolean): void {
if (!this.open) {
Copy link
Member

@driskull driskull Jan 22, 2025

Choose a reason for hiding this comment

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

The logic needs to handle changes to open, modal and focusTrapDisabled.

  • if open is false => do nothing
  • modal is true or focusTrapDisabled is false => activateFocusTrap
  • if focusTrapDisabled is true and modal is false => deactivateFocusTrap
  • else deactivateFocusTrap

@Elijbet Elijbet marked this pull request as ready for review January 24, 2025 23:36
@driskull
Copy link
Member

@Elijbet can we rename

feat(dialog): add focusTrapDisabled attribute to for non-modal dialogs

to feat(dialog): add focusTrapDisabled property for non-modal dialogs

@Elijbet Elijbet marked this pull request as draft January 28, 2025 21:36
@Elijbet Elijbet changed the title feat(dialog): add focusTrapDisabled attribute to for non-modal dialogs feat(dialog): add focusTrapDisabled property to for non-modal dialogs Jan 28, 2025
@Elijbet Elijbet changed the title feat(dialog): add focusTrapDisabled property to for non-modal dialogs feat(dialog): add focusTrapDisabled property for non-modal dialogs Jan 28, 2025
driskull
driskull previously approved these changes Jan 31, 2025
Copy link
Member

@driskull driskull left a comment

Choose a reason for hiding this comment

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

👍 LGTM!

@driskull driskull self-requested a review January 31, 2025 23:45
@driskull driskull dismissed their stale review January 31, 2025 23:46

Reviewed too early

Copy link
Member

@driskull driskull left a comment

Choose a reason for hiding this comment

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

👍 Nice! 🎉

@Elijbet Elijbet marked this pull request as ready for review February 1, 2025 00:04
Copy link
Member

@jcfranco jcfranco left a comment

Choose a reason for hiding this comment

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

Awesome work, @Elijbet! This should be good to merge once comments are addressed.

@@ -112,4 +112,37 @@ describe("focusTrapComponent", () => {
expect(customFocusTrapStack).toHaveLength(1);
});
});
describe("focusTrapDisabledOverride", () => {
it("should activate focus trap when focusTrapDisabledOverride returns false", () => {
const fakeComponent = {} as FocusTrapComponent;
Copy link
Member

Choose a reason for hiding this comment

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

Let's DRY test setup by using beforeEach.

expect(activeElementId).toBe(await outsideEl.getProperty("id"));
});

it("cannot tab out of dialog when modal=true and focusTrapDisabled=true", async () => {
Copy link
Member

Choose a reason for hiding this comment

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

For completeness, can you add tests that cover focusTrapDisabled = false?

@@ -366,6 +369,19 @@ export class Dialog
// #endregion

// #region Private Methods

private handleFocusTrapDisabled(focusTrapDisabled: boolean): void {
if (!this.open) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this hasn't been resolved yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Issues tied to a new feature or request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants