Skip to content

Commit

Permalink
Rename nodeCanBeArrowed
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesplease committed Jun 21, 2021
1 parent 8856b57 commit e7d8505
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
@@ -1,4 +1,4 @@
import nodeCanBeArrowed from './node-can-be-arrowed';
import nodeCanReceiveIndirectFocus from '../../utils/node-can-receive-indirect-focus';
import { FocusState, Node, Orientation, Direction, Id } from '../../types';

export default function getDefaultNavTarget(
Expand All @@ -24,7 +24,7 @@ export default function getDefaultNavTarget(
const parentsChildren = unfilteredChildren.filter((nodeId) => {
const node = focusState.nodes[nodeId];

if (!nodeCanBeArrowed(focusState, node)) {
if (!nodeCanReceiveIndirectFocus(focusState, node)) {
return false;
}

Expand Down
@@ -1,6 +1,16 @@
import { FocusState, Node } from '../../types';

export default function nodeCanBeArrowed(focusState: FocusState, node?: Node) {
import { FocusState, Node } from '../types';

// "Indirect focus" here means:
// 1. receiving focus when a parent node receives focus, either through LRUD input or through an explicit call
// to `setFocus`
// 2. receiving focus after being mounted
//
// This function ensures that things like disabled nodes don't receive focus when LRUD is input or when they mount.

export default function nodeCanReceiveIndirectFocus(
focusState: FocusState,
node?: Node
) {
if (!node) {
return false;
}
Expand All @@ -21,7 +31,10 @@ export default function nodeCanBeArrowed(focusState: FocusState, node?: Node) {
const childId = children[i];
const childNode = focusState.nodes[childId];

const childCanReceiveFocus = nodeCanBeArrowed(focusState, childNode);
const childCanReceiveFocus = nodeCanReceiveIndirectFocus(
focusState,
childNode
);

if (childCanReceiveFocus) {
someChildIsEnabled = true;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/tree-navigation.ts
@@ -1,6 +1,6 @@
import clamp from './clamp';
import nodeCanReceiveIndirectFocus from './node-can-receive-indirect-focus';
import { FocusState, Id, NodeHierarchy, Orientation } from '../types';
import nodeCanBeArrowed from '../handle-arrow/determine-navigation-style/node-can-be-arrowed';

interface GetParentsOptions {
focusState: FocusState;
Expand Down Expand Up @@ -55,7 +55,7 @@ export function getChildren({
const nodeChildren = node.children.filter((childId) => {
const node = focusState.nodes[childId];

return nodeCanBeArrowed(focusState, node);
return nodeCanReceiveIndirectFocus(focusState, node);
});

let nextPreferredChildren: NodeHierarchy = [];
Expand Down

0 comments on commit e7d8505

Please sign in to comment.