@@ -171,6 +171,26 @@ describe("focus traps - finalizeFocusWithPreCollectedMetadata", () => {
171171 assert . equal ( next . focusedId , "outside" ) ;
172172 } ) ;
173173
174+ test ( "empty trap focusables still honor valid initialFocus" , ( ) => {
175+ const next = finalizeWith (
176+ managerState ( { focusedId : "outside" } ) ,
177+ [ "outside" , "nested-id" ] ,
178+ new Map < string , CollectedTrap > ( [
179+ [
180+ "modal" ,
181+ trap ( {
182+ id : "modal" ,
183+ active : true ,
184+ initialFocus : "nested-id" ,
185+ focusableIds : [ ] ,
186+ } ) ,
187+ ] ,
188+ ] ) ,
189+ ) ;
190+
191+ assert . equal ( next . focusedId , "nested-id" ) ;
192+ } ) ;
193+
174194 test ( "deactivation restores returnFocusTo when valid" , ( ) => {
175195 const prev = managerState ( { focusedId : "inside" , trapStack : Object . freeze ( [ "modal" ] ) } ) ;
176196
@@ -358,6 +378,34 @@ describe("focus traps - finalizeFocusForCommittedTreeWithZones integration", ()
358378 assert . deepEqual ( next . trapStack , [ "modal" ] ) ;
359379 } ) ;
360380
381+ test ( "empty trap focusables can still focus a valid nested initialFocus id" , ( ) => {
382+ const tree : VNode = {
383+ kind : "column" ,
384+ props : { } ,
385+ children : [
386+ { kind : "button" , props : { id : "outside" , label : "Outside" } } ,
387+ {
388+ kind : "focusTrap" ,
389+ props : { id : "modal" , active : true , initialFocus : "nested-id" } ,
390+ children : [
391+ {
392+ kind : "focusZone" ,
393+ props : { id : "nested-zone" , navigation : "linear" } ,
394+ children : [ { kind : "button" , props : { id : "nested-id" , label : "Nested" } } ] ,
395+ } ,
396+ ] ,
397+ } ,
398+ ] ,
399+ } ;
400+
401+ const next = finalizeFocusForCommittedTreeWithZones (
402+ createFocusManagerState ( ) ,
403+ commitTree ( tree ) ,
404+ ) ;
405+ assert . equal ( next . focusedId , "nested-id" ) ;
406+ assert . deepEqual ( next . trapStack , [ "modal" ] ) ;
407+ } ) ;
408+
361409 test ( "inactive trap does not capture focus" , ( ) => {
362410 const tree : VNode = {
363411 kind : "column" ,
0 commit comments