@@ -62,8 +62,8 @@ describe("settings search targets", () => {
6262 expect ( target . classList . contains ( PULSE ) ) . toBe ( false ) ;
6363 } ) ;
6464
65- it . each ( [ "before" , "after" ] as const ) (
66- "fully reveals the row when selected %s the opening style clears" ,
65+ it . each ( [ "before" , "after" , "without animation" ] as const ) (
66+ "fully reveals the row when the opening style clears: %s " ,
6767 async ( phase ) => {
6868 // Keep scrolling synchronous while the panel height transitions independently.
6969 reduceMotion ( true ) ;
@@ -81,19 +81,30 @@ describe("settings search targets", () => {
8181 const target = document . getElementById ( "legacy-sidebar" ) ! ;
8282
8383 void panel . offsetHeight ;
84- panel . style . height = "600px" ;
85- const transition = panel . getAnimations ( ) [ 0 ] ! ;
86- expect ( transition ) . toBeDefined ( ) ;
87- transition . pause ( ) ;
88- transition . currentTime = phase === "before" ? 0 : 100 ;
89- if ( phase === "after" ) panel . removeAttribute ( "data-starting-style" ) ;
84+ const animated = phase !== "without animation" ;
85+ if ( animated ) {
86+ panel . style . height = "600px" ;
87+ } else {
88+ panel . style . transition = "none" ;
89+ }
90+ const transition = panel . getAnimations ( ) [ 0 ] ;
91+ if ( animated ) {
92+ expect ( transition ) . toBeDefined ( ) ;
93+ transition ! . pause ( ) ;
94+ transition ! . currentTime = phase === "before" ? 0 : 100 ;
95+ if ( phase === "after" ) panel . removeAttribute ( "data-starting-style" ) ;
96+ }
9097
9198 expect ( scrollToSettingsTarget ( "legacy-sidebar" ) ) . toBe ( true ) ;
92- const opened = new Promise < void > ( ( resolve ) => {
93- panel . addEventListener ( "transitionend" , ( ) => resolve ( ) , { once : true } ) ;
94- } ) ;
99+ expect ( document . activeElement ) . toBe ( target ) ;
100+ const opened = animated
101+ ? new Promise < void > ( ( resolve ) => {
102+ panel . addEventListener ( "transitionend" , ( ) => resolve ( ) , { once : true } ) ;
103+ } )
104+ : Promise . resolve ( ) ;
105+ panel . style . height = "600px" ;
95106 panel . removeAttribute ( "data-starting-style" ) ;
96- transition . finish ( ) ;
107+ transition ? .finish ( ) ;
97108 await opened ;
98109
99110 const bounds = viewport . getBoundingClientRect ( ) ;
@@ -104,6 +115,46 @@ describe("settings search targets", () => {
104115 } ,
105116 ) ;
106117
118+ it ( "keeps the newer search destination visible when an earlier panel finishes opening" , async ( ) => {
119+ reduceMotion ( true ) ;
120+ document . body . innerHTML = `
121+ <div id="viewport" style="height: 200px; overflow: auto; overflow-anchor: none">
122+ <div id="new-target" tabindex="-1" style="height: 40px">New target</div>
123+ <div style="height: 1000px"></div>
124+ <div id="panel" data-slot="collapsible-panel" data-open data-starting-style
125+ style="height: 0; overflow: hidden; transition: height 200ms linear">
126+ <div style="height: 500px"></div>
127+ <div id="legacy-sidebar" tabindex="-1" style="height: 40px">Legacy sidebar</div>
128+ <div style="height: 60px"></div>
129+ </div>
130+ </div>` ;
131+ const panel = document . getElementById ( "panel" ) ! ;
132+ void panel . offsetHeight ;
133+ panel . style . height = "600px" ;
134+ const transition = panel . getAnimations ( ) [ 0 ] ! ;
135+ transition . pause ( ) ;
136+ transition . currentTime = 100 ;
137+
138+ scrollToSettingsTarget ( "legacy-sidebar" ) ;
139+ panel . removeAttribute ( "data-starting-style" ) ;
140+ scrollToSettingsTarget ( "new-target" ) ;
141+ const opened = new Promise < void > ( ( resolve ) => {
142+ panel . addEventListener ( "transitionend" , ( ) => resolve ( ) , { once : true } ) ;
143+ } ) ;
144+ transition . finish ( ) ;
145+ await opened ;
146+
147+ const viewport = document . getElementById ( "viewport" ) ! ;
148+ const target = document . getElementById ( "new-target" ) ! ;
149+ expect ( target . getBoundingClientRect ( ) . top ) . toBeGreaterThanOrEqual (
150+ viewport . getBoundingClientRect ( ) . top ,
151+ ) ;
152+ expect ( target . getBoundingClientRect ( ) . bottom ) . toBeLessThanOrEqual (
153+ viewport . getBoundingClientRect ( ) . bottom ,
154+ ) ;
155+ expect ( document . activeElement ) . toBe ( target ) ;
156+ } ) ;
157+
107158 it ( "leaves not-yet-mounted destinations to their mount lifecycle" , ( ) => {
108159 expect ( scrollToSettingsTarget ( "archive" ) ) . toBe ( false ) ;
109160 } ) ;
0 commit comments