Skip to content

Commit 19cc291

Browse files
author
Kubit
committed
Change roles for options and ListOptions components
1 parent 60aa3fe commit 19cc291

File tree

4 files changed

+11
-19
lines changed

4 files changed

+11
-19
lines changed

src/components/listOptions/__tests__/listOptions.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ describe('ListOptions component', () => {
146146
expect(results).toHaveNoViolations();
147147
});
148148

149-
it('List options with type=NAVIGATION must render a role=presentation', async () => {
149+
it('List options with type=NAVIGATION must render a role=li', async () => {
150150
const { container, getAllByRole } = renderProvider(
151151
<ListOptions {...MOCK} type={ListOptionsType.NAVIGATION} />
152152
);
153-
const options = getAllByRole(ROLES.PRESENTATION);
153+
const options = getAllByRole(ROLES.LISTITEM);
154154
expect(options.length).toBe(2);
155155

156156
const results = await axe(container, {

src/components/listOptions/listOptionsStandAlone.tsx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,9 @@ export const ListOptionsStandAlone = React.forwardRef(
3939
const [focus, setFocus, listEl] = useRoveFocus(props.roveFocus ?? roveFocusProps);
4040
const _id = useId();
4141

42-
React.useImperativeHandle(
43-
ref,
44-
() => {
45-
return listEl.current as HTMLDivElement;
46-
},
47-
[]
48-
);
42+
React.useImperativeHandle(ref, () => {
43+
return listEl.current as HTMLDivElement;
44+
}, []);
4945

5046
const id = props.id ?? _id;
5147
const isSelection = type === ListOptionsType.SELECTION;
@@ -73,7 +69,7 @@ export const ListOptionsStandAlone = React.forwardRef(
7369
aria-labelledby={props.optionsContainerArias?.['aria-labelledby']}
7470
as={'ul'}
7571
id={id}
76-
role={isSelection ? ROLES.LISTBOX : ROLES.MENU}
72+
role={isSelection ? ROLES.LISTBOX : undefined}
7773
styles={props.styles}
7874
>
7975
{props.options.map((option, index) => {
@@ -93,7 +89,7 @@ export const ListOptionsStandAlone = React.forwardRef(
9389
focus={focus === index}
9490
labelCharsHighlighted={props.charsHighlighted}
9591
multiSelect={props.multiSelect}
96-
role={isSelection ? ROLES.OPTION : ROLES.MENUITEM}
92+
role={isSelection ? ROLES.OPTION : undefined}
9793
selected={selected}
9894
tabIndex={isNavigation ? 0 : -1}
9995
variant={getOptionVariant(
@@ -116,11 +112,7 @@ export const ListOptionsStandAlone = React.forwardRef(
116112
/>
117113
);
118114
if (type === ListOptionsType.NAVIGATION) {
119-
return (
120-
<li key={`${id}LiOption${index}`} role="presentation">
121-
{optionComponent}
122-
</li>
123-
);
115+
return <li key={`${id}LiOption${index}`}>{optionComponent}</li>;
124116
}
125117
return optionComponent;
126118
})}

src/components/listOptions/types/listOptions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ReactNode } from 'react';
22

33
import { IElementOrIcon } from '@/components/elementOrIcon';
4-
import { IOption } from '@/components/option';
4+
import { IOption, OptionSublabelType } from '@/components/option';
55
import { IText } from '@/components/text';
66
import { UseRoveFocusProps } from '@/hooks/useRoveFocus/useRoveFocus';
77
import { CustomTokenTypes } from '@/types';
@@ -17,6 +17,7 @@ export type ListOptionsOptionType = Omit<IOption<string>, 'children' | 'variant'
1717
variant?: string;
1818
highlighted?: boolean;
1919
value?: string | number;
20+
sublabel?: OptionSublabelType;
2021
};
2122

2223
export type OptionsContainerAriasType = Pick<

src/components/oliveMenu/__test__/oliveMenu.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { axe } from 'jest-axe';
55

66
import { renderProvider } from '@/tests/renderProvider/renderProvider.utility';
77
import { windowMatchMedia } from '@/tests/windowMatchMedia';
8-
import { ROLES } from '@/types';
98

109
import { OliveMenu } from '../oliveMenu';
1110
import { IOliveMenu, OliveMenuListOptions } from '../types';
@@ -116,7 +115,7 @@ describe('OliveMenu component', () => {
116115
const openButton = screen.getAllByText('Options');
117116
fireEvent.click(openButton[0]);
118117

119-
const option = screen.getAllByRole(ROLES.MENUITEM, { name: 'option 1' })[0];
118+
const option = screen.getAllByText('option 1')[0];
120119
fireEvent.click(option);
121120

122121
expect(onOptionClickMock).toHaveBeenCalled();

0 commit comments

Comments
 (0)