@enact/spotlight 5.2.1 → 5.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/package.json +2 -2
- package/src/container.js +3 -5
- package/src/target.js +52 -1
- package/src/tests/target-specs.js +81 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
The following is a curated list of changes in the Enact spotlight module, newest changes on the top.
|
|
4
4
|
|
|
5
|
+
## [5.3.1] - 2025-10-14
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- `spotlight` navigation from an element to a different container
|
|
10
|
+
|
|
11
|
+
## [5.3.0] - 2025-09-24
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- `spotlight` to not prioritize elements which are invisible due to overflow as next spottable elements
|
|
16
|
+
|
|
5
17
|
## [5.2.1] - 2025-09-02
|
|
6
18
|
|
|
7
19
|
### Fixed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enact/spotlight",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.1",
|
|
4
4
|
"description": "A focus management library",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@enact/core": "^5.
|
|
28
|
+
"@enact/core": "^5.3.1",
|
|
29
29
|
"classnames": "^2.5.1",
|
|
30
30
|
"prop-types": "^15.8.1",
|
|
31
31
|
"ramda": "^0.31.3",
|
package/src/container.js
CHANGED
|
@@ -378,25 +378,23 @@ var getSpottableDescendants = exports.getSpottableDescendants = function getSpot
|
|
|
378
378
|
|
|
379
379
|
/**
|
|
380
380
|
* Recursively get spottable descendants by including elements within sub-containers that do not
|
|
381
|
-
* have `enterTo` configured
|
|
381
|
+
* have `enterTo` configured
|
|
382
382
|
*
|
|
383
383
|
* @param {String} containerId ID of container
|
|
384
384
|
* @param {String[]} [excludedContainers] IDs of containers to exclude from result set
|
|
385
|
-
* @param {Boolean} useLastFocusedElement Determines whether to use the last focused element
|
|
386
385
|
*
|
|
387
386
|
* @returns {Node[]} Array of spottable elements and containers
|
|
388
387
|
* @memberof spotlight/container
|
|
389
388
|
* @private
|
|
390
389
|
*/
|
|
391
|
-
var _getDeepSpottableDescendants = exports.getDeepSpottableDescendants = function getDeepSpottableDescendants(containerId, excludedContainers
|
|
390
|
+
var _getDeepSpottableDescendants = exports.getDeepSpottableDescendants = function getDeepSpottableDescendants(containerId, excludedContainers) {
|
|
392
391
|
return getSpottableDescendants(containerId).map(function (n) {
|
|
393
392
|
if (isContainer(n)) {
|
|
394
393
|
var id = getContainerId(n);
|
|
395
394
|
var config = getContainerConfig(id);
|
|
396
|
-
var hasSpottedControl = getContainerLastFocusedElement(id);
|
|
397
395
|
if (excludedContainers && excludedContainers.indexOf(id) >= 0) {
|
|
398
396
|
return [];
|
|
399
|
-
} else if (config && !config.enterTo
|
|
397
|
+
} else if (config && !config.enterTo) {
|
|
400
398
|
return _getDeepSpottableDescendants(id, excludedContainers);
|
|
401
399
|
}
|
|
402
400
|
}
|
package/src/target.js
CHANGED
|
@@ -193,6 +193,22 @@ function getTargetInContainerByDirectionFromPosition(direction, containerId, pos
|
|
|
193
193
|
return 0; // continue
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
+
var nextCandidateContainerId = (0, _container.getContainersForNode)(next).pop();
|
|
197
|
+
// check if we want to navigate to another container
|
|
198
|
+
if (next && containerId !== nextCandidateContainerId) {
|
|
199
|
+
// verify is the element from another container is visible
|
|
200
|
+
if (isElementVisibleInContainer(next, nextCandidateContainerId)) {
|
|
201
|
+
return {
|
|
202
|
+
v: next
|
|
203
|
+
};
|
|
204
|
+
} else {
|
|
205
|
+
// otherwise, try to navigate to an element that is visible in its container
|
|
206
|
+
next = (0, _navigate["default"])(positionRect, direction, elementRects.filter(function (rect) {
|
|
207
|
+
var elementContainerId = (0, _container.getContainersForNode)(rect.element).pop();
|
|
208
|
+
return isElementVisibleInContainer(rect.element, elementContainerId);
|
|
209
|
+
}), (0, _container.getContainerConfig)(containerId));
|
|
210
|
+
}
|
|
211
|
+
}
|
|
196
212
|
|
|
197
213
|
// If we've met every condition and haven't explicitly retried the search via `continue`,
|
|
198
214
|
// break out and return
|
|
@@ -203,6 +219,7 @@ function getTargetInContainerByDirectionFromPosition(direction, containerId, pos
|
|
|
203
219
|
_ret = _loop();
|
|
204
220
|
if (_ret === 0) continue;
|
|
205
221
|
if (_ret === 1) break;
|
|
222
|
+
if (_ret) return _ret.v;
|
|
206
223
|
}
|
|
207
224
|
return next;
|
|
208
225
|
}
|
|
@@ -270,7 +287,9 @@ function getTargetInContainerByDirectionFromElement(direction, containerId, elem
|
|
|
270
287
|
|
|
271
288
|
// and it is restricted, return its target
|
|
272
289
|
if (isRestrictedContainer(nextContainerId)) {
|
|
273
|
-
|
|
290
|
+
return {
|
|
291
|
+
v: getTargetByContainer(nextContainerId)
|
|
292
|
+
};
|
|
274
293
|
} else {
|
|
275
294
|
// otherwise, recurse into it
|
|
276
295
|
next = getTargetInContainerByDirectionFromElement(direction, nextContainerId, element, elementRect, elementContainerIds, getOverflowContainerRect(nextContainerId) || boundingRect);
|
|
@@ -282,6 +301,22 @@ function getTargetInContainerByDirectionFromElement(direction, containerId, elem
|
|
|
282
301
|
return 0; // continue
|
|
283
302
|
}
|
|
284
303
|
}
|
|
304
|
+
var nextCandidateContainerId = (0, _container.getContainersForNode)(next).pop();
|
|
305
|
+
// check if we want to navigate to another container
|
|
306
|
+
if (next && containerId !== nextCandidateContainerId) {
|
|
307
|
+
// verify is the element from another container is visible
|
|
308
|
+
if (isElementVisibleInContainer(next, nextCandidateContainerId)) {
|
|
309
|
+
return {
|
|
310
|
+
v: next
|
|
311
|
+
};
|
|
312
|
+
} else {
|
|
313
|
+
// otherwise, try to navigate to an element that is visible in its container
|
|
314
|
+
next = (0, _navigate["default"])(elementRect, direction, elementRects.filter(function (rect) {
|
|
315
|
+
var elementContainerId = (0, _container.getContainersForNode)(rect.element).pop();
|
|
316
|
+
return isElementVisibleInContainer(rect.element, elementContainerId);
|
|
317
|
+
}), (0, _container.getContainerConfig)(containerId), partitionRect);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
285
320
|
|
|
286
321
|
// If we've met every condition and haven't explicitly retried the search via `continue`,
|
|
287
322
|
// break out and return
|
|
@@ -292,6 +327,7 @@ function getTargetInContainerByDirectionFromElement(direction, containerId, elem
|
|
|
292
327
|
_ret2 = _loop2();
|
|
293
328
|
if (_ret2 === 0) continue;
|
|
294
329
|
if (_ret2 === 1) break;
|
|
330
|
+
if (_ret2) return _ret2.v;
|
|
295
331
|
}
|
|
296
332
|
return next;
|
|
297
333
|
}
|
|
@@ -374,6 +410,21 @@ function getNavigableTarget(target) {
|
|
|
374
410
|
}
|
|
375
411
|
return target;
|
|
376
412
|
}
|
|
413
|
+
function isElementVisibleInContainer(element, containerId) {
|
|
414
|
+
var _getContainerRect = (0, _utils.getContainerRect)(containerId),
|
|
415
|
+
containerTop = _getContainerRect.top,
|
|
416
|
+
containerRight = _getContainerRect.right,
|
|
417
|
+
containerBottom = _getContainerRect.bottom,
|
|
418
|
+
containerLeft = _getContainerRect.left;
|
|
419
|
+
var _element$getBoundingC = element.getBoundingClientRect(),
|
|
420
|
+
elementTop = _element$getBoundingC.top,
|
|
421
|
+
elementRight = _element$getBoundingC.right,
|
|
422
|
+
elementBottom = _element$getBoundingC.bottom,
|
|
423
|
+
elementLeft = _element$getBoundingC.left;
|
|
424
|
+
var isVerticallyVisible = elementBottom >= containerTop && elementTop <= containerBottom;
|
|
425
|
+
var isHorizontallyVisible = elementRight >= containerLeft && elementLeft <= containerRight;
|
|
426
|
+
return isVerticallyVisible && isHorizontallyVisible;
|
|
427
|
+
}
|
|
377
428
|
var getOffsetDistanceToTargetFromPosition = function getOffsetDistanceToTargetFromPosition(distance, direction, _ref, _ref2) {
|
|
378
429
|
var x = _ref.x,
|
|
379
430
|
y = _ref.y;
|
|
@@ -587,4 +587,85 @@ describe('target', function () {
|
|
|
587
587
|
})).toBe('below');
|
|
588
588
|
}));
|
|
589
589
|
});
|
|
590
|
+
describe('#directional visibility across containers', function () {
|
|
591
|
+
test('should skip invisible target in another container and select a visible one', (0, _utils.testScenario)(scenarios.overflow, function (root) {
|
|
592
|
+
(0, _container10.configureContainer)('overflow-container', {
|
|
593
|
+
overflow: true
|
|
594
|
+
});
|
|
595
|
+
var overflowContainer = root.querySelector("[".concat(_container10.containerAttribute, "='overflow-container']"));
|
|
596
|
+
var outside = root.querySelector('#outside-overflow');
|
|
597
|
+
var above = root.querySelector('#overflow-above');
|
|
598
|
+
var within = root.querySelector('#overflow-within');
|
|
599
|
+
var below = root.querySelector('#overflow-below');
|
|
600
|
+
overflowContainer.getBoundingClientRect = function () {
|
|
601
|
+
return {
|
|
602
|
+
top: 0,
|
|
603
|
+
left: 0,
|
|
604
|
+
bottom: 30,
|
|
605
|
+
right: 30,
|
|
606
|
+
width: 30,
|
|
607
|
+
height: 30
|
|
608
|
+
};
|
|
609
|
+
};
|
|
610
|
+
outside.getBoundingClientRect = function () {
|
|
611
|
+
return {
|
|
612
|
+
top: -20,
|
|
613
|
+
left: 0,
|
|
614
|
+
bottom: -10,
|
|
615
|
+
right: 10,
|
|
616
|
+
width: 10,
|
|
617
|
+
height: 10
|
|
618
|
+
};
|
|
619
|
+
};
|
|
620
|
+
above.getBoundingClientRect = function () {
|
|
621
|
+
return {
|
|
622
|
+
top: -10,
|
|
623
|
+
left: 0,
|
|
624
|
+
bottom: -5,
|
|
625
|
+
right: 10,
|
|
626
|
+
width: 10,
|
|
627
|
+
height: 10
|
|
628
|
+
};
|
|
629
|
+
};
|
|
630
|
+
within.getBoundingClientRect = function () {
|
|
631
|
+
return {
|
|
632
|
+
top: 0,
|
|
633
|
+
left: 0,
|
|
634
|
+
bottom: 10,
|
|
635
|
+
right: 10,
|
|
636
|
+
width: 10,
|
|
637
|
+
height: 10
|
|
638
|
+
};
|
|
639
|
+
};
|
|
640
|
+
below.getBoundingClientRect = function () {
|
|
641
|
+
return {
|
|
642
|
+
top: 30,
|
|
643
|
+
left: 0,
|
|
644
|
+
bottom: 40,
|
|
645
|
+
right: 10,
|
|
646
|
+
width: 10,
|
|
647
|
+
height: 10
|
|
648
|
+
};
|
|
649
|
+
};
|
|
650
|
+
var _outside$getBoundingC = outside.getBoundingClientRect(),
|
|
651
|
+
left = _outside$getBoundingC.left,
|
|
652
|
+
right = _outside$getBoundingC.right,
|
|
653
|
+
top = _outside$getBoundingC.top,
|
|
654
|
+
bottom = _outside$getBoundingC.bottom;
|
|
655
|
+
var x = (left + right) / 2;
|
|
656
|
+
var y = (top + bottom) / 2;
|
|
657
|
+
var expected = 'overflow-within';
|
|
658
|
+
var actualFromPosition = safeTarget((0, _target.getTargetByDirectionFromPosition)('down', {
|
|
659
|
+
x: x,
|
|
660
|
+
y: y
|
|
661
|
+
}, _container10.rootContainerId), function (t) {
|
|
662
|
+
return t.id;
|
|
663
|
+
});
|
|
664
|
+
var actualFromElement = safeTarget((0, _target.getTargetByDirectionFromElement)('down', outside), function (t) {
|
|
665
|
+
return t.id;
|
|
666
|
+
});
|
|
667
|
+
expect(actualFromPosition).toBe(expected);
|
|
668
|
+
expect(actualFromElement).toBe(expected);
|
|
669
|
+
}));
|
|
670
|
+
});
|
|
590
671
|
});
|