fix: Prevent errors when mixing keyboard/mouse input in the toolbox/flyout (#9773)

This commit is contained in:
Aaron Dodson
2026-04-29 09:20:35 -07:00
committed by GitHub
parent 86fa331867
commit a5ff158b1f
4 changed files with 21 additions and 5 deletions
@@ -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;
}
+15 -4
View File
@@ -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');