From 12f048f5eee3dedd302db43c3b61b25ef25aa50e Mon Sep 17 00:00:00 2001 From: far-fetched Date: Mon, 1 Nov 2021 19:32:48 +0100 Subject: [PATCH] :white_check_mark: set return focus test --- addon/components/dialog.ts | 5 ++- tests/integration/components/dialog-test.js | 38 +++++++++++++++++---- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/addon/components/dialog.ts b/addon/components/dialog.ts index 9bdefea5..56be143b 100644 --- a/addon/components/dialog.ts +++ b/addon/components/dialog.ts @@ -112,11 +112,14 @@ export default class DialogComponent extends Component { @action allowOutsideClick(e: MouseEvent) { let target = e.target as HTMLElement; + if (target && target.tagName !== 'BODY') { this.outsideClickedElement = target; } + this.onClose(); - return true + + return true; } @action diff --git a/tests/integration/components/dialog-test.js b/tests/integration/components/dialog-test.js index 94202663..e8be2dcd 100644 --- a/tests/integration/components/dialog-test.js +++ b/tests/integration/components/dialog-test.js @@ -405,13 +405,33 @@ module('Integration | Component | ', function (hooks) { assertDialog({ state: DialogState.InvisibleUnmounted }); - assertActiveElement(getByText('Trigger')); + await assertActiveElement(getByText('Trigger')); }); - todo( - 'it should be possible to close the dialog, and keep focus on the focusable element', - async function () {} - ); + test('it should be possible to close the dialog, and keep focus on the focusable element', async function () { + this.set('isOpen', false); + + await render(hbs` + + + + Contents +
+
+ `); + + await click(getByText('Trigger')); + + assertDialog({ state: DialogState.Visible }); + + await click(getByText('Hello')); + + assertDialog({ state: DialogState.InvisibleUnmounted }); + + await assertActiveElement(getByText('Hello')); + }); test('it should stop propagating click events when clicking on the Dialog.Overlay', async function (assert) { this.set('isOpen', true); @@ -768,11 +788,15 @@ module('Integration | Component | ', function (hooks) { //close the top most dialog with ${strategy} await action(); - assert.equal(getDialogs(), 0, 'Verify that we have 0 open dialogs'); + assert.equal( + getDialogs().length, + 0, + 'Verify that we have 0 open dialogs' + ); await assertActiveElement( getByText('Open 1'), - 'Verify that we have 1 open dialog' + 'Verify that the `Open 1` got focused again' ); } );