Skip to content

Commit 58406af

Browse files
authored
fix: Fix menu scrolling. (#8765)
* Revert "fix: Fix bug that preventing scrolling menu items into view. (#8726)" This reverts commit f166b67. * fix: Fix menu scrolling.
1 parent db57976 commit 58406af

3 files changed

Lines changed: 13 additions & 22 deletions

File tree

core/field_dropdown.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {Coordinate} from './utils/coordinate.js';
2929
import * as dom from './utils/dom.js';
3030
import * as parsing from './utils/parsing.js';
3131
import * as utilsString from './utils/string.js';
32+
import * as style from './utils/style.js';
3233
import {Svg} from './utils/svg.js';
3334

3435
/**
@@ -303,6 +304,11 @@ export class FieldDropdown extends Field<string> {
303304

304305
if (this.selectedMenuItem) {
305306
this.menu_!.setHighlighted(this.selectedMenuItem);
307+
style.scrollIntoContainerView(
308+
this.selectedMenuItem.getElement()!,
309+
dropDownDiv.getContentDiv(),
310+
true,
311+
);
306312
}
307313

308314
this.applyColour();

core/menu.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,13 @@ export class Menu {
260260
this.highlightedItem = item;
261261
// Bring the highlighted item into view. This has no effect if the menu is
262262
// not scrollable.
263-
const el = this.getElement();
264-
if (el) {
265-
aria.setState(el, aria.State.ACTIVEDESCENDANT, item.getId());
266-
}
267-
item.getElement()?.scrollIntoView({
268-
block: 'nearest',
269-
inline: 'start',
270-
});
263+
const menuElement = this.getElement();
264+
const scrollingParent = menuElement?.parentElement;
265+
const menuItemElement = item.getElement();
266+
if (!scrollingParent || !menuItemElement) return;
267+
268+
style.scrollIntoContainerView(menuItemElement, scrollingParent);
269+
aria.setState(menuElement, aria.State.ACTIVEDESCENDANT, item.getId());
271270
}
272271
}
273272

core/utils/style.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// Former goog.module ID: Blockly.utils.style
88

99
import {Coordinate} from './coordinate.js';
10-
import * as deprecation from './deprecation.js';
1110
import {Rect} from './rect.js';
1211
import {Size} from './size.js';
1312

@@ -59,7 +58,6 @@ function getSizeInternal(element: Element): Size {
5958
* @returns Object with width/height properties.
6059
*/
6160
function getSizeWithDisplay(element: Element): Size {
62-
deprecation.warn(`Blockly.utils.style.getSizeWithDisplay()`, 'v11.2', 'v13');
6361
const offsetWidth = (element as HTMLElement).offsetWidth;
6462
const offsetHeight = (element as HTMLElement).offsetHeight;
6563
return new Size(offsetWidth, offsetHeight);
@@ -132,7 +130,6 @@ export function getViewportPageOffset(): Coordinate {
132130
* @returns The computed border widths.
133131
*/
134132
export function getBorderBox(element: Element): Rect {
135-
deprecation.warn(`Blockly.utils.style.getBorderBox()`, 'v11.2', 'v13');
136133
const left = parseFloat(getComputedStyle(element, 'borderLeftWidth'));
137134
const right = parseFloat(getComputedStyle(element, 'borderRightWidth'));
138135
const top = parseFloat(getComputedStyle(element, 'borderTopWidth'));
@@ -159,12 +156,6 @@ export function scrollIntoContainerView(
159156
container: Element,
160157
opt_center?: boolean,
161158
) {
162-
deprecation.warn(
163-
`Blockly.utils.style.scrollIntoContainerView()`,
164-
'v11.2',
165-
'v13',
166-
'the native Element.scrollIntoView()',
167-
);
168159
const offset = getContainerOffsetToScrollInto(element, container, opt_center);
169160
container.scrollLeft = offset.x;
170161
container.scrollTop = offset.y;
@@ -189,11 +180,6 @@ export function getContainerOffsetToScrollInto(
189180
container: Element,
190181
opt_center?: boolean,
191182
): Coordinate {
192-
deprecation.warn(
193-
`Blockly.utils.style.getContainerOffsetToScrollInto()`,
194-
'v11.2',
195-
'v13',
196-
);
197183
// Absolute position of the element's border's top left corner.
198184
const elementPos = getPageOffset(element);
199185
// Absolute position of the container's border's top left corner.

0 commit comments

Comments
 (0)