Skip to content

Commit dd6a0b4

Browse files
author
Kubit
committed
Add aria-controls utilities on OliveMenu component
1 parent 58b4a27 commit dd6a0b4

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

src/components/oliveMenu/__test__/oliveMenu.utils.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ const menuSection: OliveMenuListOptions[] = [
4747

4848
describe('Olive Menu utils', () => {
4949
test('Should get ariaControls', async () => {
50-
expect(getAriaControls(menuSection, 'ariaControls')).toStrictEqual(
51-
'ariaControls0number1 ariaControls1number2'
52-
);
50+
expect(getAriaControls(menuSection, 'ariaControls')).toStrictEqual([
51+
'ariaControls0number1',
52+
'ariaControls1number2',
53+
]);
5354
});
5455
});

src/components/oliveMenu/oliveMenu.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22

3-
import { useEscPressed, useMediaDevice } from '@/hooks';
3+
import { useEscPressedV2, useMediaDevice } from '@/hooks';
44
import { useStyles } from '@/hooks/useStyles/useStyles';
55
import { ErrorBoundary, FallbackComponent } from '@/provider/errorBoundary';
66

@@ -30,7 +30,7 @@ const OliveMenuComponent = React.forwardRef(
3030
onOpenClose?.(false);
3131
}, [open]);
3232

33-
useEscPressed({ execute: handlePressScape, element: innerRef });
33+
useEscPressedV2({ ref: innerRef, onEscPress: handlePressScape });
3434

3535
const handleTriggerClick = e => {
3636
setOpen(!open);

src/components/oliveMenu/oliveMenuStandAlone.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const OliveMenuStandAloneComponent = (
3030

3131
const titleId = actionBottomSheetTitle?.id ?? `${uniqueId}Title`;
3232

33+
const ariaControlIds = getAriaControls(props.sections, ariaControls);
34+
3335
return (
3436
<OliveMenuStyled
3537
ref={ref}
@@ -41,7 +43,7 @@ const OliveMenuStandAloneComponent = (
4143
(props.styles.button?.[props.device]?.size || props.trigger?.size) && (
4244
<ButtonContainer ref={buttonRef} styles={props.styles}>
4345
<Button
44-
aria-controls={props.open ? getAriaControls(props.sections, ariaControls) : undefined}
46+
aria-controls={props.open ? ariaControlIds?.join(' ') : undefined}
4547
aria-expanded={props.open}
4648
dataTestId={`${props.dataTestId}Button`}
4749
size={props.styles.button?.[props.device]?.size}
@@ -93,14 +95,14 @@ const OliveMenuStandAloneComponent = (
9395
<ListOptions
9496
key={section.id}
9597
dataTestId={props.dataTestId}
96-
id={`${ariaControls}${index}${section.id ? `${section.id}` : ''}`}
9798
optionVariant={props.styles.listOptions?.optionVariant as string}
9899
selectedValue={props.selectedValue}
99100
title={{ component: TextComponentType.H6, ...title }}
100101
type={ListOptionsType.NAVIGATION}
101102
variant={props.styles.listOptions?.variant as string}
102103
onOptionClick={props.onOptionClick}
103104
{...section}
105+
id={ariaControlIds?.[index]}
104106
/>
105107
))}
106108
</ListboxStyled>

src/components/oliveMenu/utils/getAriaControls.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import { OliveMenuListOptions } from '../types';
33
export const getAriaControls = (
44
sections: OliveMenuListOptions[] | undefined,
55
ariaControls: string
6-
): string => {
7-
let newAriaControls = '';
8-
sections?.forEach(
9-
(_section, index) =>
10-
(newAriaControls += ` ${ariaControls}${index}${_section.id ? `${_section.id}` : ''}`)
11-
);
12-
return newAriaControls.trimStart();
6+
): string[] | undefined => {
7+
const ariaControlsIds = sections?.map(({ title, ...section }, index) => {
8+
return `${ariaControls}${index}${section.id ? `${section.id}` : ''}`;
9+
});
10+
11+
return ariaControlsIds;
1312
};

0 commit comments

Comments
 (0)