8000 refactor: Make INavigable extend IFocusableNode. by gonfunko · Pull Request #9033 · google/blockly · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor: Make INavigable extend IFocusableNode. #9033

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
merged 3 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions core/block_svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1824,15 +1824,6 @@ export class BlockSvg
return true;
}

/**
* Returns whether or not this block can be navigated to via the keyboard.
*
* @returns True if this block is keyboard navigable, otherwise false.
*/
isNavigable() {
return true;
}

/**
* Returns this block's class.
*
Expand Down
14 changes: 0 additions & 14 deletions core/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1385,20 +1385,6 @@ export abstract class Field<T = any>
);
}

/**
* Returns whether or not this field is accessible by keyboard navigation.
*
* @returns True if this field is keyboard accessible, otherwise false.
*/
isNavigable() {
return (
this.isClickable() &&
this.isCurrentlyEditable() &&
!(this.getSourceBlock()?.isSimpleReporter() && this.isFullBlockField()) &&
this.getParentInput().isVisible()
);
}

/**
* Returns this field's class.
*
Expand Down
10 changes: 0 additions & 10 deletions core/flyout_button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,16 +413,6 @@ export class FlyoutButton
return true;
}

/**
* Returns whether or not this button is accessible through keyboard
* navigation.
*
* @returns True if this button is keyboard accessible, otherwise false.
*/
isNavigable() {
return true;
}

/**
* Returns this button's class.
*
Expand Down
25 changes: 24 additions & 1 deletion core/flyout_separator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
*/

import type {IBoundedElement} from './interfaces/i_bounded_element.js';
import type {IFocusableNode} from './interfaces/i_focusable_node.js';
import type {IFocusableTree} from './interfaces/i_focusable_tree.js';
import type {INavigable} from './interfaces/i_navigable.js';
import {Rect} from './utils/rect.js';

/**
* Representation of a gap between elements in a flyout.
*/
export class FlyoutSeparator
implements IBoundedElement, INavigable<FlyoutSeparator>
implements IBoundedElement, INavigable<FlyoutSeparator>, IFocusableNode
{
private x = 0;
private y = 0;
Expand Down Expand Up @@ -75,6 +77,27 @@ export class FlyoutSeparator
getClass() {
return FlyoutSeparator;
}

/** See IFocusableNode.getFocusableElement. */
getFocusableElement(): HTMLElement | SVGElement {
throw new Error('Cannot be focused');
}

/** See IFocusableNode.getFocusableTree. */
getFocusableTree(): IFocusableTree {
throw new Error('Cannot be focused');
}

/** See IFocusableNode.onNodeFocus. */
onNodeFocus(): void {}

/** See IFocusableNode.onNodeBlur. */
onNodeBlur(): void {}

/** See IFocusableNode.canBeFocused. */
canBeFocused(): boolean {
return false;
}
}

/**
Expand Down
18 changes: 3 additions & 15 deletions core/interfaces/i_navigable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,12 @@
* SPDX-License-Identifier: Apache-2.0
*/

import type {IFocusableNode} from './i_focusable_node.js';

/**
* Represents a UI element which can be navigated to using the keyboard.
*/
export interface INavigable<T> {
/**
* Returns whether or not this specific instance should be reachable via
* keyboard navigation.
*
* Implementors should generally return true, unless there are circumstances
* under which this item should be skipped while using keyboard navigation.
* Common examples might include being disabled, invalid, readonly, or purely
* a visual decoration. For example, while Fields are navigable, non-editable
* fields return false, since they cannot be interacted with when focused.
*
* @returns True if this element should be included in keyboard navigation.
*/
isNavigable(): boolean;

export interface INavigable<T> extends IFocusableNode {
/**
* Returns the class of this instance.
*
Expand Down
14 changes: 14 additions & 0 deletions core/interfaces/i_navigation_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,18 @@ export interface INavigationPolicy<T> {
* there is none.
*/
getPreviousSibling(current: T): INavigable<any> | null;

/**
* Returns whether or not the given instance should be reachable via keyboard
* navigation.
*
* Implementors should generally return true, unless there are circumstances
* under which this item should be skipped while using keyboard navigation.
* Common examples might include being disabled, invalid, readonly, or purely
* a visual decoration. For example, while Fields are navigable, non-editable
* fields return false, since they cannot be interacted with when focused.
*
* @returns True if this element should be included in keyboard navigation.
*/
isNavigable(current: T): boolean;
}
10 changes: 10 additions & 0 deletions core/keyboard_nav/block_navigation_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,14 @@ export class BlockNavigationPolicy implements INavigationPolicy<BlockSvg> {
}
return block.outputConnection;
}

/**
* Returns whether or not the given block can be navigated to.
*
* @param current The instance to check for navigability.
* @returns True if the given block can be focused.
*/
isNavigable(current: BlockSvg): boolean {
return current.canBeFocused();
}
}
10 changes: 10 additions & 0 deletions core/keyboard_nav/connection_navigation_policy.ts