-
Notifications
You must be signed in to change notification settings - Fork 77
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
base: dev
Are you sure you want to change the base?
feat(dialog): add focusTrapDisabled property for non-modal dialogs #11362
Conversation
3a1913a
to
702b4c8
Compare
@@ -366,6 +369,19 @@ export class Dialog | |||
// #endregion | |||
|
|||
// #region Private Methods | |||
|
|||
private handleFocusTrapDisabled(focusTrapDisabled: boolean): void { | |||
if (!this.open) { |
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.
shouldn't it deactivate if not open?
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.
The logic needs to handle changes to open
, modal
and focusTrapDisabled
.
- if
open
is false => do nothing modal
is true orfocusTrapDisabled
is false => activateFocusTrap- if
focusTrapDisabled
is true and modal is false => deactivateFocusTrap - else deactivateFocusTrap
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.
I think this hasn't been resolved yet.
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.
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
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.
Gotcha. Sounds like focusTrapDisabled
is intended for use at "open" time. Maybe we can clarify this in the docs. cc @geospatialem @DitwanP
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.
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) { |
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.
The logic needs to handle changes to open
, modal
and focusTrapDisabled
.
- if
open
is false => do nothing modal
is true orfocusTrapDisabled
is false => activateFocusTrap- if
focusTrapDisabled
is true and modal is false => deactivateFocusTrap - else deactivateFocusTrap
packages/calcite-components/src/components/dialog/dialog.e2e.ts
Outdated
Show resolved
Hide resolved
…-non-modal-dialogs
@Elijbet can we rename
to |
packages/calcite-components/src/utils/focusTrapComponent.spec.ts
Outdated
Show resolved
Hide resolved
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.
👍 LGTM!
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.
👍 Nice! 🎉
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.
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; |
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.
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 () => { |
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.
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) { |
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.
I think this hasn't been resolved yet.
Related Issue: #10685
Summary
Add
focusTrapDisabled
attribute to for non-modal
dialog
s.