@@ -62,6 +62,99 @@ describe("settings search targets", () => {
6262 expect ( target . classList . contains ( PULSE ) ) . toBe ( false ) ;
6363 } ) ;
6464
65+ it . each ( [ "before" , "after" , "without animation" ] as const ) (
66+ "fully reveals the row when the opening style clears: %s" ,
67+ async ( phase ) => {
68+ // Keep scrolling synchronous while the panel height transitions independently.
69+ reduceMotion ( true ) ;
70+ document . body . innerHTML = `
71+ <div id="viewport" style="height: 200px; overflow: auto; overflow-anchor: none">
72+ <div id="panel" data-slot="collapsible-panel" data-open data-starting-style
73+ style="height: 0; overflow: hidden; transition: height 200ms linear">
74+ <div style="height: 500px"></div>
75+ <div id="legacy-sidebar" tabindex="-1" style="height: 40px">Legacy sidebar</div>
76+ <div style="height: 60px"></div>
77+ </div>
78+ </div>` ;
79+ const viewport = document . getElementById ( "viewport" ) ! ;
80+ const panel = document . getElementById ( "panel" ) ! ;
81+ const target = document . getElementById ( "legacy-sidebar" ) ! ;
82+
83+ void panel . offsetHeight ;
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+ }
97+
98+ expect ( scrollToSettingsTarget ( "legacy-sidebar" ) ) . toBe ( true ) ;
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" ;
106+ panel . removeAttribute ( "data-starting-style" ) ;
107+ transition ?. finish ( ) ;
108+ await opened ;
109+
110+ const bounds = viewport . getBoundingClientRect ( ) ;
111+ const row = target . getBoundingClientRect ( ) ;
112+ expect ( row . top ) . toBeGreaterThanOrEqual ( bounds . top ) ;
113+ expect ( row . bottom ) . toBeLessThanOrEqual ( bounds . bottom ) ;
114+ expect ( document . activeElement ) . toBe ( target ) ;
115+ } ,
116+ ) ;
117+
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+
65158 it ( "leaves not-yet-mounted destinations to their mount lifecycle" , ( ) => {
66159 expect ( scrollToSettingsTarget ( "archive" ) ) . toBe ( false ) ;
67160 } ) ;
0 commit comments