@@ -8,6 +8,7 @@ export const CascadeSelectSub = React.memo((props) => {
88 const mergeProps = useMergeProps ( ) ;
99 const [ activeOptionState , setActiveOptionState ] = React . useState ( null ) ;
1010 const elementRef = React . useRef ( null ) ;
11+ const shouldFocusSubmenu = React . useRef ( false ) ;
1112 const context = React . useContext ( PrimeReactContext ) ;
1213 const { ptm, cx } = props ;
1314
@@ -64,6 +65,7 @@ export const CascadeSelectSub = React.memo((props) => {
6465 if ( activeOptionState === option ) {
6566 listItem . children [ 1 ] . children [ 0 ] . children [ 0 ] . focus ( ) ;
6667 } else {
68+ shouldFocusSubmenu . current = true ;
6769 setActiveOptionState ( option ) ;
6870 }
6971 }
@@ -74,10 +76,16 @@ export const CascadeSelectSub = React.memo((props) => {
7476 case 'ArrowLeft' :
7577 setActiveOptionState ( null ) ;
7678
77- const parentList = event . currentTarget . parentElement . parentElement . previousElementSibling ;
79+ const currentList = event . currentTarget . parentElement . parentElement ;
80+ const wrapperDiv = currentList . parentElement ;
81+ const parentListItem = wrapperDiv . parentElement ;
7882
79- if ( parentList ) {
80- parentList . focus ( ) ;
83+ if ( parentListItem && parentListItem . tagName === 'LI' ) {
84+ const parentContent = parentListItem . querySelector ( '[data-pc-section="content"]' ) ;
85+
86+ if ( parentContent ) {
87+ parentContent . focus ( ) ;
88+ }
8189 }
8290
8391 break ;
@@ -178,6 +186,25 @@ export const CascadeSelectSub = React.memo((props) => {
178186 }
179187 } , [ props . parentActive ] ) ;
180188
189+ useUpdateEffect ( ( ) => {
190+ if ( shouldFocusSubmenu . current && activeOptionState && elementRef . current ) {
191+ shouldFocusSubmenu . current = false ;
192+
193+ setTimeout ( ( ) => {
194+ const activeItem = elementRef . current . querySelector ( '[data-p-highlight="true"]' ) ;
195+
196+ if ( activeItem && activeItem . children . length > 1 ) {
197+ const submenuWrapper = activeItem . children [ 1 ] ;
198+ const firstFocusable = submenuWrapper . querySelector ( 'div[tabindex="0"]' ) ;
199+
200+ if ( firstFocusable ) {
201+ firstFocusable . focus ( ) ;
202+ }
203+ }
204+ } , 150 ) ;
205+ }
206+ } , [ activeOptionState ] ) ;
207+
181208 const createSubmenu = ( option ) => {
182209 if ( isOptionGroup ( option ) && activeOptionState === option ) {
183210 const options = getOptionGroupChildren ( option ) ;
0 commit comments