Skip to content

Commit b927e1f

Browse files
authored
fix: announce item label when removing chip with keyboard (#4105)
1 parent 48566fc commit b927e1f

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

‎packages/multi-select-combo-box/src/vaadin-multi-select-combo-box.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,8 @@ class MultiSelectComboBox extends ResizeMixin(InputControlMixin(ThemableMixin(El
762762
const itemsCopy = [...this.selectedItems];
763763
itemsCopy.splice(itemsCopy.indexOf(item), 1);
764764
this.__updateSelection(itemsCopy);
765-
this.__announceItem(item, false, itemsCopy.length);
765+
const itemLabel = this._getItemLabel(item);
766+
this.__announceItem(itemLabel, false, itemsCopy.length);
766767
}
767768

768769
/** @private */

‎packages/multi-select-combo-box/test/accessibility.test.js‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ describe('accessibility', () => {
112112
});
113113

114114
describe('announcements', () => {
115+
const apple = { id: 1, name: 'Apple' };
116+
const banana = { id: 2, name: 'Banana' };
117+
const lemon = { id: 3, name: 'Lemon' };
118+
const orange = { id: 4, name: 'Orange' };
119+
const fruits = [apple, banana, lemon, orange];
115120
let clock, region;
116121

117122
before(() => {
@@ -120,7 +125,9 @@ describe('accessibility', () => {
120125

121126
beforeEach(() => {
122127
comboBox = fixtureSync(`<vaadin-multi-select-combo-box></vaadin-multi-select-combo-box>`);
123-
comboBox.items = ['Apple', 'Banana', 'Lemon', 'Orange'];
128+
comboBox.itemIdPath = 'id';
129+
comboBox.itemLabelPath = 'name';
130+
comboBox.items = fruits;
124131
inputElement = comboBox.inputElement;
125132
clock = sinon.useFakeTimers();
126133
});
@@ -141,7 +148,7 @@ describe('accessibility', () => {
141148
});
142149

143150
it('should announce when deselecting an item', () => {
144-
comboBox.selectedItems = ['Apple', 'Banana', 'Lemon'];
151+
comboBox.selectedItems = [apple, banana, lemon];
145152
inputElement.click();
146153

147154
const item = document.querySelector('vaadin-multi-select-combo-box-item');
@@ -153,7 +160,7 @@ describe('accessibility', () => {
153160
});
154161

155162
it('should announce when clicking clear button', () => {
156-
comboBox.selectedItems = ['Apple', 'Banana', 'Lemon'];
163+
comboBox.selectedItems = [apple, banana, lemon];
157164
comboBox.clearButtonVisible = true;
158165

159166
comboBox.$.clearButton.click();
@@ -164,7 +171,7 @@ describe('accessibility', () => {
164171
});
165172

166173
it('should announce when focusing a chip with keyboard', async () => {
167-
comboBox.selectedItems = ['Apple'];
174+
comboBox.selectedItems = [apple];
168175

169176
inputElement.focus();
170177
await sendKeys({ press: 'Backspace' });
@@ -173,5 +180,17 @@ describe('accessibility', () => {
173180

174181
expect(region.textContent).to.equal('Apple focused. Press Backspace to remove');
175182
});
183+
184+
it('should announce when removing a chip with keyboard', async () => {
185+
comboBox.selectedItems = [apple];
186+
187+
inputElement.focus();
188+
await sendKeys({ press: 'Backspace' });
189+
await sendKeys({ press: 'Backspace' });
190+
191+
clock.tick(150);
192+
193+
expect(region.textContent).to.equal('Apple removed from selection 0 items selected');
194+
});
176195
});
177196
});

0 commit comments

Comments
 (0)