Skip to content

Commit 7fe1167

Browse files
committed
Provides an option for finding candidates that contain elements outside of viewport.
Add FocusableAreaOptions parameter for findNextTarget() and findCandidates(). When the current focus is out of viewport because of scrolling, the next candidates may can be elements which is out of screen also.
1 parent a47da55 commit 7fe1167

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

polyfill/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ NOTE: The APIs below are non-standard and experimental features of the spatial n
138138
* Parameter
139139
* element : Required.
140140
- Any element.
141-
* <code>findCandidates (element, dir)</code> :
141+
* <code>findCandidates (element, dir, option)</code> :
142142
* Searchs all valid candidates for a certain direction.
143143
* Returns a list of elements.
144144
* Parameter
@@ -147,7 +147,11 @@ NOTE: The APIs below are non-standard and experimental features of the spatial n
147147
* dir : Required.
148148
- The direction to find candidates.
149149
- It should be one of <code>['up', 'down', 'left', 'right']</code>.
150-
* <code>findNextTarget (element, dir)</code> :
150+
* option : Optional.
151+
- Default value is <code>{'mode': 'visible'}</code>.
152+
- The FocusableAreasOptions to find candidates.
153+
- It should be <code>{'mode': 'visible'}</code> or <code>{ mode: 'all' }</code>.
154+
* <code>findNextTarget (element, dir, option)</code> :
151155
* Indicates what is the best element to move the focus for a certain direction.
152156
* Returns the next target element.
153157
- If there is no target for the direction, it returns <code>null</code>.
@@ -158,6 +162,10 @@ NOTE: The APIs below are non-standard and experimental features of the spatial n
158162
* dir : Required.
159163
- The direction to find candidates.
160164
- It should be one of <code>['up', 'down', 'left', 'right']</code>.
165+
* option : Optional.
166+
- Default value is <code>{'mode': 'visible'}</code>.
167+
- The FocusableAreasOptions to find candidates.
168+
- It should be <code>{'mode': 'visible'}</code> or <code>{ mode: 'all' }</code>.
161169
* <code>getDistanceFromTarget (element, candidateElement, dir)</code> :
162170
* Calculates the distance between the currently focused element and a certain candiate element.
163171
* Parameter

polyfill/spatnav-heuristic.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@
11571157
}
11581158

11591159

1160-
function findTarget(findCandidate, element, dir) {
1160+
function findTarget(findCandidate, element, dir, option) {
11611161
let eventTarget = element;
11621162
let bestNextTarget = null;
11631163

@@ -1174,14 +1174,14 @@
11741174
if (eventTarget.nodeName === 'IFRAME')
11751175
eventTarget = eventTarget.contentDocument.body;
11761176

1177-
const candidates = eventTarget.focusableAreas();
1177+
const candidates = eventTarget.focusableAreas(option);
11781178

11791179
// 5-2
11801180
if (Array.isArray(candidates) && candidates.length > 0) {
11811181
if(findCandidate) {
1182-
return spatNavCandidates(eventTarget, dir);
1182+
return spatNavCandidates(eventTarget, dir, candidates);
11831183
} else {
1184-
bestNextTarget = eventTarget.spatialNavigationSearch(dir);
1184+
bestNextTarget = eventTarget.spatialNavigationSearch(dir, candidates);
11851185
return bestNextTarget;
11861186
}
11871187
}
@@ -1211,13 +1211,13 @@
12111211

12121212
// 7
12131213
while (parentContainer) {
1214-
const candidates = filteredCandidates(eventTarget, container.focusableAreas(), dir, container);
1214+
const candidates = filteredCandidates(eventTarget, container.focusableAreas(option), dir, container);
12151215

12161216
if (Array.isArray(candidates) && candidates.length > 0) {
12171217
bestNextTarget = eventTarget.spatialNavigationSearch(dir, candidates, container);
12181218
if (bestNextTarget) {
12191219
if(findCandidate) {
1220-
return spatNavCandidates(eventTarget, dir, candidates, container);
1220+
return candidates;
12211221
} else {
12221222
return bestNextTarget;
12231223
}
@@ -1266,15 +1266,15 @@
12661266

12671267
if (!parentContainer && container) {
12681268
// Getting out from the current spatnav container
1269-
const candidates = filteredCandidates(eventTarget, container.focusableAreas(), dir, container);
1269+
const candidates = filteredCandidates(eventTarget, container.focusableAreas(option), dir, container);
12701270

12711271
// 9
12721272
if (Array.isArray(candidates) && candidates.length > 0) {
12731273
bestNextTarget = eventTarget.spatialNavigationSearch(dir, candidates, container);
12741274

12751275
if (bestNextTarget) {
12761276
if(findCandidate) {
1277-
return spatNavCandidates(eventTarget, dir, candidates, container);
1277+
return candidates;
12781278
} else {
12791279
return bestNextTarget;
12801280
}

0 commit comments

Comments
 (0)