diff options
author | louismaxime.piton <louismaxime.piton@orange.com> | 2022-03-16 19:51:43 +0300 |
---|---|---|
committer | GeoSot <geo.sotis@gmail.com> | 2022-03-19 02:43:43 +0300 |
commit | 0e5cd69c02ae07b0ddb1656ef9b7eac5f9aca2e7 (patch) | |
tree | 03a33dd5bdfd6b73c9aad7b98cbb573e5106f3c5 /js/tests | |
parent | 88bd287b27c8097ca02347038dbb0b321b71d169 (diff) |
No propagating escape event in an open dropdown.
Diffstat (limited to 'js/tests')
-rw-r--r-- | js/tests/unit/dropdown.spec.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/js/tests/unit/dropdown.spec.js b/js/tests/unit/dropdown.spec.js index ef97fc71bc..bde5697d04 100644 --- a/js/tests/unit/dropdown.spec.js +++ b/js/tests/unit/dropdown.spec.js @@ -1943,6 +1943,41 @@ describe('Dropdown', () => { }) }) + it('should not propagate escape key events if dropdown is open', () => { + return new Promise(resolve => { + fixtureEl.innerHTML = [ + '<div class="parent">', + ' <div class="dropdown">', + ' <button class="btn dropdown-toggle" data-bs-toggle="dropdown">Dropdown</button>', + ' <div class="dropdown-menu">', + ' <a class="dropdown-item" href="#">Some Item</a>', + ' </div>', + ' </div>', + '</div>' + ].join('') + + const parent = fixtureEl.querySelector('.parent') + const toggle = fixtureEl.querySelector('[data-bs-toggle="dropdown"]') + + const parentKeyHandler = jasmine.createSpy('parentKeyHandler') + + parent.addEventListener('keydown', parentKeyHandler) + parent.addEventListener('keyup', () => { + expect(parentKeyHandler).not.toHaveBeenCalled() + resolve() + }) + + const keydownEscape = createEvent('keydown', { bubbles: true }) + keydownEscape.key = 'Escape' + const keyupEscape = createEvent('keyup', { bubbles: true }) + keyupEscape.key = 'Escape' + + toggle.click() + toggle.dispatchEvent(keydownEscape) + toggle.dispatchEvent(keyupEscape) + }) + }) + it('should close dropdown using `escape` button, and return focus to its trigger', () => { return new Promise(resolve => { fixtureEl.innerHTML = [ |