|
3 | 3 | * SPDX-License-Identifier: MPL-2.0
|
4 | 4 | */
|
5 | 5 |
|
6 |
| -import { module, test } from 'qunit'; |
| 6 | +import { module, test, skip } from 'qunit'; |
7 | 7 | import { setupRenderingTest } from 'ember-qunit';
|
8 | 8 | import {
|
9 | 9 | click,
|
@@ -194,6 +194,63 @@ module('Integration | Component | hds/modal/index', function (hooks) {
|
194 | 194 | assert.dom('button.hds-modal__dismiss').isFocused();
|
195 | 195 | });
|
196 | 196 |
|
| 197 | + test('it returns focus to the element that initiated the open event, if is still in the DOM', async function (assert) { |
| 198 | + await render( |
| 199 | + hbs`<button id="test-button" type="button" {{on "click" (set this "showModal" true)}}>open modal</button> |
| 200 | + {{#if this.showModal}} |
| 201 | + <Hds::Modal id="test-modal" as |M|> |
| 202 | + <M.Header>Title</M.Header> |
| 203 | + </Hds::Modal> |
| 204 | + {{/if}} |
| 205 | + ` |
| 206 | + ); |
| 207 | + await click('#test-button'); |
| 208 | + assert.true(this.showModal); |
| 209 | + await click('button.hds-modal__dismiss'); |
| 210 | + assert.dom('#test-button').isFocused(); |
| 211 | + }); |
| 212 | + |
| 213 | + // not sure how to reach the `body` element, it says "body is not a valid root element" |
| 214 | + skip('it returns focus to the `body` element, if the one that initiated the open event not anymore in the DOM', async function (assert) { |
| 215 | + await render( |
| 216 | + hbs`<Hds::Dropdown as |D|> |
| 217 | + <D.ToggleButton id="test-toggle" @text="open modal" /> |
| 218 | + <D.Interactive id="test-interactive" {{on "click" (set this "showModal" true)}}>open modal</D.Interactive> |
| 219 | + </Hds::Dropdown> |
| 220 | + {{#if this.showModal}} |
| 221 | + <Hds::Modal id="test-modal" as |M|> |
| 222 | + <M.Header>Title</M.Header> |
| 223 | + </Hds::Modal> |
| 224 | + {{/if}} |
| 225 | + ` |
| 226 | + ); |
| 227 | + await click('#test-toggle'); |
| 228 | + await click('#test-interactive'); |
| 229 | + assert.true(this.showModal); |
| 230 | + await click('button.hds-modal__dismiss'); |
| 231 | + assert.dom('body', 'body').isFocused(); |
| 232 | + }); |
| 233 | + |
| 234 | + test('it returns focus to a specific element if provided via`@returnFocusTo`', async function (assert) { |
| 235 | + await render( |
| 236 | + hbs`<Hds::Dropdown as |D|> |
| 237 | + <D.ToggleButton id="test-toggle" @text="open modal" /> |
| 238 | + <D.Interactive id="test-interactive" {{on "click" (set this "showModal" true)}}>open modal</D.Interactive> |
| 239 | + </Hds::Dropdown> |
| 240 | + {{#if this.showModal}} |
| 241 | + <Hds::Modal id="test-modal" @returnFocusTo="test-toggle" as |M|> |
| 242 | + <M.Header>Title</M.Header> |
| 243 | + </Hds::Modal> |
| 244 | + {{/if}} |
| 245 | + ` |
| 246 | + ); |
| 247 | + await click('#test-toggle'); |
| 248 | + await click('#test-interactive'); |
| 249 | + assert.true(this.showModal); |
| 250 | + await click('button.hds-modal__dismiss'); |
| 251 | + assert.dom('#test-toggle').isFocused(); |
| 252 | + }); |
| 253 | + |
197 | 254 | // CALLBACKS
|
198 | 255 |
|
199 | 256 | test('it should call `onOpen` function if provided', async function (assert) {
|
|
0 commit comments