Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Column, Row } from '@js/ui/data_grid';
import DataGrid from '@js/ui/data_grid';
import { DataGridBaseModel } from '@ts/grids/grid_core/__tests__/__mock__/model/data_grid_base';
import { DropDownButtonModel } from '@ts/ui/drop_down_editor/__tests__/__mock__/model/drop_down_button';

export class DataGridModel extends DataGridBaseModel<DataGrid> {
protected NAME = 'dxDataGrid';
Expand All @@ -9,6 +10,10 @@ export class DataGridModel extends DataGridBaseModel<DataGrid> {
return DataGrid.getInstance(this.root) as DataGrid;
}

public getExportButton(): DropDownButtonModel {
return new DropDownButtonModel(this.root.querySelector<HTMLElement>(`.${this.addWidgetPrefix('export-button')}`));
}

public apiGetVisibleColumns(headerLevel?: number): Column[] {
if (headerLevel === undefined) {
return this.getInstance().getVisibleColumns();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
afterEach, beforeEach, describe, expect, it,
} from '@jest/globals';

import {
afterTest,
beforeTest,
createDataGrid,
} from '../../../grid_core/__tests__/__mock__/helpers/utils';

const DATA = [
{ id: 1, value: 'a' },
{ id: 2, value: 'b' },
];

describe('Export button (T1337649)', () => {
beforeEach(beforeTest);
afterEach(afterTest);

it('should be named after export.texts.exportTo when several formats are offered', async () => {
const { component } = await createDataGrid({
dataSource: DATA,
export: {
enabled: true,
formats: ['xlsx', 'pdf'],
texts: { exportTo: 'Download the grid' },
},
});

expect(component.getExportButton().getButtonElement()?.getAttribute('aria-label')).toBe('Download the grid');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import {
afterEach, describe, expect, it,
} from '@jest/globals';
import $ from '@js/core/renderer';
import type { Properties } from '@js/ui/drop_down_button';
import DropDownButton from '@js/ui/drop_down_button';

import { DropDownButtonModel } from '../drop_down_editor/__tests__/__mock__/model/drop_down_button';

const HINT = 'Exporting/Printing';

const instances: DropDownButton[] = [];

const createDropDownButton = (
options: Partial<Properties> = {},
): { instance: DropDownButton; model: DropDownButtonModel } => {
const $element = $('<div>').appendTo(document.body);

const instance = new DropDownButton($element.get(0) as HTMLElement, options);

instances.push(instance);

return { instance, model: new DropDownButtonModel($element.get(0) as HTMLElement) };
};

describe('DropDownButton', () => {
afterEach(() => {
instances.forEach((instance) => instance.dispose());
instances.length = 0;
document.body.innerHTML = '';
});

describe('action button aria-label (T1337649)', () => {
it('should be taken from the hint when the text is empty', () => {
const { model } = createDropDownButton({ icon: 'export', hint: HINT });

expect(model.getButtonElement()?.getAttribute('aria-label')).toBe(HINT);
});

it('should stay "dropdownbutton" when the hint is an empty string', () => {
const { model } = createDropDownButton({ icon: 'export', hint: '' });

expect(model.getButtonElement()?.getAttribute('aria-label')).toBe('dropdownbutton');
});

it('should stay "dropdownbutton" when the hint contains only spaces', () => {
const { model } = createDropDownButton({ icon: 'export', hint: ' ' });

expect(model.getButtonElement()?.getAttribute('aria-label')).toBe('dropdownbutton');
});

it('should stay the hint while the drop-down list is opened and after it is closed', async () => {
const { instance, model } = createDropDownButton({ icon: 'export', hint: HINT });

await instance.open();

expect(model.getButtonElement()?.getAttribute('aria-expanded')).toBe('true');
expect(model.getButtonElement()?.getAttribute('aria-label')).toBe(HINT);

await instance.close();

expect(model.getButtonElement()?.getAttribute('aria-expanded')).toBe('false');
expect(model.getButtonElement()?.getAttribute('aria-label')).toBe(HINT);
});

it('should follow a hint change at runtime', () => {
const { instance, model } = createDropDownButton({ icon: 'export', hint: HINT });

instance.option('hint', 'Print or export');

expect(model.getButtonElement()?.getAttribute('aria-label')).toBe('Print or export');
});

it('should follow a hint change while the drop-down list is opened and keep it expanded', async () => {
const { instance, model } = createDropDownButton({ icon: 'export', hint: HINT });

await instance.open();

expect(model.getButtonElement()?.getAttribute('aria-expanded')).toBe('true');

instance.option('hint', 'Print or export');

expect(model.getButtonElement()?.getAttribute('aria-label')).toBe('Print or export');
expect(model.getButtonElement()?.getAttribute('aria-expanded')).toBe('true');
});

it('should return to "dropdownbutton" when the hint is cleared at runtime', () => {
const { instance, model } = createDropDownButton({ icon: 'export', hint: HINT });

expect(model.getButtonElement()?.getAttribute('aria-label')).toBe(HINT);

instance.option('hint', '');

expect(model.getButtonElement()?.getAttribute('aria-label')).toBe('dropdownbutton');
});

it('should be the visible text when both the text and the hint are set', () => {
const { model } = createDropDownButton({ icon: 'export', text: 'Export', hint: HINT });

expect(model.getButtonElement()?.getAttribute('aria-label')).toBe('Export');
});
});

describe('hint tooltip (T1337649)', () => {
it('should follow a hint change at runtime', () => {
const { instance, model } = createDropDownButton({ icon: 'export', hint: HINT });

expect(model.getElement()?.getAttribute('title')).toBe(HINT);

instance.option('hint', 'Print or export');

expect(model.getElement()?.getAttribute('title')).toBe('Print or export');
});
});
});
12 changes: 10 additions & 2 deletions packages/devextreme/js/__internal/ui/drop_down_button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { getPublicElement } from '@ts/core/m_element';
import { Guid } from '@ts/core/m_guid';
import { FunctionTemplate } from '@ts/core/templates/m_function_template';
import { ensureDefined } from '@ts/core/utils/m_common';
import { isEmpty } from '@ts/core/utils/m_string';
import { isDefined, isObject, isPlainObject } from '@ts/core/utils/m_type';
import type { OptionChanged } from '@ts/core/widget/types';
import Widget from '@ts/core/widget/widget';
Expand Down Expand Up @@ -605,9 +606,10 @@ class DropDownButton extends Widget<DropDownButtonProperties> {
haspopup: 'listbox',
};
const firstButtonAria: AriaAttributes = {};
const { text, hint } = this.option();

if (!this.option('text')) {
firstButtonAria.label = 'dropdownbutton';
if (!text) {
firstButtonAria.label = isEmpty(hint) ? 'dropdownbutton' : hint;
}

this._getButtons().each((index, $button) => {
Expand Down Expand Up @@ -896,6 +898,12 @@ class DropDownButton extends Widget<DropDownButtonProperties> {
case 'template':
this._renderButtonGroup();
break;
case 'hint': {
super._optionChanged(args);
const { opened } = this.option();
this._updateAriaAttributes(opened ?? false);
break;
}
case '_cached_buttonGroupOptions':
case '_cached_dropDownOptions':
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,20 @@ QUnit.module('Toolbar', moduleConfig, () => {
assert.equal($dropDownButton.attr('title'), 'Thumbnails View', 'Thumbnails View');
});

test('itemView dropDownButton is named after the current view mode (T1337649)', function(assert) {
createFileManager(false);
this.clock.tick(400);

const getViewSwitcherLabel = () => this.wrapper.getToolbarDropDownButton().find(`.${Consts.BUTTON_CLASS}`).attr('aria-label');

assert.strictEqual(getViewSwitcherLabel(), 'Details View', 'details view');

this.wrapper.getInstance().option('itemView.mode', 'thumbnails');
this.clock.tick(400);

assert.strictEqual(getViewSwitcherLabel(), 'Thumbnails View', 'thumbnails view');
});

test('Raise the ToolbarItemClick event on default toolbar', function(assert) {
createFileManager(false);
this.clock.tick(400);
Expand Down
Loading