File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -335,7 +335,8 @@ function CommandPaletteDialog(props: {
335335 const returnFocus = getCommandPaletteReturnFocus ( ) ;
336336 if ( returnFocus === false ) return false ;
337337 const composer = composerHandleRef ?. current ;
338- if ( ! composer ) return returnFocus ;
338+ // Behind the Settings modal the composer is inert and cannot take focus.
339+ if ( ! composer || document . querySelector ( "[data-app-modal]" ) ) return returnFocus ;
339340 composer . focusAtEnd ( ) ;
340341 return false ;
341342 } }
Original file line number Diff line number Diff line change @@ -120,4 +120,25 @@ describe("sidebar keyboard navigation", () => {
120120 expect ( document . activeElement ) . toBe ( owner ) ;
121121 expect ( action . tabIndex ) . toBe ( - 1 ) ;
122122 } ) ;
123+
124+ it ( "keeps row actions after an action's portalled menu returns focus" , ( ) => {
125+ using tree = setup ( ) ;
126+ const owner = tree . row ( "thread" ) ;
127+ const action = document . createElement ( "button" ) ;
128+ action . textContent = "Snooze" ;
129+ action . dataset . sidebarActionFor = "thread" ;
130+ tree . root . append ( action ) ;
131+ const menu = document . createElement ( "button" ) ;
132+ menu . textContent = "1 hour" ;
133+ document . body . append ( menu ) ;
134+ using _menu = { [ Symbol . dispose ] : ( ) => menu . remove ( ) } ;
135+ tree . install ( ) ;
136+ owner . focus ( ) ;
137+ press ( owner , "F2" ) ;
138+ menu . focus ( ) ;
139+ action . focus ( ) ;
140+ expect ( action . tabIndex ) . toBe ( 0 ) ;
141+ press ( action , "Escape" ) ;
142+ expect ( document . activeElement ) . toBe ( owner ) ;
143+ } ) ;
123144} ) ;
Original file line number Diff line number Diff line change @@ -102,7 +102,8 @@ export function installSidebarTree(root: HTMLElement) {
102102
103103 const onFocus = ( event : FocusEvent ) => {
104104 ownsFocus = root . contains ( event . target as Node ) ;
105- if ( ! ownsFocus || ( event . target instanceof HTMLElement && event . target . matches ( ROW ) ) )
105+ // A row action can open a portalled menu; keep the actions until focus returns to a row.
106+ if ( ownsFocus && event . target instanceof HTMLElement && event . target . matches ( ROW ) )
106107 leaveActions ( ) ;
107108 if ( ! ownsFocus || ! ( event . target instanceof HTMLElement ) || ! event . target . matches ( ROW ) ) return ;
108109 setTabStop ( event . target ) ;
@@ -155,10 +156,10 @@ export function installSidebarTree(root: HTMLElement) {
155156 rowActions = Array . from ( root . querySelectorAll < HTMLElement > ( CONTROL ) ) . filter (
156157 ( control ) =>
157158 control !== row &&
158- ! control . matches ( `${ ROW } , :disabled` ) &&
159- isWorkspaceElementVisible ( control ) &&
160159 ( control . closest ( ROW ) === row ||
161- control . dataset . sidebarActionFor === row . dataset . sidebarRow ) ,
160+ control . dataset . sidebarActionFor === row . dataset . sidebarRow ) &&
161+ ! control . matches ( `${ ROW } , :disabled` ) &&
162+ isWorkspaceElementVisible ( control ) ,
162163 ) ;
163164 if ( rowActions . length > 0 ) {
164165 actionRow = row ;
You can’t perform that action at this time.
0 commit comments