Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen committed Jan 16, 2025
1 parent 48b208d commit 3db870e
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/button/src/vaadin-button-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export const buttonStyles = css`
display: none !important;
}
:host([disabled][tabindex='-1']) {
pointer-events: none;
:host([disabled]) {
pointer-events: var(--_vaadin-button-disabled-pointer-events, none);
}
/* Aligns the button with form fields when placed on the same line.
Expand Down
4 changes: 4 additions & 0 deletions packages/button/src/vaadin-button-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export const ButtonMixin = (superClass) =>
if (!this.hasAttribute('role')) {
this.setAttribute('role', 'button');
}

if (this._shouldAllowFocusWhenDisabled()) {
this.style.setProperty('--_vaadin-button-disabled-pointer-events', 'auto');
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/menu-bar/test/focusable-disabled-buttons-lit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import './not-animated-styles.js';
import '../theme/lumo/vaadin-lit-menu-bar.js';
import './menu-bar.common.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import './not-animated-styles.js';
import '../vaadin-menu-bar.js';
import './focusable-disabled-buttons.common.js';
84 changes: 84 additions & 0 deletions packages/menu-bar/test/focusable-disabled-buttons.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { expect } from '@vaadin/chai-plugins';
import { fixtureSync, middleOfNode, nextRender } from '@vaadin/testing-helpers';
import { resetMouse, sendKeys, sendMouse } from '@web/test-runner-commands';

describe('focusable disabled buttons', () => {
let menuBar, buttons;

before(() => {
window.Vaadin.featureFlags ??= {};
window.Vaadin.featureFlags.focusableDisabledComponents = true;
});

after(() => {
window.Vaadin.featureFlags.focusableDisabledComponents = false;
});

beforeEach(async () => {
menuBar = fixtureSync('<vaadin-menu-bar></vaadin-menu-bar>');
menuBar.items = [
{ text: 'Item 0' },
{ text: 'Item 1', disabled: true, children: [{ text: 'SubItem 0' }] },
{ text: 'Item 2' },
];
await nextRender(menuBar);
buttons = menuBar._buttons;
});

afterEach(async () => {
await resetMouse();
});

it('should not open sub-menu on disabled button click', async () => {
const { x, y } = middleOfNode(buttons[1]);
await sendMouse({ type: 'click', position: [Math.floor(x), Math.floor(y)] });
expect(buttons[1].hasAttribute('expanded')).to.be.false;
});

it('should not open sub-menu on disabled button hover', async () => {
menuBar.openOnHover = true;
const { x, y } = middleOfNode(buttons[1]);
await sendMouse({ type: 'move', position: [Math.floor(x), Math.floor(y)] });
expect(buttons[1].hasAttribute('expanded')).to.be.false;
});

it('should include disabled buttons in arrow key navigation', async () => {
await sendKeys({ press: 'Tab' });
expect(document.activeElement).to.equal(buttons[0]);

await sendKeys({ press: 'ArrowRight' });
expect(document.activeElement).to.equal(buttons[1]);

await sendKeys({ press: 'ArrowRight' });
expect(document.activeElement).to.equal(buttons[2]);

await sendKeys({ press: 'ArrowLeft' });
expect(document.activeElement).to.equal(buttons[1]);

await sendKeys({ press: 'ArrowLeft' });
expect(document.activeElement).to.equal(buttons[0]);
});

it('should include disabled buttons in Tab navigation', async () => {
menuBar.tabNavigation = true;

await sendKeys({ press: 'Tab' });
expect(document.activeElement).to.equal(buttons[0]);

await sendKeys({ press: 'Tab' });
expect(document.activeElement).to.equal(buttons[1]);

await sendKeys({ press: 'Tab' });
expect(document.activeElement).to.equal(buttons[2]);

await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
expect(document.activeElement).to.equal(buttons[1]);

await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
expect(document.activeElement).to.equal(buttons[0]);
});
});

0 comments on commit 3db870e

Please sign in to comment.