@@ -423,5 +423,26 @@ suite('WidgetDiv', function () {
423423 assert . strictEqual ( Blockly . getFocusManager ( ) . getFocusedNode ( ) , block ) ;
424424 assert . strictEqual ( document . activeElement , blockFocusableElem ) ;
425425 } ) ;
426+
427+ test ( 'for showing nested div with ephemeral focus restores DOM focus' , function ( ) {
428+ const block = this . setUpBlockWithField ( ) ;
429+ const field = Array . from ( block . getFields ( ) ) [ 0 ] ;
430+ Blockly . getFocusManager ( ) . focusNode ( block ) ;
431+ const nestedDiv = document . createElement ( 'div' ) ;
432+ nestedDiv . tabIndex = - 1 ;
433+ Blockly . WidgetDiv . getDiv ( ) . appendChild ( nestedDiv ) ;
434+ Blockly . WidgetDiv . show ( field , false , ( ) => { } , null , true ) ;
435+ nestedDiv . focus ( ) ; // It's valid to focus this during ephemeral focus.
436+
437+ // Hiding will cause the now focused child div to be removed, leading to
438+ // ephemeral focus being lost if the implementation doesn't handle
439+ // returning ephemeral focus correctly.
440+ Blockly . WidgetDiv . hide ( ) ;
441+
442+ // Hiding the div should restore focus back to the block.
443+ const blockFocusableElem = block . getFocusableElement ( ) ;
444+ assert . strictEqual ( Blockly . getFocusManager ( ) . getFocusedNode ( ) , block ) ;
445+ assert . strictEqual ( document . activeElement , blockFocusableElem ) ;
446+ } ) ;
426447 } ) ;
427448} ) ;
0 commit comments