Skip to content

Commit fc6c20d

Browse files
committed
feat(SelectDialog): add SR announcement for number of selected items
1 parent 5c7dab6 commit fc6c20d

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

packages/main/src/components/SelectDialog/SelectDialog.cy.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,24 @@ describe('SelectDialog', () => {
295295
cy.findByTestId('confirmBtn').should('be.visible').and('have.attr', 'disabled');
296296
cy.findByTestId('confirmBtn').should('have.attr', 'design', 'Emphasized');
297297
});
298+
299+
it('invisible messaging', () => {
300+
cy.mount(
301+
<SelectDialog open selectionMode={ListSelectionMode.Multiple}>
302+
<ListItemStandard text={'ListItem 1'} data-testid="1" />
303+
<ListItemStandard text={'ListItem 2'} data-testid="2" />
304+
<ListItemStandard text={'ListItem 3'} data-testid="3" />
305+
<ListItemStandard text={'ListItem 4'} data-testid="4" />
306+
</SelectDialog>,
307+
);
308+
cy.findByTestId('1').click();
309+
cy.findByText('Selected Items 1').should('exist');
310+
cy.findByTestId('1').click();
311+
cy.findByText('Selected Items 1').should('not.exist');
312+
cy.findByTestId('1').click();
313+
cy.findByTestId('2').click();
314+
cy.findByTestId('3').click();
315+
cy.findByTestId('4').click();
316+
cy.findByText('Selected Items 4').should('exist');
317+
});
298318
});

packages/main/src/components/SelectDialog/index.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ import ButtonDesign from '@ui5/webcomponents/dist/types/ButtonDesign.js';
44
import IconMode from '@ui5/webcomponents/dist/types/IconMode.js';
55
import InputType from '@ui5/webcomponents/dist/types/InputType.js';
66
import ListSelectionMode from '@ui5/webcomponents/dist/types/ListSelectionMode.js';
7+
import InvisibleMessageMode from '@ui5/webcomponents-base/dist/types/InvisibleMessageMode.js';
8+
import announce from '@ui5/webcomponents-base/dist/util/InvisibleMessage.js';
79
import iconDecline from '@ui5/webcomponents-icons/dist/decline.js';
810
import iconSearch from '@ui5/webcomponents-icons/dist/search.js';
911
import { enrichEventWithDetails, useI18nBundle, useStylesheet, useSyncRef } from '@ui5/webcomponents-react-base';
1012
import { clsx } from 'clsx';
1113
import type { ReactNode } from 'react';
1214
import { forwardRef, useEffect, useState } from 'react';
13-
import { CANCEL, CLEAR, RESET, SEARCH, SELECT, SELECTED } from '../../i18n/i18n-defaults.js';
15+
// todo: remove comment once translations are available
16+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
17+
import { CANCEL, CLEAR, RESET, SEARCH, SELECT, SELECTED, SELECTED_ITEMS } from '../../i18n/i18n-defaults.js';
1418
import { Button, Dialog, FlexBox, FlexBoxAlignItems, Icon, Input, List, Text, Title } from '../../index.js';
1519
import type { Ui5CustomEvent } from '../../types/index.js';
1620
import type {
@@ -218,12 +222,18 @@ const SelectDialog = forwardRef<DialogDomRef, SelectDialogPropTypes>((props, ref
218222
setSearchValue('');
219223
};
220224

221-
const handleSelectionChange = (e) => {
225+
const handleSelectionChange: ListPropTypes['onSelectionChange'] = (e) => {
226+
const { selectedItems } = e.detail;
222227
if (typeof listProps?.onSelectionChange === 'function') {
223228
listProps.onSelectionChange(e);
224229
}
225230
if (selectionMode === ListSelectionMode.Multiple) {
226-
setSelectedItems(e.detail.selectedItems);
231+
setSelectedItems(selectedItems);
232+
if (selectedItems.length) {
233+
announce('Selected Items ' + selectedItems.length, InvisibleMessageMode.Polite);
234+
//todo: uncomment this, once translations are available
235+
// announce(i18nBundle.getText(SELECTED_ITEMS, selectedItems.length), InvisibleMessageMode.Polite);
236+
}
227237
} else {
228238
if (typeof onConfirm === 'function') {
229239
onConfirm(e);

packages/main/src/i18n/messagebundle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,5 +378,7 @@ HAS_DETAILS=Has Details
378378
#XACT: Message Item counter label
379379
COUNTER=Counter
380380

381+
#ACT: Screen reader announcement text for selection in the SelectDialog component when multi-selection mode is active. The placeholder represents a number.
382+
SELECTED_ITEMS=Selected Items {0}
381383

382384

0 commit comments

Comments
 (0)