Skip to content

Commit d5a4522

Browse files
authored
fix: Skip invisible inputs in the field navigation policy (#9092)
* Skip over hidden inputs when navigating from a field * Add tests and fix implementation
1 parent edf344c commit d5a4522

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

core/keyboard_nav/field_navigation_policy.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ export class FieldNavigationPolicy implements INavigationPolicy<Field<any>> {
4848
let fieldIdx = input.fieldRow.indexOf(current) + 1;
4949
for (let i = curIdx; i < block.inputList.length; i++) {
5050
const newInput = block.inputList[i];
51-
const fieldRow = newInput.fieldRow;
52-
if (fieldIdx < fieldRow.length) return fieldRow[fieldIdx];
53-
fieldIdx = 0;
54-
if (newInput.connection?.targetBlock()) {
55-
return newInput.connection.targetBlock() as BlockSvg;
51+
if (newInput.isVisible()) {
52+
const fieldRow = newInput.fieldRow;
53+
if (fieldIdx < fieldRow.length) return fieldRow[fieldIdx];
54+
if (newInput.connection?.targetBlock()) {
55+
return newInput.connection.targetBlock() as BlockSvg;
56+
}
5657
}
58+
fieldIdx = 0;
5759
}
5860
return null;
5961
}
@@ -73,12 +75,13 @@ export class FieldNavigationPolicy implements INavigationPolicy<Field<any>> {
7375
let fieldIdx = parentInput.fieldRow.indexOf(current) - 1;
7476
for (let i = curIdx; i >= 0; i--) {
7577
const input = block.inputList[i];
76-
if (input.connection?.targetBlock() && input !== parentInput) {
77-
return input.connection.targetBlock() as BlockSvg;
78+
if (input.isVisible()) {
79+
if (input.connection?.targetBlock() && input !== parentInput) {
80+
return input.connection.targetBlock() as BlockSvg;
81+
}
82+
const fieldRow = input.fieldRow;
83+
if (fieldIdx > -1) return fieldRow[fieldIdx];
7884
}
79-
const fieldRow = input.fieldRow;
80-
if (fieldIdx > -1) return fieldRow[fieldIdx];
81-
8285
// Reset the fieldIdx to the length of the field row of the previous
8386
// input.
8487
if (i - 1 >= 0) {

tests/mocha/navigation_test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,13 @@ suite('Navigation', function () {
534534
const nextNode = this.navigator.getNextSibling(this.blocks.buttonBlock);
535535
assert.equal(nextNode.id, this.blocks.buttonNext.id);
536536
});
537+
test('fromFieldSkipsHiddenInputs', function () {
538+
this.blocks.buttonBlock.inputList[2].setVisible(false);
539+
const fieldStart = this.blocks.buttonBlock.getField('BUTTON2');
540+
const fieldEnd = this.blocks.buttonBlock.getField('BUTTON3');
541+
const nextNode = this.navigator.getNextSibling(fieldStart);
542+
assert.equal(nextNode.name, fieldEnd.name);
543+
});
537544
});
538545

539546
suite('Previous', function () {
@@ -669,6 +676,13 @@ suite('Navigation', function () {
669676
);
670677
assert.equal(prevNode.id, this.blocks.buttonBlock.id);
671678
});
679+
test('fromFieldSkipsHiddenInputs', function () {
680+
this.blocks.buttonBlock.inputList[2].setVisible(false);
681+
const fieldStart = this.blocks.buttonBlock.getField('BUTTON3');
682+
const fieldEnd = this.blocks.buttonBlock.getField('BUTTON2');
683+
const nextNode = this.navigator.getPreviousSibling(fieldStart);
684+
assert.equal(nextNode.name, fieldEnd.name);
685+
});
672686
});
673687

674688
suite('In', function () {

0 commit comments

Comments
 (0)