@enact/spotlight 5.2.1 → 5.3.0
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 +6 -0
- package/package.json +2 -2
- package/src/container.js +3 -5
- package/src/target.js +49 -0
- package/src/tests/target-specs.js +81 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
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.0] - 2025-09-24
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- `spotlight` to not prioritize elements which are invisible due to overflow as next spottable elements
|
|
10
|
+
|
|
5
11
|
## [5.2.1] - 2025-09-02
|
|
6
12
|
|
|
7
13
|
### Fixed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enact/spotlight",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
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.0",
|
|
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
|
}
|
|
@@ -282,6 +299,22 @@ function getTargetInContainerByDirectionFromElement(direction, containerId, elem
|
|
|
282
299
|
return 0; // continue
|
|
283
300
|
}
|
|
284
301
|
}
|
|
302
|
+
var nextCandidateContainerId = (0, _container.getContainersForNode)(next).pop();
|
|
303
|
+
// check if we want to navigate to another container
|
|
304
|
+
if (next && containerId !== nextCandidateContainerId) {
|
|
305
|
+
// verify is the element from another container is visible
|
|
306
|
+
if (isElementVisibleInContainer(next, nextCandidateContainerId)) {
|
|
307
|
+
return {
|
|
308
|
+
v: next
|
|
309
|
+
};
|
|
310
|
+
} else {
|
|
311
|
+
// otherwise, try to navigate to an element that is visible in its container
|
|
312
|
+
next = (0, _navigate["default"])(elementRect, direction, elementRects.filter(function (rect) {
|
|
313
|
+
var elementContainerId = (0, _container.getContainersForNode)(rect.element).pop();
|
|
314
|
+
return isElementVisibleInContainer(rect.element, elementContainerId);
|
|
315
|
+
}), (0, _container.getContainerConfig)(containerId), partitionRect);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
285
318
|
|
|
286
319
|
// If we've met every condition and haven't explicitly retried the search via `continue`,
|
|
287
320
|
// break out and return
|
|
@@ -292,6 +325,7 @@ function getTargetInContainerByDirectionFromElement(direction, containerId, elem
|
|
|
292
325
|
_ret2 = _loop2();
|
|
293
326
|
if (_ret2 === 0) continue;
|
|
294
327
|
if (_ret2 === 1) break;
|
|
328
|
+
if (_ret2) return _ret2.v;
|
|
295
329
|
}
|
|
296
330
|
return next;
|
|
297
331
|
}
|
|
@@ -374,6 +408,21 @@ function getNavigableTarget(target) {
|
|
|
374
408
|
}
|
|
375
409
|
return target;
|
|
376
410
|
}
|
|
411
|
+
function isElementVisibleInContainer(element, containerId) {
|
|
412
|
+
var _getContainerRect = (0, _utils.getContainerRect)(containerId),
|
|
413
|
+
containerTop = _getContainerRect.top,
|
|
414
|
+
containerRight = _getContainerRect.right,
|
|
415
|
+
containerBottom = _getContainerRect.bottom,
|
|
416
|
+
containerLeft = _getContainerRect.left;
|
|
417
|
+
var _element$getBoundingC = element.getBoundingClientRect(),
|
|
418
|
+
elementTop = _element$getBoundingC.top,
|
|
419
|
+
elementRight = _element$getBoundingC.right,
|
|
420
|
+
elementBottom = _element$getBoundingC.bottom,
|
|
421
|
+
elementLeft = _element$getBoundingC.left;
|
|
422
|
+
var isVerticallyVisible = elementBottom >= containerTop && elementTop <= containerBottom;
|
|
423
|
+
var isHorizontallyVisible = elementRight >= containerLeft && elementLeft <= containerRight;
|
|
424
|
+
return isVerticallyVisible && isHorizontallyVisible;
|
|
425
|
+
}
|
|
377
426
|
var getOffsetDistanceToTargetFromPosition = function getOffsetDistanceToTargetFromPosition(distance, direction, _ref, _ref2) {
|
|
378
427
|
var x = _ref.x,
|
|
379
428
|
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
|
});
|