From 0773091d47fe5a959e89fd8987d9114409d55b2e Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Fri, 22 Feb 2019 18:01:01 +0100 Subject: [PATCH] Do not select first child if no "propagateFocus" set --- dist/spatialNavigation.js | 24 +++++------------------- src/spatialNavigation.js | 22 +++++----------------- 2 files changed, 10 insertions(+), 36 deletions(-) diff --git a/dist/spatialNavigation.js b/dist/spatialNavigation.js index 0847edd..f6955ae 100644 --- a/dist/spatialNavigation.js +++ b/dist/spatialNavigation.js @@ -247,7 +247,7 @@ var SpatialNavigation = function () { /** * Security check, if component doesn't exist, stay on the same focusKey */ - if (!targetFocusKey) { + if (!targetComponent) { return targetFocusKey; } @@ -255,7 +255,9 @@ var SpatialNavigation = function () { return component.parentFocusKey === targetFocusKey; }); - if (children.length > 0) { + if (children.length > 0 && this.isPropagateFocus(targetFocusKey)) { + this.onIntermediateNodeBecameFocused(targetFocusKey); + /** * First of all trying to focus last focused child */ @@ -263,8 +265,6 @@ var SpatialNavigation = function () { if (lastFocusedChildKey && !targetComponent.forgetLastFocusedChild && this.isFocusableComponent(lastFocusedChildKey)) { - this.onIntermediateNodeBecameFocused(targetFocusKey); - return this.getNextFocusKey(lastFocusedChildKey); } @@ -281,21 +281,7 @@ var SpatialNavigation = function () { var _first = (0, _first3.default)(sortedYChildren), childKey = _first.focusKey; - /** - * If the target node is propagating focus, try to target first child - */ - - - if (this.isPropagateFocus(targetFocusKey)) { - this.onIntermediateNodeBecameFocused(targetFocusKey); - - return this.getNextFocusKey(childKey); - } - - /** - * Otherwise focus first child - */ - return childKey; + return this.getNextFocusKey(childKey); } /** diff --git a/src/spatialNavigation.js b/src/spatialNavigation.js index 718c4b9..acefb30 100644 --- a/src/spatialNavigation.js +++ b/src/spatialNavigation.js @@ -196,13 +196,15 @@ class SpatialNavigation { /** * Security check, if component doesn't exist, stay on the same focusKey */ - if (!targetFocusKey) { + if (!targetComponent) { return targetFocusKey; } const children = filter(this.focusableComponents, (component) => component.parentFocusKey === targetFocusKey); - if (children.length > 0) { + if (children.length > 0 && this.isPropagateFocus(targetFocusKey)) { + this.onIntermediateNodeBecameFocused(targetFocusKey); + /** * First of all trying to focus last focused child */ @@ -210,8 +212,6 @@ class SpatialNavigation { if (lastFocusedChildKey && !targetComponent.forgetLastFocusedChild && this.isFocusableComponent(lastFocusedChildKey)) { - this.onIntermediateNodeBecameFocused(targetFocusKey); - return this.getNextFocusKey(lastFocusedChildKey); } @@ -222,19 +222,7 @@ class SpatialNavigation { const sortedYChildren = sortBy(sortedXChildren, (child) => child.layout.top); const {focusKey: childKey} = first(sortedYChildren); - /** - * If the target node is propagating focus, try to target first child - */ - if (this.isPropagateFocus(targetFocusKey)) { - this.onIntermediateNodeBecameFocused(targetFocusKey); - - return this.getNextFocusKey(childKey); - } - - /** - * Otherwise focus first child - */ - return childKey; + return this.getNextFocusKey(childKey); } /**