Skip to content

Commit e45471d

Browse files
authored
fix: Fix menu scrolling. (#8881)
1 parent 98cf5cb commit e45471d

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

core/css.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,6 @@ let content = `
124124
125125
.blocklyDropDownContent {
126126
max-height: 300px; /* @todo: spec for maximum height. */
127-
overflow: auto;
128-
overflow-x: hidden;
129-
position: relative;
130127
}
131128
132129
.blocklyDropDownArrow {
@@ -416,7 +413,9 @@ input[type=number] {
416413
border: inherit; /* Compatibility with gapi, reset from goog-menu */
417414
font: normal 13px "Helvetica Neue", Helvetica, sans-serif;
418415
outline: none;
419-
position: relative; /* Compatibility with gapi, reset from goog-menu */
416+
overflow-y: auto;
417+
overflow-x: hidden;
418+
max-height: 100%;
420419
z-index: 20000; /* Arbitrary, but some apps depend on it... */
421420
}
422421

core/field_dropdown.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {Coordinate} from './utils/coordinate.js';
3030
import * as dom from './utils/dom.js';
3131
import * as parsing from './utils/parsing.js';
3232
import * as utilsString from './utils/string.js';
33-
import * as style from './utils/style.js';
3433
import {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();

core/menu.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,10 @@ export class Menu {
258258
// Bring the highlighted item into view. This has no effect if the menu is
259259
// not scrollable.
260260
const menuElement = this.getElement();
261-
const scrollingParent = menuElement?.parentElement;
262261
const menuItemElement = item.getElement();
263-
if (!scrollingParent || !menuItemElement) return;
262+
if (!menuElement || !menuItemElement) return;
264263

265-
style.scrollIntoContainerView(menuItemElement, scrollingParent);
264+
style.scrollIntoContainerView(menuItemElement, menuElement);
266265
aria.setState(menuElement, aria.State.ACTIVEDESCENDANT, item.getId());
267266
}
268267
}

0 commit comments

Comments
 (0)