diff --git a/toolbox.js b/toolbox.js index 435d12f5..a38c4320 100644 --- a/toolbox.js +++ b/toolbox.js @@ -4904,6 +4904,16 @@ class CustomCollapsibleToolboxCategory extends Blockly.CollapsibleToolboxCategor this.htmlDiv_?.focus?.(); } + ensureKeyboardFocusedSelection_() { + this.setExpanded(true); + + const flyout = this.parentToolbox_?.getFlyout?.(); + if (flyout && !flyout.isVisible?.()) { + const contents = this.getContents?.(); + if (contents) flyout.show?.(contents); + } + } + // Preserve the original icon createIconDom_() { const img = document.createElement("img"); @@ -4918,6 +4928,10 @@ class CustomCollapsibleToolboxCategory extends Blockly.CollapsibleToolboxCategor setSelected(isSelected) { super.setSelected(isSelected); + if (isSelected) { + this.ensureKeyboardFocusedSelection_(); + } + // Get the category color const categoryColour = this.colour_; @@ -4984,6 +4998,13 @@ class CustomCollapsibleToolboxCategory extends Blockly.CollapsibleToolboxCategor { capture: true }, ); + this.rowDiv_.addEventListener("focusin", () => { + if (this.toolboxHasFocus_()) { + this.parentToolbox_?.setSelectedItem?.(this); + this.ensureKeyboardFocusedSelection_(); + } + }); + return this.htmlDiv_; } }