File tree Expand file tree Collapse file tree 4 files changed +16
-14
lines changed Expand file tree Collapse file tree 4 files changed +16
-14
lines changed Original file line number Diff line number Diff line change @@ -47,8 +47,9 @@ const menuSection: OliveMenuListOptions[] = [
47
47
48
48
describe ( 'Olive Menu utils' , ( ) => {
49
49
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
+ ] ) ;
53
54
} ) ;
54
55
} ) ;
Original file line number Diff line number Diff line change 1
1
import * as React from 'react' ;
2
2
3
- import { useEscPressed , useMediaDevice } from '@/hooks' ;
3
+ import { useEscPressedV2 , useMediaDevice } from '@/hooks' ;
4
4
import { useStyles } from '@/hooks/useStyles/useStyles' ;
5
5
import { ErrorBoundary , FallbackComponent } from '@/provider/errorBoundary' ;
6
6
@@ -30,7 +30,7 @@ const OliveMenuComponent = React.forwardRef(
30
30
onOpenClose ?.( false ) ;
31
31
} , [ open ] ) ;
32
32
33
- useEscPressed ( { execute : handlePressScape , element : innerRef } ) ;
33
+ useEscPressedV2 ( { ref : innerRef , onEscPress : handlePressScape } ) ;
34
34
35
35
const handleTriggerClick = e => {
36
36
setOpen ( ! open ) ;
Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ const OliveMenuStandAloneComponent = (
30
30
31
31
const titleId = actionBottomSheetTitle ?. id ?? `${ uniqueId } Title` ;
32
32
33
+ const ariaControlIds = getAriaControls ( props . sections , ariaControls ) ;
34
+
33
35
return (
34
36
< OliveMenuStyled
35
37
ref = { ref }
@@ -41,7 +43,7 @@ const OliveMenuStandAloneComponent = (
41
43
( props . styles . button ?. [ props . device ] ?. size || props . trigger ?. size ) && (
42
44
< ButtonContainer ref = { buttonRef } styles = { props . styles } >
43
45
< Button
44
- aria-controls = { props . open ? getAriaControls ( props . sections , ariaControls ) : undefined }
46
+ aria-controls = { props . open ? ariaControlIds ?. join ( ' ' ) : undefined }
45
47
aria-expanded = { props . open }
46
48
dataTestId = { `${ props . dataTestId } Button` }
47
49
size = { props . styles . button ?. [ props . device ] ?. size }
@@ -93,14 +95,14 @@ const OliveMenuStandAloneComponent = (
93
95
< ListOptions
94
96
key = { section . id }
95
97
dataTestId = { props . dataTestId }
96
- id = { `${ ariaControls } ${ index } ${ section . id ? `${ section . id } ` : '' } ` }
97
98
optionVariant = { props . styles . listOptions ?. optionVariant as string }
98
99
selectedValue = { props . selectedValue }
99
100
title = { { component : TextComponentType . H6 , ...title } }
100
101
type = { ListOptionsType . NAVIGATION }
101
102
variant = { props . styles . listOptions ?. variant as string }
102
103
onOptionClick = { props . onOptionClick }
103
104
{ ...section }
105
+ id = { ariaControlIds ?. [ index ] }
104
106
/>
105
107
) ) }
106
108
</ ListboxStyled >
Original file line number Diff line number Diff line change @@ -3,11 +3,10 @@ import { OliveMenuListOptions } from '../types';
3
3
export const getAriaControls = (
4
4
sections : OliveMenuListOptions [ ] | undefined ,
5
5
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 ;
13
12
} ;
You can’t perform that action at this time.
0 commit comments