Skip to content

Commit

Permalink
Menu: remove excess role attribute when menu is in adaptivity mode (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nikkithelegendarypokemonster authored Sep 25, 2024
1 parent 3f2bdc8 commit 147725a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions e2e/testcafe-devextreme/tests/accessibility/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ const items: Item[] = [
const options: Options<Properties> = {
items: [items],
disabled: [true, false],
width: [400, 1024],
orientation: ['horizontal', 'vertical'],
adaptivityEnabled: [true, false],
};

const created = async (t: TestController, optionConfiguration): Promise<void> => {
Expand Down
7 changes: 7 additions & 0 deletions packages/devextreme/js/__internal/ui/menu/m_menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ class Menu extends MenuBase {
this.setAria('role', 'menubar');
}

_setAriaRole(state: boolean): void {
const role = this._isAdaptivityEnabled() && state ? undefined : 'menubar';
this.setAria({ role });
}

_render(): void {
super._render();
this._initAdaptivity();
Expand Down Expand Up @@ -346,6 +351,8 @@ class Menu extends MenuBase {
this._overlay && this._toggleTreeView(state);
}

this._setAriaRole(state);

$menuItemsContainer.toggle(!state);
$adaptiveElements.toggle(state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2970,6 +2970,53 @@ QUnit.module('adaptivity: render', {
fx.off = false;
}
}, () => {
QUnit.test('Adds "menubar" role when menu is wider than item', function(assert) {
new Menu(this.$element, {
items: this.items,
adaptivityEnabled: true,
width: 1000
});

assert.strictEqual(this.$element.attr('role'), 'menubar');
});

QUnit.test('No role added when menu is smaller than item', function(assert) {
new Menu(this.$element, {
items: this.items,
adaptivityEnabled: true,
width: 20
});

assert.strictEqual(this.$element.attr('role'), undefined);
});

QUnit.test('Adds "menu bar" role when menu width is increased at runtime', function(assert) {
const instance = new Menu(this.$element, {
items: this.items,
adaptivityEnabled: true,
width: 20
});

assert.strictEqual(this.$element.attr('role'), undefined);

instance.option('width', 1000);

assert.strictEqual(this.$element.attr('role'), 'menubar');
});

QUnit.test('Removes role when menu width is decreased at runtime', function(assert) {
const instance = new Menu(this.$element, {
items: this.items,
adaptivityEnabled: true,
width: 1200
});
assert.strictEqual(this.$element.attr('role'), 'menubar');

instance.option('width', 20);

assert.strictEqual(this.$element.attr('role'), undefined);
});

QUnit.test('Hamburger button should be rendered', function(assert) {
new Menu(this.$element, {
items: this.items,
Expand Down

0 comments on commit 147725a

Please sign in to comment.