Blocks getting unselected

29 views
Skip to first unread message

co...@cortscorner.net

unread,
Nov 11, 2025, 3:17:13 AM (yesterday) Nov 11
to Blockly
I'm currently using 12.3.0, and noticed that if I have a block selected, then click anywhere outside of the Blockly workspace, the block gets unselected. The last version I was using, 9.20221004.0, did not have this behaviour.

The demo at https://blockly-demo.appspot.com/static/demos/code/index.html (version 12.3.1) exhibits this behaviour (...block gets unselected), but the blockly games (https://blockly.games/puzzle?lang=en) do not.

Not sure if this is a bug or intended behaviour. If it's an intended behaviour, is there a way for me to preserve block selection? I have a "Run selected block" function in my application, and that no longer works due to the unselection of the block.

Ben Henning

unread,
Nov 11, 2025, 3:32:51 PM (23 hours ago) Nov 11
to blo...@googlegroups.com
Hi,

This behavior change was introduced in #9004 which first landed in Blockly v12.0.0. This is an incidental change that comes from an intentional behavioral change. The concept of block selection is now strictly tied to a new concept in Blockly v12 called 'active focus' (which is essentially the logical representation of what Blockly component currently has DOM focus and can be interacted with which is an important part of keyboard navigation and ongoing screenreader work). We decided to make this tight coupling because we didn't want to conflate selection and active focus: if something has active focus (e.g. for DOM input) then it may also be selected (in the case of blocks and comments), but it doesn't make sense for something to be selected without active focus (because selection implies the ability to perform actions upon a block).

This introduces a regression for one very specific use case (which I think you're running into): if a block loses active focus and the selection is also communicating some sort of external importance (maybe for a pedagogical reason), then losing focus loses the selection (e.g. when a learner is navigating to more lesson information). This is a gap that we don't currently have plans to solve, but you're welcome to file a feature request for it.

In the meantime, I think other platforms might solve this problem by introducing a separate means of highlighting and/or emphasizing a block separate from Blockly selection (or they implement their own selection logic). One option you may have is to customize the CSS class 'blocklyPassiveFocus' but it highly depends on your use case. Along with 'active' focus Blockly v12 introduces the concept of 'passive' focus. These are components that previously held active focus until the user navigated to a different, logically distinct part of the page. Returning to the previous part of the page will return active focus unless a new element is selected/focused (this is more relevant in keyboard navigation than when using a mouse). You could consider styling 'blocklyPassiveFocus' specifically for blocks ('blocklyPath') to continue providing some sort of highlight but this will only work very specifically in the case where a block is selected and then the user clicks out of the main workspace (plus some other cases like when interacting with the toolbox/flyout, or opening a field editor) so it may not exactly fit your situation.

If none of that works then you could also listen for selection events and style the block path manually to suit your needs with CSS.

I hope this helps.
Ben

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/blockly/a7ec59d5-bca7-4c76-ba86-b24e0ef70593n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages