From d4e3d2266d76849a67104529f63927f1e6a916fd Mon Sep 17 00:00:00 2001 From: Ryan Duffy Date: Tue, 16 Jun 2020 15:15:59 -0700 Subject: [PATCH] PLAT-110783: Fix spotlight to trigger onLeaveContainerFail when leaveFor is configured (#2791) * fix container target selection to return null when leaveFor is configured Signed-off-by: Ryan Duffy * change log Signed-off-by: Ryan Duffy * fix change log Signed-off-by: Ryan Duffy --- packages/spotlight/CHANGELOG.md | 6 ++++++ packages/spotlight/src/target.js | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/spotlight/CHANGELOG.md b/packages/spotlight/CHANGELOG.md index 1dee551300..3d94920e8a 100644 --- a/packages/spotlight/CHANGELOG.md +++ b/packages/spotlight/CHANGELOG.md @@ -2,6 +2,12 @@ The following is a curated list of changes in the Enact spotlight module, newest changes on the top. +## [unreleased] + +### Fixed + +- `spotlight` to trigger `onLeaveContainerFail` when `leaveFor` prevents navigation + ## [3.3.0-alpha.12] - 2020-06-15 No significant changes. diff --git a/packages/spotlight/src/target.js b/packages/spotlight/src/target.js index 4fd4a1d050..b44d8c3b27 100644 --- a/packages/spotlight/src/target.js +++ b/packages/spotlight/src/target.js @@ -357,7 +357,7 @@ function getTargetByDirectionFromElement (direction, element) { const elementRect = getRect(element); - return getNavigableContainersForNode(element) + const next = getNavigableContainersForNode(element) .reduceRight((result, containerId, index, elementContainerIds) => { result = result || getTargetInContainerByDirectionFromElement( direction, @@ -380,6 +380,10 @@ function getTargetByDirectionFromElement (direction, element) { return result; }, null); + + // if the reduce above returns the original element, it means it hit a `leaveFor` config that + // prevents navigation so we enforce that here by returning null. + return next !== element ? next : null; } function getTargetByDirectionFromPosition (direction, position, containerId) {