Skip to content

Commit

Permalink
✅ set return focus test
Browse files Browse the repository at this point in the history
  • Loading branch information
far-fetched committed Nov 1, 2021
1 parent 0550e59 commit 12f048f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
5 changes: 4 additions & 1 deletion addon/components/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,14 @@ export default class DialogComponent extends Component<Args> {
@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
Expand Down
38 changes: 31 additions & 7 deletions tests/integration/components/dialog-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,33 @@ module('Integration | Component | <Dialog>', 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`
<button>Hello</button>
<button type="button" {{on "click" (set this "isOpen" true)}}>
Trigger
</button>
<Dialog @isOpen={{this.isOpen}} @onClose={{set this "isOpen" false}}>
Contents
<div tabindex="0"></div>
</Dialog>
`);

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);
Expand Down Expand Up @@ -768,11 +788,15 @@ module('Integration | Component | <Dialog>', 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'
);
}
);
Expand Down

0 comments on commit 12f048f

Please sign in to comment.