@@ -30,7 +30,6 @@ import {Coordinate} from './utils/coordinate.js';
3030import * as dom from './utils/dom.js' ;
3131import * as parsing from './utils/parsing.js' ;
3232import * as utilsString from './utils/string.js' ;
33- import * as style from './utils/style.js' ;
3433import { Svg } from './utils/svg.js' ;
3534
3635/**
@@ -276,16 +275,18 @@ export class FieldDropdown extends Field<string> {
276275 throw new UnattachedFieldError ( ) ;
277276 }
278277 this . dropdownCreate ( ) ;
278+ if ( ! this . menu_ ) return ;
279+
279280 if ( e && typeof e . clientX === 'number' ) {
280- this . menu_ ! . openingCoords = new Coordinate ( e . clientX , e . clientY ) ;
281+ this . menu_ . openingCoords = new Coordinate ( e . clientX , e . clientY ) ;
281282 } else {
282- this . menu_ ! . openingCoords = null ;
283+ this . menu_ . openingCoords = null ;
283284 }
284285
285286 // Remove any pre-existing elements in the dropdown.
286287 dropDownDiv . clearContent ( ) ;
287288 // Element gets created in render.
288- const menuElement = this . menu_ ! . render ( dropDownDiv . getContentDiv ( ) ) ;
289+ const menuElement = this . menu_ . render ( dropDownDiv . getContentDiv ( ) ) ;
289290 dom . addClass ( menuElement , 'blocklyDropdownMenu' ) ;
290291
291292 if ( this . getConstants ( ) ! . FIELD_DROPDOWN_COLOURED_DIV ) {
@@ -296,18 +297,15 @@ export class FieldDropdown extends Field<string> {
296297
297298 dropDownDiv . showPositionedByField ( this , this . dropdownDispose_ . bind ( this ) ) ;
298299
300+ dropDownDiv . getContentDiv ( ) . style . height = `${ this . menu_ . getSize ( ) . height } px` ;
301+
299302 // Focusing needs to be handled after the menu is rendered and positioned.
300303 // Otherwise it will cause a page scroll to get the misplaced menu in
301304 // view. See issue #1329.
302- this . menu_ ! . focus ( ) ;
305+ this . menu_ . focus ( ) ;
303306
304307 if ( this . selectedMenuItem ) {
305- this . menu_ ! . setHighlighted ( this . selectedMenuItem ) ;
306- style . scrollIntoContainerView (
307- this . selectedMenuItem . getElement ( ) ! ,
308- dropDownDiv . getContentDiv ( ) ,
309- true ,
310- ) ;
308+ this . menu_ . setHighlighted ( this . selectedMenuItem ) ;
311309 }
312310
313311 this . applyColour ( ) ;
0 commit comments