Skip to content

Commit f166b67

Browse files
committed
fix: Fix bug that preventing scrolling menu items into view. (#8726)
* fix: Fix bug that preventing scrolling menu items into view. * chore: Deprecate now-unused-in-core functions in style. (cherry picked from commit 0c20129)
1 parent 44e783c commit f166b67

3 files changed

Lines changed: 19 additions & 10 deletions

File tree

core/field_dropdown.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ 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';
3332
import {Svg} from './utils/svg.js';
3433

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

305304
if (this.selectedMenuItem) {
306305
this.menu_!.setHighlighted(this.selectedMenuItem);
307-
style.scrollIntoContainerView(
308-
this.selectedMenuItem.getElement()!,
309-
dropDownDiv.getContentDiv(),
310-
true,
311-
);
312306
}
313307

314308
this.applyColour();

core/menu.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,11 @@ 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() as Element;
264-
style.scrollIntoContainerView(item.getElement() as Element, el);
265-
266-
aria.setState(el, aria.State.ACTIVEDESCENDANT, item.getId());
263+
const el = this.getElement();
264+
if (el) {
265+
aria.setState(el, aria.State.ACTIVEDESCENDANT, item.getId());
266+
}
267+
item.getElement()?.scrollIntoView();
267268
}
268269
}
269270

core/utils/style.ts

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

99
import {Coordinate} from './coordinate.js';
10+
import * as deprecation from './deprecation.js';
1011
import {Rect} from './rect.js';
1112
import {Size} from './size.js';
1213

@@ -58,6 +59,7 @@ function getSizeInternal(element: Element): Size {
5859
* @returns Object with width/height properties.
5960
*/
6061
function getSizeWithDisplay(element: Element): Size {
62+
deprecation.warn(`Blockly.utils.style.getSizeWithDisplay()`, 'v11.2', 'v13');
6163
const offsetWidth = (element as HTMLElement).offsetWidth;
6264
const offsetHeight = (element as HTMLElement).offsetHeight;
6365
return new Size(offsetWidth, offsetHeight);
@@ -130,6 +132,7 @@ export function getViewportPageOffset(): Coordinate {
130132
* @returns The computed border widths.
131133
*/
132134
export function getBorderBox(element: Element): Rect {
135+
deprecation.warn(`Blockly.utils.style.getBorderBox()`, 'v11.2', 'v13');
133136
const left = parseFloat(getComputedStyle(element, 'borderLeftWidth'));
134137
const right = parseFloat(getComputedStyle(element, 'borderRightWidth'));
135138
const top = parseFloat(getComputedStyle(element, 'borderTopWidth'));
@@ -156,6 +159,12 @@ export function scrollIntoContainerView(
156159
container: Element,
157160
opt_center?: boolean,
158161
) {
162+
deprecation.warn(
163+
`Blockly.utils.style.scrollIntoContainerView()`,
164+
'v11.2',
165+
'v13',
166+
'the native Element.scrollIntoView()',
167+
);
159168
const offset = getContainerOffsetToScrollInto(element, container, opt_center);
160169
container.scrollLeft = offset.x;
161170
container.scrollTop = offset.y;
@@ -180,6 +189,11 @@ export function getContainerOffsetToScrollInto(
180189
container: Element,
181190
opt_center?: boolean,
182191
): Coordinate {
192+
deprecation.warn(
193+
`Blockly.utils.style.getContainerOffsetToScrollInto()`,
194+
'v11.2',
195+
'v13',
196+
);
183197
// Absolute position of the element's border's top left corner.
184198
const elementPos = getPageOffset(element);
185199
// Absolute position of the container's border's top left corner.

0 commit comments

Comments
 (0)