@@ -37,6 +37,21 @@ const resetTabindexToCurrentPage = ($tree) => {
3737 }
3838} ;
3939
40+ const updateTreeAriaExpanded = ( $treeNode , expanded ) => {
41+ if ( ! $treeNode || ! $treeNode . length ) {
42+ return ;
43+ }
44+
45+ const ariaExpanded = expanded ? 'true' : 'false' ;
46+
47+ $treeNode
48+ . children ( 'a[role="treeitem"][aria-expanded], strong[role="treeitem"][aria-expanded]' )
49+ . attr ( 'aria-expanded' , ariaExpanded ) ;
50+ $treeNode
51+ . children ( '.jstree-icon--arrow[role="button"]' )
52+ . attr ( 'aria-expanded' , ariaExpanded ) ;
53+ } ;
54+
4055// this conditional check is so that we can unit test the functions above in this file without needing to
4156// load in jquery.entwine
4257if ( typeof $ . entwine === 'function' ) {
@@ -175,6 +190,17 @@ if (typeof $.entwine === 'function') {
175190 }
176191 resetTabindexToCurrentPage ( self ) ;
177192 } )
193+ . on ( 'open_node.jstree close_node.jstree' , function ( e , data ) {
194+ var node = data && data . rslt ? data . rslt . obj : null ;
195+ if ( ( ! node || ! $ ( node ) . length ) && data && data . args && data . args . length ) {
196+ node = data . args [ 0 ] ;
197+ }
198+ if ( ( ! node || ! $ ( node ) . length ) && data && data . node ) {
199+ node = data . node ;
200+ }
201+
202+ updateTreeAriaExpanded ( $ ( node ) , e . type === 'open_node' ) ;
203+ } )
178204 . on ( 'keydown' , function ( e ) {
179205 var key = e . key ;
180206 var target = e . target ;
@@ -719,4 +745,4 @@ if (typeof $.entwine === 'function') {
719745 } ) ;
720746}
721747
722- export { updateRovingTabindex , resetTabindexToCurrentPage } ;
748+ export { updateRovingTabindex , resetTabindexToCurrentPage , updateTreeAriaExpanded } ;
0 commit comments