|
1 | 1 | import { expect } from '@vaadin/chai-plugins';
|
2 | 2 | import { sendKeys } from '@vaadin/test-runner-commands';
|
3 |
| -import { defineLit, fixtureSync } from '@vaadin/testing-helpers'; |
| 3 | +import { defineLit, fixtureSync, mousedown } from '@vaadin/testing-helpers'; |
4 | 4 | import sinon from 'sinon';
|
5 | 5 | import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
|
6 | 6 | import { FocusTrapController } from '../src/focus-trap-controller.js';
|
@@ -95,6 +95,23 @@ describe('FocusTrapController', () => {
|
95 | 95 | expect(document.activeElement).to.equal(input);
|
96 | 96 | });
|
97 | 97 |
|
| 98 | + it('should use focusVisible: false when focusing the first focusable element if keyboard not active', () => { |
| 99 | + const input = trap.querySelector('#trap-input-1'); |
| 100 | + const spy = sinon.spy(input, 'focus'); |
| 101 | + mousedown(document.body); |
| 102 | + controller.trapFocus(trap); |
| 103 | + expect(spy.firstCall.args[0]).to.deep.equal({ focusVisible: false }); |
| 104 | + }); |
| 105 | + |
| 106 | + it('should use focusVisible: true when focusing the first focusable element if keyboard active', async () => { |
| 107 | + // Mimic opening the overlay on key press |
| 108 | + await sendKeys({ press: 'Enter' }); |
| 109 | + const input = trap.querySelector('#trap-input-1'); |
| 110 | + const spy = sinon.spy(input, 'focus'); |
| 111 | + controller.trapFocus(trap); |
| 112 | + expect(spy.firstCall.args[0]).to.deep.equal({ focusVisible: true }); |
| 113 | + }); |
| 114 | + |
98 | 115 | describe('no focusable elements', () => {
|
99 | 116 | beforeEach(() => {
|
100 | 117 | trap.querySelectorAll('input, textarea').forEach((input) => {
|
@@ -193,6 +210,12 @@ describe('FocusTrapController', () => {
|
193 | 210 | await tab();
|
194 | 211 | expect(spy.calledOnce).to.be.false;
|
195 | 212 | });
|
| 213 | + |
| 214 | + it('should focus element with focusVisible on Tab', async () => { |
| 215 | + const spy = sinon.spy(trapInput2, 'focus'); |
| 216 | + await tab(); |
| 217 | + expect(spy.firstCall.args[0]).to.deep.equal({ focusVisible: true }); |
| 218 | + }); |
196 | 219 | });
|
197 | 220 |
|
198 | 221 | describe('custom tab order', () => {
|
|
0 commit comments