Skip to content

feat!: Add support for keyboard navigation#9634

Merged
gonfunko merged 21 commits intov13from
arrow-nav
Apr 1, 2026
Merged

feat!: Add support for keyboard navigation#9634
gonfunko merged 21 commits intov13from
arrow-nav

Conversation

@gonfunko
Copy link
Copy Markdown
Contributor

The basics

The details

Proposed Changes

This PR backports the core support for keyboard navigation of the workspace, toolbox and flyout from the blockly-keyboard-experimentation repo. It also refactors things to provide a more cohesive API for interacting with navigation. The general aspirational approach is:

  • The various *_navigation_policy.ts files specify, for each kind of focusable/navigable entity in Blockly, what its parent, first child, and previous/next siblings are, from a "just the facts"/AST perspective.
  • Navigator provides methods to query the "just the facts" relationships between elements, but also provides methods that incorporate business logic to make navigation order in response to the arrow keys make sense/feel right/pass the vibe test.
  • FlyoutNavigator and ToolboxNavigator customize the business logic for navigation in a flyout and toolbox context, respectively, and operate on a set of navigation policies relevant to focusable/navigable entities that exist in those contexts
  • Every IFocusableTree provides a Navigator instance which should be used to handle navigation within that tree
  • The actual shortcuts for the arrow keys are effectively one-liners that delegate to the Navigator for the active focus tree

This means that keyboard navigation does not have to keep track of the current state/context as in the keyboard-experimentation repo, because that maps precisely to the currently focused tree, which the FocusManager already keeps track of.

I backported the navigation business logic from the add-screen-reader-support-experimental branch, where up/down move between "rows" and left/right navigate within the current "row".

Future Work

  • Navigation within the toolbox needs to be adjusted to accomodate horizontal layouts and the various start/end toolbox positions
  • Some CSS rules need to be backported to make it clearer where focus is
  • The navigation policies should be cleaned up a bit to remove some vestiges of business logic
  • Additional tests for navigation behavior should be added; the suite from the keyboard-experimentation repo was backported with LLM assistance and manual review, but additional cases should be exercised, particularly with looping enabled
  • Enter/space to act on the focused element still needs to be backported

Breaking Changes

  • MarkerManager, Marker, and LineCursor have all been removed, along with their accessors. If you were interacting with one of these classes, Navigator should be close to a drop-in replacement.
  • IFocusableTree must implement getNavigator(), which should return a Navigator instance or subclass appropriate for navigating the tree
  • Flyout no longer implements IFocusableNode or IFocusableTree. The flyout's workspace continues to implement those interfaces, and should be used in place of the flyout itself.
  • Changes have been made to several toolbox-related interfaces. If you have custom toolbox-related classes that do not inherit from those provided in Blockly, you may need to adjust your implementation to ensure that:
    • IToolbox provides a getToolboxItems() method that returns an array of all items
    • IToolboxItem provides a getParentToolbox() method that returns a reference to its containing toolbox

@gonfunko gonfunko requested a review from maribethb March 16, 2026 21:02
@gonfunko gonfunko requested a review from a team as a code owner March 16, 2026 21:02
@github-actions github-actions bot added breaking change Used to mark a PR or issue that changes our public APIs. PR: feature Adds a feature labels Mar 16, 2026
@gonfunko
Copy link
Copy Markdown
Contributor Author

Comment thread packages/blockly/core/interfaces/i_toolbox.ts Outdated
Comment thread packages/blockly/core/keyboard_nav/navigators/navigator.ts Outdated
Comment thread packages/blockly/core/keyboard_nav/navigators/navigator.ts Outdated
Comment thread packages/blockly/core/keyboard_nav/navigators/navigator.ts
Comment thread packages/blockly/core/keyboard_nav/navigators/navigator.ts Outdated
return node.getSourceBlock();
} else if (node instanceof Icon) {
return node.getSourceBlock() as BlockSvg;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth adding a if typoeof node.getSourceBlock === function return node.getSourceBlock() to sort of make this work as if we had a IBelongsToBlock interface or something? Or worth formalizing that as an interface? potentially as a followup.

Comment thread packages/blockly/core/flyout_base.ts Outdated
/**
* Returns an ID for the visual "row" this input is part of.
*
* @internal
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be internal since it would be called from a navigation policy which is externally modifiable. right?

but if it's not internal, you can still add a disclaimer that the value only holds meaning for keyboard navigation and the value is not guaranteed to be stable, to discourage people from relying on this to do shenanigans

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was on the fence about this. You can create your own NavigationPolicy, subclass the existing ones, change the set that a Navigator uses, or subclass Navigator. There isn't inherently a reason to need this method though; we don't provide any ability to add new kinds of entities to blocks, where the block version of this might be needed, and you could for example subclass the Field or Connection navigation policies which call this method but just not override getRowId() in those, although again I don't think there's any reason to now that the navigation policies themselves don't really contain business logic. Navigator just calls getRowId() on the navigation policy, not this method, so you can even get it there with public API. If you make a new entity and put it in the flyout you'd need to specify a row ID in your navigation policy, but that would be your own synthetic ID, not an input or block one. So I think @internal is fine, especially since it's a sign not a cop? In general I figured we could start it off that way, and if someone came to us with a compelling reason why they needed it we could remove it. WDYT?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking the case where someone registers their own input navigation policy, they would need to call this. But that's fine, I think you're right it can start this way until needed.

* @param current The element to return the row ID of.
* @returns The row ID of the given element.
*/
getRowId(current: T): string;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the one remaining thing I find odd about this is that things that aren't on blocks also have this, like workspace comments. but i can't think of a different way to do this that's better

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory the bar button icons could be one row and the editor field another; it's not currently set up that way, but I don't think it's too much of a stretch. And the comment itself is of course a form of row.

@gonfunko gonfunko merged commit 05af6b6 into v13 Apr 1, 2026
4 of 5 checks passed
@gonfunko gonfunko deleted the arrow-nav branch April 1, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Used to mark a PR or issue that changes our public APIs. PR: feature Adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants