-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat: Make toolbox and flyout focusable #8920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
BenHenning
merged 16 commits into
RaspberryPiFoundation:rc/v12.0.0
from
BenHenning:make-toolbox-and-flyout-focusable
Apr 24, 2025
Merged
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
41c8215
feat: Make WorkspaceSvg focusable.
BenHenning 14b486e
chore: remove accidental 'test.only'.
BenHenning 26cf8db
feat: Make Toolbox & Flyout focusable.
BenHenning 5ef2d7e
Merge branch 'add-focus-manager-callbacks-and-improvements' into make…
BenHenning 996208d
Merge branch 'make-workspace-focusable' into make-toolbox-and-flyout-…
BenHenning 4479b82
Merge branch 'add-focus-manager-callbacks-and-improvements' into make…
BenHenning 2637736
fix: Ensure Block paths are focusable.
BenHenning 49192ba
chore: Fix line comment.
BenHenning 917c4b6
Merge branch 'make-workspace-focusable' into make-toolbox-and-flyout-…
BenHenning d276dbc
chore: reduce branching.
BenHenning a346a92
fix: remove unnecessary shadow check.
BenHenning 4ed61bf
Merge branch 'make-workspace-focusable' into make-toolbox-and-flyout-…
BenHenning 80c8859
chore: add braces.
BenHenning b3bd5e7
Merge branch 'rc/v12.0.0' into make-workspace-focusable
BenHenning 1f0cefc
Merge branch 'make-workspace-focusable' into make-toolbox-and-flyout-…
BenHenning c2384c6
chore: empty commit to make CI pass.
BenHenning File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,11 +22,14 @@ import {DeleteArea} from '../delete_area.js'; | |
| import '../events/events_toolbox_item_select.js'; | ||
| import {EventType} from '../events/type.js'; | ||
| import * as eventUtils from '../events/utils.js'; | ||
| import {getFocusManager} from '../focus_manager.js'; | ||
| import type {IAutoHideable} from '../interfaces/i_autohideable.js'; | ||
| import type {ICollapsibleToolboxItem} from '../interfaces/i_collapsible_toolbox_item.js'; | ||
| import {isDeletable} from '../interfaces/i_deletable.js'; | ||
| import type {IDraggable} from '../interfaces/i_draggable.js'; | ||
| import type {IFlyout} from '../interfaces/i_flyout.js'; | ||
| import type {IFocusableNode} from '../interfaces/i_focusable_node.js'; | ||
| import type {IFocusableTree} from '../interfaces/i_focusable_tree.js'; | ||
| import type {IKeyboardAccessible} from '../interfaces/i_keyboard_accessible.js'; | ||
| import type {ISelectableToolboxItem} from '../interfaces/i_selectable_toolbox_item.js'; | ||
| import {isSelectableToolboxItem} from '../interfaces/i_selectable_toolbox_item.js'; | ||
|
|
@@ -51,7 +54,12 @@ import {CollapsibleToolboxCategory} from './collapsible_category.js'; | |
| */ | ||
| export class Toolbox | ||
| extends DeleteArea | ||
| implements IAutoHideable, IKeyboardAccessible, IStyleable, IToolbox | ||
| implements | ||
| IAutoHideable, | ||
| IKeyboardAccessible, | ||
| IStyleable, | ||
| IToolbox, | ||
| IFocusableNode | ||
| { | ||
| /** | ||
| * The unique ID for this component that is used to register with the | ||
|
|
@@ -163,6 +171,7 @@ export class Toolbox | |
| ComponentManager.Capability.DRAG_TARGET, | ||
| ], | ||
| }); | ||
| getFocusManager().registerTree(this); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -177,7 +186,6 @@ export class Toolbox | |
| const container = this.createContainer_(); | ||
|
|
||
| this.contentsDiv_ = this.createContentsContainer_(); | ||
| this.contentsDiv_.tabIndex = 0; | ||
| aria.setRole(this.contentsDiv_, aria.Role.TREE); | ||
| container.appendChild(this.contentsDiv_); | ||
|
|
||
|
|
@@ -194,6 +202,7 @@ export class Toolbox | |
| */ | ||
| protected createContainer_(): HTMLDivElement { | ||
| const toolboxContainer = document.createElement('div'); | ||
| toolboxContainer.tabIndex = 0; | ||
| toolboxContainer.setAttribute('layout', this.isHorizontal() ? 'h' : 'v'); | ||
| dom.addClass(toolboxContainer, 'blocklyToolbox'); | ||
| toolboxContainer.setAttribute('dir', this.RTL ? 'RTL' : 'LTR'); | ||
|
|
@@ -1077,7 +1086,68 @@ export class Toolbox | |
| this.workspace_.getThemeManager().unsubscribe(this.HtmlDiv); | ||
| dom.removeNode(this.HtmlDiv); | ||
| } | ||
|
|
||
| getFocusManager().unregisterTree(this); | ||
| } | ||
|
|
||
| /** See IFocusableNode.getFocusableElement. */ | ||
| getFocusableElement(): HTMLElement | SVGElement { | ||
| if (!this.HtmlDiv) throw Error('Toolbox DOM has not yet been created.'); | ||
| return this.HtmlDiv; | ||
| } | ||
|
|
||
| /** See IFocusableNode.getFocusableTree. */ | ||
| getFocusableTree(): IFocusableTree { | ||
| return this; | ||
| } | ||
|
|
||
| /** See IFocusableNode.onNodeFocus. */ | ||
| onNodeFocus(): void {} | ||
|
|
||
| /** See IFocusableNode.onNodeBlur. */ | ||
| onNodeBlur(): void {} | ||
|
|
||
| /** See IFocusableTree.getRootFocusableNode. */ | ||
| getRootFocusableNode(): IFocusableNode { | ||
| return this; | ||
| } | ||
|
|
||
| /** See IFocusableTree.getRestoredFocusableNode. */ | ||
| getRestoredFocusableNode( | ||
| previousNode: IFocusableNode | null, | ||
| ): IFocusableNode | null { | ||
| // Always try to select the first selectable toolbox item rather than the | ||
| // root of the toolbox. | ||
| if (!previousNode || previousNode === this) { | ||
| return this.getToolboxItems().find((item) => item.isSelectable()) ?? null; | ||
| } else return null; | ||
| } | ||
|
|
||
| /** See IFocusableTree.getNestedTrees. */ | ||
| getNestedTrees(): Array<IFocusableTree> { | ||
| return []; | ||
| } | ||
|
|
||
| /** See IFocusableTree.lookUpFocusableNode. */ | ||
| lookUpFocusableNode(id: string): IFocusableNode | null { | ||
| return this.getToolboxItemById(id) as IFocusableNode; | ||
| } | ||
|
|
||
| /** See IFocusableTree.onTreeFocus. */ | ||
| onTreeFocus( | ||
| node: IFocusableNode, | ||
| _previousTree: IFocusableTree | null, | ||
| ): void { | ||
| if (node !== this) { | ||
| // Only select the item if it isn't already selected so as to not toggle. | ||
| if (this.getSelectedItem() !== node) { | ||
| this.setSelectedItem(node as IToolboxItem); | ||
| } | ||
| } else this.clearSelection(); | ||
|
||
| } | ||
|
|
||
| /** See IFocusableTree.onTreeBlur. */ | ||
| onTreeBlur(_nextTree: IFocusableTree | null): void {} | ||
| } | ||
|
|
||
| /** CSS for Toolbox. See css.js for use. */ | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the
else, just do a newline andreturn nullThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.