Skip to content
Open
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
8 changes: 7 additions & 1 deletion packages/blockly/core/inputs/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,13 @@ export class Input {
getRowId(): string {
const inputs = this.getSourceBlock().inputList;

// The first input in a block has the same ID as its parent block.
// The first visible input shares the block's row id; this also covers
// the collapsed-input placeholder, since every other input is hidden.
if (this === inputs.find((i) => i.isVisible())) {
return (this.getSourceBlock() as BlockSvg).getRowId();
}

// Fallback when inputs[0] itself is hidden.
if (this === inputs[0]) {
return (this.getSourceBlock() as BlockSvg).getRowId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,12 @@ export class BlockNavigationPolicy implements INavigationPolicy<BlockSvg> {
* @returns A list of navigable/focusable children of the given block.
*/
function getBlockNavigationCandidates(block: BlockSvg): IFocusableNode[] {
// Collapsed blocks have no navigable children.
if (block.isCollapsed()) return [];

const candidates: IFocusableNode[] = [];

// Icons and open bubbles are navigable.
for (const icon of block.getIcons()) {
// Icons hidden when the block is collapsed shouldn't be navigable.
if (block.isCollapsed() && !icon.isShownWhenCollapsed()) continue;
candidates.push(icon);
let bubble;
if (
Expand Down
18 changes: 18 additions & 0 deletions packages/blockly/tests/mocha/navigation_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,24 @@ suite('Navigation', function () {
const inNode = this.navigator.getFirstChild(this.blocks.buttonBlock);
assert.isNull(inNode);
});
test('reachesClickableFieldOnCollapsedInput', function () {
// Models a pattern where a clickable field is appended to
// COLLAPSED_INPUT_NAME when the block collapses.
const block = this.blocks.buttonBlock;
block.setCollapsed(true);
const input = block.getInput(Blockly.constants.COLLAPSED_INPUT_NAME);
const expandButton = new Blockly.FieldImage(
'https://www.gstatic.com/codesite/ph/images/star_on.gif',
16,
16,
'expand',
() => {},
);
input.appendField(expandButton);

const inNode = this.navigator.getInNode(block);
assert.equal(inNode, expandButton);
});
});

suite('Out', function () {
Expand Down
Loading