@enact/spotlight 5.1.0 → 5.2.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 CHANGED
@@ -2,6 +2,22 @@
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.2.1] - 2025-09-02
6
+
7
+ ### Fixed
8
+
9
+ - `spotlight` to preserve the last focused element on component unmount
10
+
11
+ ## [5.2.0] - 2025-08-08
12
+
13
+ ### Added
14
+
15
+ - `spotlight` methods `getPausedInstance` to get the name of the paused instance
16
+
17
+ ### Fixed
18
+
19
+ - `spotlight` to not prioritize elements which are invisible due to overflow as next spottable elements
20
+
5
21
  ## [5.1.0] - 2025-07-11
6
22
 
7
23
  No significant changes.
package/Pause/Pause.js CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = exports.Pause = void 0;
7
+ exports.getPausedInstance = getPausedInstance;
7
8
  exports.isPaused = isPaused;
8
9
  exports.pause = pause;
9
10
  exports.resume = _resume;
@@ -61,6 +62,9 @@ var paused = false;
61
62
 
62
63
  // Private, exported methods used by Spotlight to set and query the pause state from its public API
63
64
 
65
+ function getPausedInstance() {
66
+ return paused === false ? null : paused.name;
67
+ }
64
68
  function pause() {
65
69
  paused = true;
66
70
  }
@@ -64,4 +64,11 @@ describe('Pause', function () {
64
64
  var actual = subject.toString();
65
65
  expect(actual).toBe(expected);
66
66
  });
67
+ test('should return the name of the pause instance when Spotlight is paused', function () {
68
+ var subject = new _Pause["default"]('paused');
69
+ subject.pause();
70
+ var expected = 'paused';
71
+ var actual = (0, _Pause.getPausedInstance)();
72
+ expect(actual).toBe(expected);
73
+ });
67
74
  });
@@ -54,7 +54,7 @@ describe('Spottable', function () {
54
54
  unmount();
55
55
  var expected = 1;
56
56
  expect(spy).toHaveBeenCalledTimes(expected);
57
- expect(spy).toBeCalledWith({
57
+ expect(spy).toHaveBeenCalledWith({
58
58
  type: 'onSpotlightDisappear'
59
59
  });
60
60
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enact/spotlight",
3
- "version": "5.1.0",
3
+ "version": "5.2.1",
4
4
  "description": "A focus management library",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,10 +25,10 @@
25
25
  }
26
26
  },
27
27
  "dependencies": {
28
- "@enact/core": "^5.1.0",
28
+ "@enact/core": "^5.2.1",
29
29
  "classnames": "^2.5.1",
30
30
  "prop-types": "^15.8.1",
31
- "ramda": "^0.30.1",
31
+ "ramda": "^0.31.3",
32
32
  "react": "^19.1.0",
33
33
  "react-dom": "^19.1.0",
34
34
  "warning": "^4.0.3"
package/src/container.js CHANGED
@@ -378,23 +378,25 @@ 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 or which are not hidden due to overflow
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
+ * @param {Boolean} useLastFocusedElement Determines whether to use the last focused element
385
386
  *
386
- * @returns {Node[]} Array of spottable elements and containers
387
+ * @returns {Node[]} Array of spottable elements and containers
387
388
  * @memberof spotlight/container
388
389
  * @private
389
390
  */
390
- var _getDeepSpottableDescendants = exports.getDeepSpottableDescendants = function getDeepSpottableDescendants(containerId, excludedContainers) {
391
+ var _getDeepSpottableDescendants = exports.getDeepSpottableDescendants = function getDeepSpottableDescendants(containerId, excludedContainers, useLastFocusedElement) {
391
392
  return getSpottableDescendants(containerId).map(function (n) {
392
393
  if (isContainer(n)) {
393
394
  var id = getContainerId(n);
394
395
  var config = getContainerConfig(id);
396
+ var hasSpottedControl = getContainerLastFocusedElement(id);
395
397
  if (excludedContainers && excludedContainers.indexOf(id) >= 0) {
396
398
  return [];
397
- } else if (config && !config.enterTo) {
399
+ } else if (config && !config.enterTo && (useLastFocusedElement || !hasSpottedControl || hasSpottedControl && !config.overflow)) {
398
400
  return _getDeepSpottableDescendants(id, excludedContainers);
399
401
  }
400
402
  }
@@ -858,7 +860,7 @@ function persistLastFocusedElement(containerId) {
858
860
  if (cfg) {
859
861
  var lastFocusedElement = cfg.lastFocusedElement;
860
862
  if (lastFocusedElement) {
861
- var all = _getDeepSpottableDescendants(containerId);
863
+ var all = _getDeepSpottableDescendants(containerId, [], true);
862
864
  var lastFocusedKey = cfg.lastFocusedPersist(lastFocusedElement, all);
863
865
 
864
866
  // store lastFocusedKey and release node reference to lastFocusedElement
@@ -881,7 +883,7 @@ function persistLastFocusedElement(containerId) {
881
883
  function restoreLastFocusedElement(containerId) {
882
884
  var cfg = getContainerConfig(containerId);
883
885
  if (cfg && cfg.lastFocusedKey) {
884
- var all = _getDeepSpottableDescendants(containerId);
886
+ var all = _getDeepSpottableDescendants(containerId, [], true);
885
887
  var lastFocusedElement = cfg.lastFocusedRestore(cfg.lastFocusedKey, all);
886
888
 
887
889
  // restore lastFocusedElement and release lastFocusedKey
@@ -89,6 +89,10 @@ element selector may be supplied as the starting point.
89
89
  contained within the current container then the active container will not be updated.
90
90
  */
91
91
  setActiveContainer(containerId?: string): void;
92
+ /**
93
+ * Get the name of the instance.
94
+ */
95
+ getPausedInstance(): string;
92
96
  /**
93
97
  * Gets the current pointer mode
94
98
  */
package/src/spotlight.js CHANGED
@@ -726,6 +726,14 @@ var Spotlight = exports.Spotlight = function () {
726
726
  (0, _container.setLastContainer)(containerId || _container.rootContainerId);
727
727
  }
728
728
  },
729
+ /**
730
+ * Get the name of the instance.
731
+ *
732
+ * @function
733
+ * @returns {String} the name of the instance.
734
+ * @public
735
+ */
736
+ getPausedInstance: _Pause.getPausedInstance,
729
737
  /**
730
738
  * Gets the current pointer mode
731
739
  *
@@ -51,39 +51,39 @@ describe('Spotlight', function () {
51
51
  test('should focus spottable by id', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
52
52
  var fn = mockFocus(root.querySelector('[data-spotlight-id="s1"]'));
53
53
  _spotlight["default"].focus('s1');
54
- expect(fn).toBeCalled();
54
+ expect(fn).toHaveBeenCalled();
55
55
  }));
56
56
  test('should focus container by id', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
57
57
  (0, _container4.configureContainer)('first-container');
58
58
  var fn = mockFocus(root.querySelector('[data-spotlight-id="first-container"] > .spottable'));
59
59
  _spotlight["default"].focus('first-container');
60
- expect(fn).toBeCalled();
60
+ expect(fn).toHaveBeenCalled();
61
61
  }));
62
62
  test('should focus spottable by node', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
63
63
  var n = root.querySelector('[data-spotlight-id="s1"]');
64
64
  var fn = mockFocus(n);
65
65
  _spotlight["default"].focus(n);
66
- expect(fn).toBeCalled();
66
+ expect(fn).toHaveBeenCalled();
67
67
  }));
68
68
  test('should focus container by node', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
69
69
  (0, _container4.configureContainer)('first-container');
70
70
  var n = root.querySelector('[data-spotlight-id="first-container"]');
71
71
  var fn = mockFocus(n.querySelector('.spottable'));
72
72
  _spotlight["default"].focus(n);
73
- expect(fn).toBeCalled();
73
+ expect(fn).toHaveBeenCalled();
74
74
  }));
75
75
  test('should focus spottable by selector', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
76
76
  var n = root.querySelector('[data-spotlight-id="s1"]');
77
77
  var fn = mockFocus(n);
78
78
  _spotlight["default"].focus('[data-spotlight-id="s1"]');
79
- expect(fn).toBeCalled();
79
+ expect(fn).toHaveBeenCalled();
80
80
  }));
81
81
  test('should focus container by selector', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
82
82
  (0, _container4.configureContainer)('first-container');
83
83
  var n = root.querySelector('[data-spotlight-id="first-container"]');
84
84
  var fn = mockFocus(n.querySelector('.spottable'));
85
85
  _spotlight["default"].focus('[data-spotlight-id="first-container"]');
86
- expect(fn).toBeCalled();
86
+ expect(fn).toHaveBeenCalled();
87
87
  }));
88
88
  test('should pass preventScroll option', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
89
89
  var fn = mockFocus(root.querySelector('[data-spotlight-id="s1"]'));
@@ -112,12 +112,12 @@ describe('Spotlight', function () {
112
112
  });
113
113
  test('should register event listener of several event types', function () {
114
114
  _spotlight["default"].initialize();
115
- expect(window.addEventListener).toBeCalledWith('blur', expect.any(Function));
116
- expect(window.addEventListener).toBeCalledWith('focus', expect.any(Function));
117
- expect(window.addEventListener).toBeCalledWith('keydown', expect.any(Function));
118
- expect(window.addEventListener).toBeCalledWith('keyup', expect.any(Function));
119
- expect(window.addEventListener).toBeCalledWith('mouseover', expect.any(Function));
120
- expect(window.addEventListener).toBeCalledWith('mousemove', expect.any(Function));
115
+ expect(window.addEventListener).toHaveBeenCalledWith('blur', expect.any(Function));
116
+ expect(window.addEventListener).toHaveBeenCalledWith('focus', expect.any(Function));
117
+ expect(window.addEventListener).toHaveBeenCalledWith('keydown', expect.any(Function));
118
+ expect(window.addEventListener).toHaveBeenCalledWith('keyup', expect.any(Function));
119
+ expect(window.addEventListener).toHaveBeenCalledWith('mouseover', expect.any(Function));
120
+ expect(window.addEventListener).toHaveBeenCalledWith('mousemove', expect.any(Function));
121
121
  });
122
122
  });
123
123
  describe('#terminate', function () {
@@ -129,12 +129,12 @@ describe('Spotlight', function () {
129
129
  });
130
130
  test('should remove event listener of several event types', function () {
131
131
  _spotlight["default"].terminate();
132
- expect(window.removeEventListener).toBeCalledWith('blur', expect.any(Function));
133
- expect(window.removeEventListener).toBeCalledWith('focus', expect.any(Function));
134
- expect(window.removeEventListener).toBeCalledWith('keydown', expect.any(Function));
135
- expect(window.removeEventListener).toBeCalledWith('keyup', expect.any(Function));
136
- expect(window.removeEventListener).toBeCalledWith('mouseover', expect.any(Function));
137
- expect(window.removeEventListener).toBeCalledWith('mousemove', expect.any(Function));
132
+ expect(window.removeEventListener).toHaveBeenCalledWith('blur', expect.any(Function));
133
+ expect(window.removeEventListener).toHaveBeenCalledWith('focus', expect.any(Function));
134
+ expect(window.removeEventListener).toHaveBeenCalledWith('keydown', expect.any(Function));
135
+ expect(window.removeEventListener).toHaveBeenCalledWith('keyup', expect.any(Function));
136
+ expect(window.removeEventListener).toHaveBeenCalledWith('mouseover', expect.any(Function));
137
+ expect(window.removeEventListener).toHaveBeenCalledWith('mousemove', expect.any(Function));
138
138
  });
139
139
  });
140
140
  });