Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Do not select first child if no "propagateFocus" set
Browse files Browse the repository at this point in the history
  • Loading branch information
asgvard committed Feb 22, 2019
1 parent 81ddc43 commit 0773091
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 36 deletions.
24 changes: 5 additions & 19 deletions dist/spatialNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,24 +247,24 @@ var SpatialNavigation = function () {
/**
* Security check, if component doesn't exist, stay on the same focusKey
*/
if (!targetFocusKey) {
if (!targetComponent) {
return targetFocusKey;
}

var children = (0, _filter2.default)(this.focusableComponents, function (component) {
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
*/
var lastFocusedChildKey = targetComponent.lastFocusedChildKey;


if (lastFocusedChildKey && !targetComponent.forgetLastFocusedChild && this.isFocusableComponent(lastFocusedChildKey)) {
this.onIntermediateNodeBecameFocused(targetFocusKey);

return this.getNextFocusKey(lastFocusedChildKey);
}

Expand All @@ -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);
}

/**
Expand Down
22 changes: 5 additions & 17 deletions src/spatialNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,22 +196,22 @@ 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
*/
const {lastFocusedChildKey} = targetComponent;

if (lastFocusedChildKey && !targetComponent.forgetLastFocusedChild &&
this.isFocusableComponent(lastFocusedChildKey)) {
this.onIntermediateNodeBecameFocused(targetFocusKey);

return this.getNextFocusKey(lastFocusedChildKey);
}

Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 0773091

Please sign in to comment.