Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix bug that preventing scrolling menu items into view. #8726

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions core/field_dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {Coordinate} from './utils/coordinate.js';
import * as dom from './utils/dom.js';
import * as parsing from './utils/parsing.js';
import * as utilsString from './utils/string.js';
import * as style from './utils/style.js';
import {Svg} from './utils/svg.js';

/**
Expand Down Expand Up @@ -304,11 +303,6 @@ export class FieldDropdown extends Field<string> {

if (this.selectedMenuItem) {
this.menu_!.setHighlighted(this.selectedMenuItem);
style.scrollIntoContainerView(
this.selectedMenuItem.getElement()!,
dropDownDiv.getContentDiv(),
true,
);
}

this.applyColour();
Expand Down
9 changes: 5 additions & 4 deletions core/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,11 @@ export class Menu {
this.highlightedItem = item;
// Bring the highlighted item into view. This has no effect if the menu is
// not scrollable.
const el = this.getElement() as Element;
style.scrollIntoContainerView(item.getElement() as Element, el);

aria.setState(el, aria.State.ACTIVEDESCENDANT, item.getId());
const el = this.getElement();
if (el) {
aria.setState(el, aria.State.ACTIVEDESCENDANT, item.getId());
}
item.getElement()?.scrollIntoView();
}
}

Expand Down
14 changes: 14 additions & 0 deletions core/utils/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// Former goog.module ID: Blockly.utils.style

import {Coordinate} from './coordinate.js';
import * as deprecation from './deprecation.js';
import {Rect} from './rect.js';
import {Size} from './size.js';

Expand Down Expand Up @@ -58,6 +59,7 @@ function getSizeInternal(element: Element): Size {
* @returns Object with width/height properties.
*/
function getSizeWithDisplay(element: Element): Size {
deprecation.warn(`Blockly.utils.style.getSizeWithDisplay()`, 'v11.2', 'v13');
const offsetWidth = (element as HTMLElement).offsetWidth;
const offsetHeight = (element as HTMLElement).offsetHeight;
return new Size(offsetWidth, offsetHeight);
Expand Down Expand Up @@ -130,6 +132,7 @@ export function getViewportPageOffset(): Coordinate {
* @returns The computed border widths.
*/
export function getBorderBox(element: Element): Rect {
deprecation.warn(`Blockly.utils.style.getBorderBox()`, 'v11.2', 'v13');
const left = parseFloat(getComputedStyle(element, 'borderLeftWidth'));
const right = parseFloat(getComputedStyle(element, 'borderRightWidth'));
const top = parseFloat(getComputedStyle(element, 'borderTopWidth'));
Expand All @@ -156,6 +159,12 @@ export function scrollIntoContainerView(
container: Element,
opt_center?: boolean,
) {
deprecation.warn(
`Blockly.utils.style.scrollIntoContainerView()`,
'v11.2',
'v13',
'the native Element.scrollIntoView()',
);
const offset = getContainerOffsetToScrollInto(element, container, opt_center);
container.scrollLeft = offset.x;
container.scrollTop = offset.y;
Expand All @@ -180,6 +189,11 @@ export function getContainerOffsetToScrollInto(
container: Element,
opt_center?: boolean,
): Coordinate {
deprecation.warn(
`Blockly.utils.style.getContainerOffsetToScrollInto()`,
'v11.2',
'v13',
);
// Absolute position of the element's border's top left corner.
const elementPos = getPageOffset(element);
// Absolute position of the container's border's top left corner.
Expand Down
Loading