Skip to content

Commit b0dc1de

Browse files
authored
fix: Don't open the toolbox when clicking beneath the categories (#9535)
* fix: Don't open the toolbox when clicking beneath the categories * chore: Add docstring * chore: Add test * chore: Add comment clarifying selection logic
1 parent f9fb226 commit b0dc1de

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

core/toolbox/toolbox.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ export class Toolbox
108108
/** The workspace this toolbox is on. */
109109
protected readonly workspace_: WorkspaceSvg;
110110

111+
/** Whether the mouse is currently being clicked. */
112+
private mouseDown = false;
113+
111114
/** @param workspace The workspace in which to create new blocks. */
112115
constructor(workspace: WorkspaceSvg) {
113116
super();
@@ -243,6 +246,16 @@ export class Toolbox
243246
);
244247
this.boundEvents_.push(clickEvent);
245248

249+
const mouseUpEvent = browserEvents.bind(
250+
container,
251+
'pointerup',
252+
this,
253+
() => {
254+
this.mouseDown = false;
255+
},
256+
);
257+
this.boundEvents_.push(mouseUpEvent);
258+
246259
const keyDownEvent = browserEvents.conditionalBind(
247260
contentsContainer,
248261
'keydown',
@@ -259,6 +272,7 @@ export class Toolbox
259272
* @param e Click event to handle.
260273
*/
261274
protected onClick_(e: PointerEvent) {
275+
this.mouseDown = true;
262276
if (browserEvents.isRightButton(e) || e.target === this.HtmlDiv) {
263277
// Close flyout.
264278
(common.getMainWorkspace() as WorkspaceSvg).hideChaff(false);
@@ -1134,7 +1148,10 @@ export class Toolbox
11341148
): void {
11351149
if (node !== this) {
11361150
// Only select the item if it isn't already selected so as to not toggle.
1137-
if (this.getSelectedItem() !== node) {
1151+
// Also require that the mouse not be down, i.e. that the focusing of
1152+
// the toolbox was keyboard-driven, to avoid opening the flyout when
1153+
// clicking on an empty part of the toolbox.
1154+
if (this.getSelectedItem() !== node && !this.mouseDown) {
11381155
this.setSelectedItem(node as IToolboxItem);
11391156
}
11401157
} else {

tests/browser/test/toolbox_drag_test.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,13 @@ suite('Open toolbox categories', function () {
207207
);
208208
await openCategories(this.browser, testCategories, screenDirection.RTL);
209209
});
210+
211+
test('clicking the toolbox itself does not open the flyout', async function () {
212+
this.browser = await testSetup(testFileLocations.PLAYGROUND);
213+
await this.browser.$('.blocklyToolbox').click();
214+
const flyoutOpen = await this.browser.execute(() => {
215+
return Blockly.getMainWorkspace().getFlyout().isVisible();
216+
});
217+
chai.assert.isFalse(flyoutOpen);
218+
});
210219
});

0 commit comments

Comments
 (0)