File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 258258 }
259259 }
260260
261+ function focusSearchInput ( ) {
262+ if ( ! input ) return ;
263+ var opts = { preventScroll : true } ;
264+ if ( document . activeElement && document . activeElement . closest && document . activeElement . closest ( '[data-search-open]' ) ) {
265+ document . activeElement . blur ( ) ;
266+ }
267+ input . focus ( opts ) ;
268+ requestAnimationFrame ( function ( ) {
269+ if ( ! input ) return ;
270+ input . focus ( opts ) ;
271+ requestAnimationFrame ( function ( ) {
272+ if ( ! input ) return ;
273+ input . focus ( opts ) ;
274+ } ) ;
275+ } ) ;
276+ setTimeout ( function ( ) {
277+ if ( ! input || ! isOpen ) return ;
278+ input . focus ( opts ) ;
279+ } , 220 ) ;
280+ }
281+
261282 function isPaletteVisible ( ) {
262283 return ! ! ( palette && palette . classList . contains ( 'is-visible' ) ) ;
263284 }
285306
286307 if ( isEmbedded ) {
287308 if ( input ) {
288- input . focus ( ) ;
309+ focusSearchInput ( ) ;
289310 runSearch ( query || input . value || '' ) ;
290311 }
291312 return ;
292313 }
293314 if ( isOpen && isPaletteVisible ( ) ) {
294315 if ( input ) {
295- input . focus ( ) ;
296316 if ( query ) {
297317 input . value = query ;
298318 runSearch ( query ) ;
299319 }
320+ focusSearchInput ( ) ;
300321 }
301322 return ;
302323 }
319340 if ( input ) {
320341 input . value = query || '' ;
321342 runSearch ( input . value ) ;
322- requestAnimationFrame ( function ( ) {
323- if ( input ) input . focus ( ) ;
324- } ) ;
343+ focusSearchInput ( ) ;
325344 }
326345 }
327346
514533 if ( input ) {
515534 input . value = q ;
516535 runSearch ( q ) ;
517- input . focus ( ) ;
536+ focusSearchInput ( ) ;
518537 }
519538 }
520539
You can’t perform that action at this time.
0 commit comments