Skip to content

Commit 9e0ceb8

Browse files
marker-daomarker dao ®
and
marker dao ®
committed
List: Set item aria-label to make CheckBox/RadioGroup mock label not readable (T1248422)
Co-authored-by: marker dao ® <youdontknow@marker-dao.eth>
1 parent 2932f32 commit 9e0ceb8

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

packages/devextreme/js/__internal/ui/list/m_list.edit.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,23 @@ const ListEdit = ListBase.inherit({
191191
this._editProvider.afterItemsRendered();
192192
},
193193

194+
_renderItem(index, itemData, $container, $itemToReplace) {
195+
const { showSelectionControls, selectionMode } = this.option();
196+
const $itemFrame = this.callBase(index, itemData, $container, $itemToReplace);
197+
198+
if (showSelectionControls && selectionMode !== 'none') {
199+
this._updateItemAriaLabel($itemFrame, itemData);
200+
}
201+
202+
return $itemFrame;
203+
},
204+
205+
_updateItemAriaLabel($itemFrame, itemData) {
206+
const label = this._displayGetter?.(itemData) ?? itemData?.text ?? itemData;
207+
208+
this.setAria('label', label, $itemFrame);
209+
},
210+
194211
_selectedItemClass() {
195212
return LIST_ITEM_SELECTED_CLASS;
196213
},

packages/devextreme/testing/tests/DevExpress.ui.widgets/list.markup.tests.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,73 @@ QUnit.module('decorators markup', {}, () => {
491491
assert.notStrictEqual(window.getComputedStyle($deleteToggleIcon).backgroundImage, 'none', 'background image is defined');
492492
});
493493

494+
QUnit.module('list item aria-label should be equal to item text (T1248422)', {
495+
beforeEach: function() {
496+
const init = (options = {}) => {
497+
this.$element = $('#list').dxList(options);
498+
this.instance = this.$element.dxList('instance');
499+
};
500+
501+
init();
502+
503+
this.reinit = (options) => {
504+
this.instance.dispose();
505+
506+
init(options);
507+
};
508+
509+
this.getItem = () => this.$element.find(`.${LIST_ITEM_CLASS}`).eq(0);
510+
511+
this.checkAriaLabel = (assert, updatedItems) => {
512+
const { selectionMode, showSelectionControls } = this.instance.option();
513+
const isSelectionActive = selectionMode !== 'none' && showSelectionControls;
514+
515+
assert.strictEqual(this.getItem().attr('aria-label'), isSelectionActive ? 'item 1' : undefined, 'aria-label is correct on init');
516+
517+
this.instance.option({ items: updatedItems });
518+
519+
assert.strictEqual(this.getItem().attr('aria-label'), isSelectionActive ? 'item 2' : undefined, 'aria-label is correct if items were changed in runtime');
520+
};
521+
},
522+
}, () => {
523+
[true, false].forEach(showSelectionControls => {
524+
[ 'multiple', 'single', 'all', 'none' ].forEach(selectionMode => {
525+
QUnit.test(`showSelectionControls is ${showSelectionControls}, selectionMode is ${selectionMode}, items is string, displayExpr is not specified`, function(assert) {
526+
this.reinit({
527+
showSelectionControls,
528+
selectionMode,
529+
items: ['item 1'],
530+
displayExpr: null,
531+
});
532+
533+
this.checkAriaLabel(assert, ['item 2']);
534+
});
535+
536+
QUnit.test(`showSelectionControls is ${showSelectionControls}, selectionMode is ${selectionMode}, items is object, displayExpr is not specified`, function(assert) {
537+
this.reinit({
538+
showSelectionControls,
539+
selectionMode,
540+
items: [{ text: 'item 1' }],
541+
displayExpr: null,
542+
});
543+
544+
this.checkAriaLabel(assert, [{ text: 'item 2' }]);
545+
});
546+
547+
QUnit.test(`showSelectionControls is ${showSelectionControls}, selectionMode is ${selectionMode}, items is object, displayExpr is specified`, function(assert) {
548+
this.reinit({
549+
showSelectionControls,
550+
selectionMode,
551+
items: [{ custom: 'item 1' }],
552+
displayExpr: 'custom',
553+
});
554+
555+
this.checkAriaLabel(assert, [{ custom: 'item 2' }]);
556+
});
557+
});
558+
});
559+
});
560+
494561
QUnit.test('list item markup, item select decorator', function(assert) {
495562
const $list = $($('#templated-list').dxList({
496563
items: ['0'],

0 commit comments

Comments
 (0)