@enact/spotlight 5.2.0 → 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 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.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
+
11
+ ## [5.2.1] - 2025-09-02
12
+
13
+ ### Fixed
14
+
15
+ - `spotlight` to preserve the last focused element on component unmount
16
+
5
17
  ## [5.2.0] - 2025-08-08
6
18
 
7
19
  ### Added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enact/spotlight",
3
- "version": "5.2.0",
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.2.0",
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,12 +378,12 @@ 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 or which are not hidden due to overflow
381
+ * have `enterTo` configured
382
382
  *
383
- * @param {String} containerId ID of container
384
- * @param {String[]} [excludedContainers] IDs of containers to exclude from result set
383
+ * @param {String} containerId ID of container
384
+ * @param {String[]} [excludedContainers] IDs of containers to exclude from result set
385
385
  *
386
- * @returns {Node[]} Array of spottable elements and containers
386
+ * @returns {Node[]} Array of spottable elements and containers
387
387
  * @memberof spotlight/container
388
388
  * @private
389
389
  */
@@ -392,10 +392,9 @@ var _getDeepSpottableDescendants = exports.getDeepSpottableDescendants = functio
392
392
  if (isContainer(n)) {
393
393
  var id = getContainerId(n);
394
394
  var config = getContainerConfig(id);
395
- var hasSpottedControl = getContainerLastFocusedElement(id);
396
395
  if (excludedContainers && excludedContainers.indexOf(id) >= 0) {
397
396
  return [];
398
- } else if (config && !config.enterTo && (!hasSpottedControl || hasSpottedControl && !config.overflow)) {
397
+ } else if (config && !config.enterTo) {
399
398
  return _getDeepSpottableDescendants(id, excludedContainers);
400
399
  }
401
400
  }
@@ -859,7 +858,7 @@ function persistLastFocusedElement(containerId) {
859
858
  if (cfg) {
860
859
  var lastFocusedElement = cfg.lastFocusedElement;
861
860
  if (lastFocusedElement) {
862
- var all = _getDeepSpottableDescendants(containerId);
861
+ var all = _getDeepSpottableDescendants(containerId, [], true);
863
862
  var lastFocusedKey = cfg.lastFocusedPersist(lastFocusedElement, all);
864
863
 
865
864
  // store lastFocusedKey and release node reference to lastFocusedElement
@@ -882,7 +881,7 @@ function persistLastFocusedElement(containerId) {
882
881
  function restoreLastFocusedElement(containerId) {
883
882
  var cfg = getContainerConfig(containerId);
884
883
  if (cfg && cfg.lastFocusedKey) {
885
- var all = _getDeepSpottableDescendants(containerId);
884
+ var all = _getDeepSpottableDescendants(containerId, [], true);
886
885
  var lastFocusedElement = cfg.lastFocusedRestore(cfg.lastFocusedKey, all);
887
886
 
888
887
  // restore lastFocusedElement and release lastFocusedKey
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
  });