mirror of
https://github.com/google/blockly.git
synced 2026-05-01 09:30:11 +02:00
fix: Prevent errors when mixing keyboard/mouse input in the toolbox/flyout (#9773)
This commit is contained in:
@@ -42,6 +42,7 @@ export function isCollapsibleToolboxItem(
|
||||
obj: any,
|
||||
): obj is ICollapsibleToolboxItem {
|
||||
return (
|
||||
obj &&
|
||||
typeof obj.getChildToolboxItems === 'function' &&
|
||||
typeof obj.isExpanded === 'function' &&
|
||||
typeof obj.toggleExpanded === 'function' &&
|
||||
|
||||
@@ -45,7 +45,10 @@ export class ToolboxNavigator extends Navigator {
|
||||
}
|
||||
}
|
||||
|
||||
if (isSelectableToolboxItem(node) && !node.getContents().length) {
|
||||
if (
|
||||
!isSelectableToolboxItem(node) ||
|
||||
(isSelectableToolboxItem(node) && !node.getContents().length)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -277,22 +277,33 @@ export class Toolbox
|
||||
* @param e Click event to handle.
|
||||
*/
|
||||
protected onClick_(e: PointerEvent) {
|
||||
const close = () => {
|
||||
getFocusManager().focusNode(this);
|
||||
this.clearSelection();
|
||||
(common.getMainWorkspace() as WorkspaceSvg).hideChaff(false);
|
||||
e.preventDefault();
|
||||
};
|
||||
|
||||
this.mouseDown = true;
|
||||
if (browserEvents.isRightButton(e) || e.target === this.HtmlDiv) {
|
||||
// Close flyout.
|
||||
(common.getMainWorkspace() as WorkspaceSvg).hideChaff(false);
|
||||
close();
|
||||
} else {
|
||||
const targetElement = e.target;
|
||||
const itemId = (targetElement as Element).getAttribute('id');
|
||||
if (itemId) {
|
||||
const item = this.getToolboxItemById(itemId);
|
||||
if (item?.isSelectable()) {
|
||||
this.setSelectedItem(item);
|
||||
(item as ISelectableToolboxItem).onClick(e);
|
||||
if (item === this.getSelectedItem()) {
|
||||
close();
|
||||
} else {
|
||||
this.setSelectedItem(item);
|
||||
// Just close popups.
|
||||
(common.getMainWorkspace() as WorkspaceSvg).hideChaff(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Just close popups.
|
||||
(common.getMainWorkspace() as WorkspaceSvg).hideChaff(true);
|
||||
}
|
||||
Touch.clearTouchIdentifier();
|
||||
}
|
||||
|
||||
@@ -234,6 +234,7 @@ suite('Toolbox', function () {
|
||||
)[0];
|
||||
const evt = {
|
||||
'target': categoryXml,
|
||||
'stopPropagation': () => {},
|
||||
};
|
||||
const item = this.toolbox.contents.get(categoryXml.getAttribute('id'));
|
||||
const setSelectedSpy = sinon.spy(this.toolbox, 'setSelectedItem');
|
||||
|
||||
Reference in New Issue
Block a user