Skip to content

Commit 3db870e

Browse files
committed
add some tests
1 parent 48b208d commit 3db870e

5 files changed

+96
-2
lines changed

packages/button/src/vaadin-button-base.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export const buttonStyles = css`
1919
display: none !important;
2020
}
2121
22-
:host([disabled][tabindex='-1']) {
23-
pointer-events: none;
22+
:host([disabled]) {
23+
pointer-events: var(--_vaadin-button-disabled-pointer-events, none);
2424
}
2525
2626
/* Aligns the button with form fields when placed on the same line.

packages/button/src/vaadin-button-mixin.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ export const ButtonMixin = (superClass) =>
6464
if (!this.hasAttribute('role')) {
6565
this.setAttribute('role', 'button');
6666
}
67+
68+
if (this._shouldAllowFocusWhenDisabled()) {
69+
this.style.setProperty('--_vaadin-button-disabled-pointer-events', 'auto');
70+
}
6771
}
6872

6973
/**
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import './not-animated-styles.js';
2+
import '../theme/lumo/vaadin-lit-menu-bar.js';
3+
import './menu-bar.common.js';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import './not-animated-styles.js';
2+
import '../vaadin-menu-bar.js';
3+
import './focusable-disabled-buttons.common.js';
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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

Comments
 (0)