|
| 1 | +import { expect } from '@vaadin/chai-plugins'; |
| 2 | +import { fixtureSync, middleOfNode, nextRender } from '@vaadin/testing-helpers'; |
| 3 | +import { resetMouse, sendKeys, sendMouse } from '@web/test-runner-commands'; |
| 4 | + |
| 5 | +describe('focusable disabled buttons', () => { |
| 6 | + let menuBar, buttons; |
| 7 | + |
| 8 | + before(() => { |
| 9 | + window.Vaadin.featureFlags ??= {}; |
| 10 | + window.Vaadin.featureFlags.focusableDisabledComponents = true; |
| 11 | + }); |
| 12 | + |
| 13 | + after(() => { |
| 14 | + window.Vaadin.featureFlags.focusableDisabledComponents = false; |
| 15 | + }); |
| 16 | + |
| 17 | + beforeEach(async () => { |
| 18 | + menuBar = fixtureSync('<vaadin-menu-bar></vaadin-menu-bar>'); |
| 19 | + menuBar.items = [ |
| 20 | + { text: 'Item 0' }, |
| 21 | + { text: 'Item 1', disabled: true, children: [{ text: 'SubItem 0' }] }, |
| 22 | + { text: 'Item 2' }, |
| 23 | + ]; |
| 24 | + await nextRender(menuBar); |
| 25 | + buttons = menuBar._buttons; |
| 26 | + }); |
| 27 | + |
| 28 | + afterEach(async () => { |
| 29 | + await resetMouse(); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should not open sub-menu on disabled button click', async () => { |
| 33 | + const { x, y } = middleOfNode(buttons[1]); |
| 34 | + await sendMouse({ type: 'click', position: [Math.floor(x), Math.floor(y)] }); |
| 35 | + expect(buttons[1].hasAttribute('expanded')).to.be.false; |
| 36 | + }); |
| 37 | + |
| 38 | + it('should not open sub-menu on disabled button hover', async () => { |
| 39 | + menuBar.openOnHover = true; |
| 40 | + const { x, y } = middleOfNode(buttons[1]); |
| 41 | + await sendMouse({ type: 'move', position: [Math.floor(x), Math.floor(y)] }); |
| 42 | + expect(buttons[1].hasAttribute('expanded')).to.be.false; |
| 43 | + }); |
| 44 | + |
| 45 | + it('should include disabled buttons in arrow key navigation', async () => { |
| 46 | + await sendKeys({ press: 'Tab' }); |
| 47 | + expect(document.activeElement).to.equal(buttons[0]); |
| 48 | + |
| 49 | + await sendKeys({ press: 'ArrowRight' }); |
| 50 | + expect(document.activeElement).to.equal(buttons[1]); |
| 51 | + |
| 52 | + await sendKeys({ press: 'ArrowRight' }); |
| 53 | + expect(document.activeElement).to.equal(buttons[2]); |
| 54 | + |
| 55 | + await sendKeys({ press: 'ArrowLeft' }); |
| 56 | + expect(document.activeElement).to.equal(buttons[1]); |
| 57 | + |
| 58 | + await sendKeys({ press: 'ArrowLeft' }); |
| 59 | + expect(document.activeElement).to.equal(buttons[0]); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should include disabled buttons in Tab navigation', async () => { |
| 63 | + menuBar.tabNavigation = true; |
| 64 | + |
| 65 | + await sendKeys({ press: 'Tab' }); |
| 66 | + expect(document.activeElement).to.equal(buttons[0]); |
| 67 | + |
| 68 | + await sendKeys({ press: 'Tab' }); |
| 69 | + expect(document.activeElement).to.equal(buttons[1]); |
| 70 | + |
| 71 | + await sendKeys({ press: 'Tab' }); |
| 72 | + expect(document.activeElement).to.equal(buttons[2]); |
| 73 | + |
| 74 | + await sendKeys({ down: 'Shift' }); |
| 75 | + await sendKeys({ press: 'Tab' }); |
| 76 | + await sendKeys({ up: 'Shift' }); |
| 77 | + expect(document.activeElement).to.equal(buttons[1]); |
| 78 | + |
| 79 | + await sendKeys({ down: 'Shift' }); |
| 80 | + await sendKeys({ press: 'Tab' }); |
| 81 | + await sendKeys({ up: 'Shift' }); |
| 82 | + expect(document.activeElement).to.equal(buttons[0]); |
| 83 | + }); |
| 84 | +}); |
0 commit comments