@enact/spotlight 5.4.3 → 5.5.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,20 @@
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.5.0] - 2026-05-08
6
+
7
+ ### Added
8
+
9
+ - `spotlight/SpotlightRootDecorator` config `focusEffectClass` and function `setFocusEffectClass` to apply a css class to every spottable component when it receives spotlight focus.
10
+
11
+ ### Changed
12
+
13
+ - `spotlight/Spottable` to reduce redundant work during high-frequency re-renders
14
+
15
+ ### Fixed
16
+
17
+ - `spotlight` to focus visible children of elements which do not have `overflow:true`
18
+
5
19
  ## [5.4.3] - 2026-02-26
6
20
 
7
21
  ### Fixed
@@ -13,6 +13,7 @@ Object.defineProperty(exports, "useSpotlightContainer", {
13
13
  var _handle = _interopRequireWildcard(require("@enact/core/handle"));
14
14
  var _useHandlers = _interopRequireDefault(require("@enact/core/useHandlers"));
15
15
  var _hoc = _interopRequireDefault(require("@enact/core/hoc"));
16
+ var _util = require("@enact/core/util");
16
17
  var _react = require("react");
17
18
  var _propTypes = _interopRequireDefault(require("prop-types"));
18
19
  var _useSpotlightContainer = _interopRequireDefault(require("./useSpotlightContainer"));
@@ -199,6 +200,7 @@ var SpotlightContainerDecorator = exports.SpotlightContainerDecorator = (0, _hoc
199
200
 
200
201
  // eslint-disable-next-line no-shadow
201
202
  function SpotlightContainerDecorator(props) {
203
+ (0, _util.checkPropTypes)(SpotlightContainerDecorator, props);
202
204
  var _props$spotlightDisab = props.spotlightDisabled,
203
205
  spotlightDisabled = _props$spotlightDisab === void 0 ? false : _props$spotlightDisab,
204
206
  spotlightId = props.spotlightId,
@@ -4,6 +4,18 @@ type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
4
4
  type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
5
5
 
6
6
  export interface SpotlightRootDecoratorConfig extends Object {
7
+ /**
8
+ * A CSS class name to apply globally to every spottable component when it receives spotlight focus.
9
+ *
10
+ * This is the declarative equivalent of calling `setFocusEffectClass` imperatively. It acts as
11
+ an app-wide default
12
+ *
13
+ * Example:
14
+ * ```
15
+ const App = SpotlightRootDecorator({focusEffectClass: css.focusClass}, AppBase);
16
+ ```
17
+ */
18
+ focusEffectClass?: string;
7
19
  /**
8
20
  * When `true` , the contents of the component will not receive spotlight focus after being rendered.
9
21
  */
@@ -17,6 +17,12 @@ Object.defineProperty(exports, "getInputType", {
17
17
  return _inputType.getInputType;
18
18
  }
19
19
  });
20
+ Object.defineProperty(exports, "setFocusEffectClass", {
21
+ enumerable: true,
22
+ get: function get() {
23
+ return _focusEffect.setFocusEffectClass;
24
+ }
25
+ });
20
26
  Object.defineProperty(exports, "setInputType", {
21
27
  enumerable: true,
22
28
  get: function get() {
@@ -28,6 +34,7 @@ var _keymap = require("@enact/core/keymap");
28
34
  var _react = require("react");
29
35
  var _Spottable = require("../Spottable");
30
36
  var _container = require("../src/container");
37
+ var _focusEffect = require("../src/focusEffect");
31
38
  var _inputType = require("../src/inputType");
32
39
  var _spotlight = _interopRequireDefault(require("../src/spotlight"));
33
40
  require("./debug.css");
@@ -60,6 +67,23 @@ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf
60
67
  * @memberof spotlight/SpotlightRootDecorator.SpotlightRootDecorator
61
68
  */
62
69
  var defaultConfig = {
70
+ /**
71
+ * A CSS class name to apply globally to every spottable component when it receives spotlight focus.
72
+ *
73
+ * This is the declarative equivalent of calling `setFocusEffectClass` imperatively. It acts as
74
+ * an app-wide default
75
+ *
76
+ * Example:
77
+ * ```js
78
+ * const App = SpotlightRootDecorator({focusEffectClass: css.focusClass}, AppBase);
79
+ * ```
80
+ *
81
+ * @type {String}
82
+ * @default null
83
+ * @public
84
+ * @memberof spotlight/SpotlightRootDecorator.SpotlightRootDecorator.defaultConfig
85
+ */
86
+ focusEffectClass: null,
63
87
  /**
64
88
  * When `true`, the contents of the component will not receive spotlight focus after being rendered.
65
89
  *
@@ -100,7 +124,8 @@ var defaultConfig = {
100
124
  */
101
125
  var SpotlightRootDecorator = exports.SpotlightRootDecorator = (0, _hoc["default"])(defaultConfig, function (config, Wrapped) {
102
126
  var _Class;
103
- var noAutoFocus = config.noAutoFocus,
127
+ var focusEffectClass = config.focusEffectClass,
128
+ noAutoFocus = config.noAutoFocus,
104
129
  rootId = config.rootId;
105
130
  return _Class = /*#__PURE__*/function (_Component) {
106
131
  function _Class(props) {
@@ -149,6 +174,9 @@ var SpotlightRootDecorator = exports.SpotlightRootDecorator = (0, _hoc["default"
149
174
  }
150
175
  };
151
176
  _this.containerNode = null;
177
+ if (focusEffectClass) {
178
+ (0, _focusEffect.setFocusEffectClass)(focusEffectClass);
179
+ }
152
180
  if (typeof window === 'object') {
153
181
  _spotlight["default"].initialize({
154
182
  selector: '.' + _Spottable.spottableClass,
@@ -4,6 +4,7 @@ require("@testing-library/jest-dom");
4
4
  var _react = require("@testing-library/react");
5
5
  var _SpotlightRootDecorator = require("../SpotlightRootDecorator");
6
6
  var _container = require("../../src/container");
7
+ var _focusEffect = require("../../src/focusEffect");
7
8
  var _jsxRuntime = require("react/jsx-runtime");
8
9
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
10
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -38,6 +39,26 @@ describe('SpotlightRootDecorator', function () {
38
39
  var actual = (0, _SpotlightRootDecorator.getInputType)();
39
40
  expect(actual).toBe(expected);
40
41
  });
42
+ test('should export setFocusEffectClass as a function', function () {
43
+ expect(typeof _SpotlightRootDecorator.setFocusEffectClass).toBe('function');
44
+ });
45
+ describe('focusEffectClass config', function () {
46
+ afterEach(function () {
47
+ (0, _SpotlightRootDecorator.setFocusEffectClass)(null);
48
+ });
49
+ test('should call setFocusEffectClass with the configured class on construction', function () {
50
+ var App = (0, _SpotlightRootDecorator.SpotlightRootDecorator)({
51
+ focusEffectClass: 'app-focus-class'
52
+ }, AppBase);
53
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(App, {}));
54
+ expect((0, _focusEffect.getFocusEffectClass)()).toBe('app-focus-class');
55
+ });
56
+ test('should not call setFocusEffectClass when focusEffectClass config is not provided', function () {
57
+ var App = (0, _SpotlightRootDecorator.SpotlightRootDecorator)(AppBase);
58
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(App, {}));
59
+ expect((0, _focusEffect.getFocusEffectClass)()).toBeNull();
60
+ });
61
+ });
41
62
  test('should set spotlightRootDecorator container enterTo config to `null` by default', function () {
42
63
  var App = (0, _SpotlightRootDecorator.SpotlightRootDecorator)(AppBase);
43
64
  (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(App, {}));
@@ -19,6 +19,7 @@ Object.defineProperty(exports, "useSpottable", {
19
19
  var _handle = _interopRequireWildcard(require("@enact/core/handle"));
20
20
  var _useHandlers = _interopRequireDefault(require("@enact/core/useHandlers"));
21
21
  var _hoc = _interopRequireDefault(require("@enact/core/hoc"));
22
+ var _util = require("@enact/core/util");
22
23
  var _WithRef = require("@enact/core/internal/WithRef");
23
24
  var _classnames = _interopRequireDefault(require("classnames"));
24
25
  var _propTypes = _interopRequireDefault(require("prop-types"));
@@ -35,16 +36,12 @@ var _excluded = ["className", "disabled", "handleForceUpdate", "onSpotlightDisap
35
36
  */
36
37
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
37
38
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
38
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
39
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
40
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
41
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
42
- function _possibleConstructorReturn(t, e) { if (e && ("object" == typeof e || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
43
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
44
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
45
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
46
- function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
47
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
39
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
40
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
41
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
42
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
43
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
44
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
48
45
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
49
46
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
50
47
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
@@ -112,6 +109,32 @@ var defaultConfig = {
112
109
  * ...
113
110
  * const SpottableComponent = Spottable(Component);
114
111
  * ```
112
+ *
113
+ * When a component receives spotlight focus, the `data-spotlight-focused` attribute is
114
+ * automatically applied to its DOM node and removed on blur. This provides a stable CSS hook
115
+ * for styling focused components without any additional configuration:
116
+ *
117
+ * ```css
118
+ * [data-spotlight-focused] {
119
+ * outline: 3px solid var(--my-focus-color);
120
+ * }
121
+ * ```
122
+ *
123
+ * Or within a CSS Modules component stylesheet:
124
+ *
125
+ * ```less
126
+ * .button {
127
+ * &[data-spotlight-focused] {
128
+ * .bg {
129
+ * background-color: var(--my-focus-bg-color);
130
+ * }
131
+ * }
132
+ * }
133
+ * ```
134
+ *
135
+ * For an app-wide focus class, see {@link spotlight/SpotlightRootDecorator.SpotlightRootDecorator}
136
+ * and its `focusEffectClass` config option.
137
+ *
115
138
  * @class Spottable
116
139
  * @memberof spotlight/Spottable
117
140
  * @param {Object} defaultConfig Set of default configuration parameters
@@ -124,6 +147,7 @@ var Spottable = exports.Spottable = (0, _hoc["default"])(defaultConfig, function
124
147
  var emulateMouse = config.emulateMouse;
125
148
  var WrappedWithRef = (0, _WithRef.WithRef)(Wrapped);
126
149
  function SpottableBase(props) {
150
+ (0, _util.checkPropTypes)(SpottableBase, props);
127
151
  var nodeRef = (0, _react.useRef)();
128
152
  var className = props.className,
129
153
  disabled = props.disabled,
@@ -161,7 +185,6 @@ var Spottable = exports.Spottable = (0, _hoc["default"])(defaultConfig, function
161
185
  }
162
186
  rest.tabIndex = tabIndex;
163
187
  var handlers = (0, _useHandlers["default"])(spotHandlers, rest, spot);
164
- delete rest.spotlightId;
165
188
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(WrappedWithRef, _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, rest), spot.attributes), handlers), {}, {
166
189
  className: (0, _classnames["default"])(className, spot.className),
167
190
  disabled: disabled,
@@ -261,34 +284,16 @@ var Spottable = exports.Spottable = (0, _hoc["default"])(defaultConfig, function
261
284
  };
262
285
 
263
286
  // eslint-disable-next-line no-shadow
264
- var Spottable = /*#__PURE__*/function (_Component) {
265
- function Spottable() {
266
- var _this;
267
- _classCallCheck(this, Spottable);
268
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
269
- args[_key] = arguments[_key];
270
- }
271
- _this = _callSuper(this, Spottable, [].concat(args));
272
- _this.handleForceUpdate = function () {
273
- _this.forceUpdate();
274
- };
275
- return _this;
276
- }
277
- _inherits(Spottable, _Component);
278
- return _createClass(Spottable, [{
279
- key: "componentDidMount",
280
- value: function componentDidMount() {
281
- this.forceUpdate();
282
- }
283
- }, {
284
- key: "render",
285
- value: function render() {
286
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableBase, _objectSpread(_objectSpread({}, this.props), {}, {
287
- handleForceUpdate: this.handleForceUpdate
288
- }));
289
- }
290
- }]);
291
- }(_react.Component);
287
+ function Spottable(props) {
288
+ var _useReducer = (0, _react.useReducer)(function (x) {
289
+ return x + 1;
290
+ }, 0),
291
+ _useReducer2 = _slicedToArray(_useReducer, 2),
292
+ forceUpdate = _useReducer2[1];
293
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableBase, _objectSpread(_objectSpread({}, props), {}, {
294
+ handleForceUpdate: forceUpdate
295
+ }));
296
+ }
292
297
  return Spottable;
293
298
  });
294
299
  var _default = exports["default"] = Spottable;
@@ -7,6 +7,7 @@ exports.spottableClass = exports["default"] = exports.SpottableCore = void 0;
7
7
  var _handle = require("@enact/core/handle");
8
8
  var _keymap = require("@enact/core/keymap");
9
9
  var _container = require("../src/container");
10
+ var _focusEffect = require("../src/focusEffect");
10
11
  var _spotlight = require("../src/spotlight");
11
12
  function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
12
13
  function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
@@ -31,6 +32,14 @@ var isKeyboardAccessible = function isKeyboardAccessible(node) {
31
32
  var isSpottable = function isSpottable(props) {
32
33
  return !props.spotlightDisabled;
33
34
  };
35
+ var hasSelectionKey = function hasSelectionKey(selectionKeys, keyCode) {
36
+ for (var i = 0; i < selectionKeys.length; i++) {
37
+ if (selectionKeys[i] === keyCode) {
38
+ return true;
39
+ }
40
+ }
41
+ return false;
42
+ };
34
43
 
35
44
  // Last instance of spottable to be focused
36
45
  var lastSelectTarget = null;
@@ -43,7 +52,17 @@ var SpottableCore = exports.SpottableCore = /*#__PURE__*/function () {
43
52
  var emulateMouse = _ref.emulateMouse;
44
53
  _classCallCheck(this, SpottableCore);
45
54
  this.didUpdate = function () {
46
- _this.isFocused = _this.node && _this.node === _spotlight.Spotlight.getCurrent();
55
+ // Avoid the cost of calling `Spotlight.getCurrent()` on every render unless we
56
+ // need focus state for class calculation (`spotlightDisabled`) or selection cancel.
57
+ var shouldUpdateFocusState = _this.props.spotlightDisabled || _this.props.disabled && lastSelectTarget === _this && !selectCancelled;
58
+ if (shouldUpdateFocusState) {
59
+ _this.isFocused = _this.node && _this.node === _spotlight.Spotlight.getCurrent();
60
+ }
61
+
62
+ // Re-apply focus effect after every render while focused
63
+ if (_this.isFocused) {
64
+ _this.applyFocusEffect();
65
+ }
47
66
 
48
67
  // if the component is focused and became disabled
49
68
  if (_this.isFocused && _this.props.disabled && lastSelectTarget === _this && !selectCancelled) {
@@ -88,9 +107,7 @@ var SpottableCore = exports.SpottableCore = /*#__PURE__*/function () {
88
107
  this.forwardAndResetLastSelectTarget = function (ev, props) {
89
108
  var keyCode = ev.keyCode;
90
109
  var selectionKeys = props.selectionKeys;
91
- var key = selectionKeys.find(function (value) {
92
- return keyCode === value;
93
- });
110
+ var key = hasSelectionKey(selectionKeys, keyCode);
94
111
  var notPrevented = !ev.defaultPrevented;
95
112
 
96
113
  // bail early for non-selection keyup to avoid clearing lastSelectTarget prematurely
@@ -111,17 +128,16 @@ var SpottableCore = exports.SpottableCore = /*#__PURE__*/function () {
111
128
  type = ev.type,
112
129
  which = ev.which;
113
130
  var selectionKeys = props.selectionKeys;
114
- var keyboardAccessible = isKeyboardAccessible(currentTarget);
115
- var keyCode = selectionKeys.find(function (value) {
116
- return (
117
- // emulate mouse events for any remote okay button event
118
- which === REMOTE_OK_KEY ||
119
- // or a non-keypress selection event or any selection event on a non-keyboard accessible
120
- // control
131
+ var isRemoteOkKey = which === REMOTE_OK_KEY;
132
+ var isSelectionKey = isRemoteOkKey || hasSelectionKey(selectionKeys, which);
121
133
 
122
- which === value && (type !== 'keypress' || !keyboardAccessible)
123
- );
124
- });
134
+ // Fast-path: avoid DOM checks and event normalization for non-selection key events.
135
+ if (!isSelectionKey) {
136
+ return false;
137
+ }
138
+ var keyboardAccessible = isKeyboardAccessible(currentTarget);
139
+ var canEmulate = isRemoteOkKey || type !== 'keypress' || !keyboardAccessible;
140
+ var keyCode = canEmulate ? which : null;
125
141
  if ((0, _spotlight.getDirection)(keyCode)) {
126
142
  (0, _handle.preventDefault)(ev);
127
143
  (0, _handle.stop)(ev);
@@ -138,9 +154,7 @@ var SpottableCore = exports.SpottableCore = /*#__PURE__*/function () {
138
154
  var selectionKeys = props.selectionKeys;
139
155
 
140
156
  // Only apply accelerator if handling a selection key
141
- if (selectionKeys.find(function (value) {
142
- return which === value;
143
- })) {
157
+ if (hasSelectionKey(selectionKeys, which)) {
144
158
  if (selectCancelled || lastSelectTarget && lastSelectTarget !== _this) {
145
159
  return false;
146
160
  }
@@ -166,6 +180,7 @@ var SpottableCore = exports.SpottableCore = /*#__PURE__*/function () {
166
180
  }
167
181
  if (ev.currentTarget === ev.target) {
168
182
  _this.isFocused = true;
183
+ _this.applyFocusEffect();
169
184
  }
170
185
  if (_spotlight.Spotlight.isMuted(ev.target)) {
171
186
  ev.stopPropagation();
@@ -177,6 +192,7 @@ var SpottableCore = exports.SpottableCore = /*#__PURE__*/function () {
177
192
  if (_this.shouldPreventBlur) return false;
178
193
  if (ev.currentTarget === ev.target) {
179
194
  _this.isFocused = false;
195
+ _this.removeFocusEffect();
180
196
  if (_this.isFocusedWhenDisabled) {
181
197
  _this.isFocusedWhenDisabled = false;
182
198
  // We only need to trigger a rerender if a focused item becomes disabled and still needs its focus.
@@ -209,6 +225,7 @@ var SpottableCore = exports.SpottableCore = /*#__PURE__*/function () {
209
225
  // Used to indicate that we want to stop propagation on blur events that occur as a
210
226
  // result of this component imperatively blurring itself on focus when spotlightDisabled
211
227
  this.shouldPreventBlur = false;
228
+ this.appliedFocusClass = null;
212
229
  }
213
230
  return _createClass(SpottableCore, [{
214
231
  key: "setPropsAndContext",
@@ -227,13 +244,58 @@ var SpottableCore = exports.SpottableCore = /*#__PURE__*/function () {
227
244
  }, {
228
245
  key: "unload",
229
246
  value: function unload() {
230
- if (this.isFocused) {
247
+ var isFocusedNow = this.node && this.node === _spotlight.Spotlight.getCurrent();
248
+ if (isFocusedNow) {
231
249
  (0, _handle.forwardCustom)('onSpotlightDisappear')(null, this.props);
232
250
  }
233
251
  if (lastSelectTarget === this) {
234
252
  lastSelectTarget = null;
235
253
  }
236
254
  }
255
+ }, {
256
+ key: "applyFocusEffect",
257
+ value:
258
+ /**
259
+ * Applies the `data-spotlight-focused` attribute and any custom focus class to `this.node`.
260
+ * Uses direct DOM manipulation to avoid a React re-render on every focus change.
261
+ *
262
+ * Priority: `data-spotlight-focused` attribute > global `focusEffectClass` value.
263
+ *
264
+ * @private
265
+ */
266
+ function applyFocusEffect() {
267
+ var _this2 = this;
268
+ if (!this.node) return;
269
+ this.node.setAttribute('data-spotlight-focused', '');
270
+ var focusClass = (0, _focusEffect.getFocusEffectClass)();
271
+ if (focusClass) {
272
+ this.appliedFocusClass = focusClass;
273
+ focusClass.split(' ').forEach(function (cls) {
274
+ if (cls) _this2.node.classList.add(cls);
275
+ });
276
+ }
277
+ }
278
+
279
+ /**
280
+ * Removes the `data-spotlight-focused` attribute and any previously applied custom focus class
281
+ * from `this.node`. Cleans up exactly what `applyFocusEffect` added, regardless of whether
282
+ * props have changed between focus and blur.
283
+ *
284
+ * @private
285
+ */
286
+ }, {
287
+ key: "removeFocusEffect",
288
+ value: function removeFocusEffect() {
289
+ var _this3 = this;
290
+ if (!this.node) return;
291
+ this.node.removeAttribute('data-spotlight-focused');
292
+ if (this.appliedFocusClass) {
293
+ this.appliedFocusClass.split(' ').forEach(function (cls) {
294
+ if (cls) _this3.node.classList.remove(cls);
295
+ });
296
+ this.appliedFocusClass = null;
297
+ }
298
+ }
237
299
  }]);
238
300
  }();
239
301
  var _default = exports["default"] = SpottableCore;
@@ -3,6 +3,7 @@
3
3
  require("@testing-library/jest-dom");
4
4
  var _react = require("@testing-library/react");
5
5
  var _Spottable = _interopRequireDefault(require("../Spottable"));
6
+ var _focusEffect = require("../../src/focusEffect");
6
7
  var _jsxRuntime = require("react/jsx-runtime");
7
8
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
8
9
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -58,6 +59,95 @@ describe('Spottable', function () {
58
59
  type: 'onSpotlightDisappear'
59
60
  });
60
61
  });
62
+ describe('applyFocusEffect / removeFocusEffect', function () {
63
+ afterEach(function () {
64
+ (0, _focusEffect.setFocusEffectClass)(null);
65
+ });
66
+ test('should add data-spotlight-focused attribute when focused', function () {
67
+ var Component = (0, _Spottable["default"])('div');
68
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
69
+ "data-testid": id
70
+ }));
71
+ var div = _react.screen.getByTestId(id);
72
+ _react.fireEvent.focus(div);
73
+ expect(div).toHaveAttribute('data-spotlight-focused');
74
+ });
75
+ test('should remove data-spotlight-focused attribute when blurred', function () {
76
+ var Component = (0, _Spottable["default"])('div');
77
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
78
+ "data-testid": id
79
+ }));
80
+ var div = _react.screen.getByTestId(id);
81
+ _react.fireEvent.focus(div);
82
+ _react.fireEvent.blur(div);
83
+ expect(div).not.toHaveAttribute('data-spotlight-focused');
84
+ });
85
+ test('should add focus effect class when focusEffectClass is set', function () {
86
+ (0, _focusEffect.setFocusEffectClass)('my-focus-class');
87
+ var Component = (0, _Spottable["default"])('div');
88
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
89
+ "data-testid": id
90
+ }));
91
+ var div = _react.screen.getByTestId(id);
92
+ _react.fireEvent.focus(div);
93
+ expect(div).toHaveClass('my-focus-class');
94
+ });
95
+ test('should remove focus effect class when blurred', function () {
96
+ (0, _focusEffect.setFocusEffectClass)('my-focus-class');
97
+ var Component = (0, _Spottable["default"])('div');
98
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
99
+ "data-testid": id
100
+ }));
101
+ var div = _react.screen.getByTestId(id);
102
+ _react.fireEvent.focus(div);
103
+ _react.fireEvent.blur(div);
104
+ expect(div).not.toHaveClass('my-focus-class');
105
+ });
106
+ test('should add multiple space-separated focus effect classes when focused', function () {
107
+ (0, _focusEffect.setFocusEffectClass)('class-a class-b');
108
+ var Component = (0, _Spottable["default"])('div');
109
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
110
+ "data-testid": id
111
+ }));
112
+ var div = _react.screen.getByTestId(id);
113
+ _react.fireEvent.focus(div);
114
+ expect(div).toHaveClass('class-a');
115
+ expect(div).toHaveClass('class-b');
116
+ });
117
+ test('should remove all space-separated focus effect classes when blurred', function () {
118
+ (0, _focusEffect.setFocusEffectClass)('class-a class-b');
119
+ var Component = (0, _Spottable["default"])('div');
120
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
121
+ "data-testid": id
122
+ }));
123
+ var div = _react.screen.getByTestId(id);
124
+ _react.fireEvent.focus(div);
125
+ _react.fireEvent.blur(div);
126
+ expect(div).not.toHaveClass('class-a');
127
+ expect(div).not.toHaveClass('class-b');
128
+ });
129
+ test('should remove the class that was set at focus time even if focusEffectClass changes before blur', function () {
130
+ (0, _focusEffect.setFocusEffectClass)('original-class');
131
+ var Component = (0, _Spottable["default"])('div');
132
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
133
+ "data-testid": id
134
+ }));
135
+ var div = _react.screen.getByTestId(id);
136
+ _react.fireEvent.focus(div);
137
+ (0, _focusEffect.setFocusEffectClass)('new-class');
138
+ _react.fireEvent.blur(div);
139
+ expect(div).not.toHaveClass('original-class');
140
+ });
141
+ test('should not add any extra class when no focusEffectClass is set', function () {
142
+ var Component = (0, _Spottable["default"])('div');
143
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
144
+ "data-testid": id
145
+ }));
146
+ var div = _react.screen.getByTestId(id);
147
+ _react.fireEvent.focus(div);
148
+ expect(div.className).toBe('spottable');
149
+ });
150
+ });
61
151
  describe('shouldComponentUpdate', function () {
62
152
  test('should re-render when a non-Spottable prop changes', function () {
63
153
  var spy = jest.fn(function (props) {
@@ -69,7 +159,7 @@ describe('Spottable', function () {
69
159
  rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
70
160
  "data-id": "123"
71
161
  }));
72
- var expected = 3;
162
+ var expected = 2;
73
163
  expect(spy).toHaveBeenCalledTimes(expected);
74
164
  });
75
165
  test('should re-render when {selectionKeys} changes', function () {
@@ -84,7 +174,7 @@ describe('Spottable', function () {
84
174
  rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
85
175
  selectionKeys: [2, 1, 3]
86
176
  }));
87
- var expected = 3;
177
+ var expected = 2;
88
178
  expect(spy).toHaveBeenCalledTimes(expected);
89
179
  });
90
180
  test('should not re-render when focused', function () {
@@ -97,7 +187,7 @@ describe('Spottable', function () {
97
187
  }));
98
188
  var div = _react.screen.getByTestId(id);
99
189
  div.focus();
100
- var expected = 2;
190
+ var expected = 1;
101
191
  expect(spy).toHaveBeenCalledTimes(expected);
102
192
  });
103
193
  });
@@ -218,6 +218,30 @@ describe('useSpottable', function () {
218
218
  _react.fireEvent.keyUp(div, makeKeyEvent(REMOTE_OK_KEY));
219
219
  expect(spy).not.toHaveBeenCalled();
220
220
  });
221
+ test('should emulate {onMouseDown} for a custom selection key', function () {
222
+ var spy = jest.fn();
223
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
224
+ "data-testid": id,
225
+ emulateMouse: true,
226
+ onMouseDown: spy,
227
+ selectionKeys: [32]
228
+ }));
229
+ var div = _react.screen.getByTestId(id);
230
+ _react.fireEvent.keyDown(div, makeKeyEvent(32));
231
+ expect(spy).toHaveBeenCalledTimes(1);
232
+ });
233
+ test('should not emulate {onMouseDown} for a non-selection key', function () {
234
+ var spy = jest.fn();
235
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
236
+ "data-testid": id,
237
+ emulateMouse: true,
238
+ onMouseDown: spy,
239
+ selectionKeys: [13]
240
+ }));
241
+ var div = _react.screen.getByTestId(id);
242
+ _react.fireEvent.keyDown(div, makeKeyEvent(65));
243
+ expect(spy).not.toHaveBeenCalled();
244
+ });
221
245
  });
222
246
  describe('shouldComponentUpdate', function () {
223
247
  test('should re-render when a non-Component prop changes', function () {
@@ -255,6 +279,23 @@ describe('useSpottable', function () {
255
279
  var expected = 2;
256
280
  expect(spy).toHaveBeenCalledTimes(expected);
257
281
  });
282
+ test('should update when {spotlightDisabled} changes', function () {
283
+ var spy = jest.fn(function (props) {
284
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
285
+ });
286
+ var _render3 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
287
+ component: spy,
288
+ "data-testid": id,
289
+ spotlightDisabled: true
290
+ })),
291
+ rerender = _render3.rerender;
292
+ rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
293
+ component: spy,
294
+ "data-testid": id,
295
+ spotlightDisabled: false
296
+ }));
297
+ expect(spy).toHaveBeenCalledTimes(2);
298
+ });
258
299
  test('should not re-render when focused', function () {
259
300
  var spy = jest.fn(function (props) {
260
301
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
@@ -269,4 +310,115 @@ describe('useSpottable', function () {
269
310
  expect(spy).toHaveBeenCalledTimes(expected);
270
311
  });
271
312
  });
313
+ describe('focus restoration on spotlightDisabled transition', function () {
314
+ var focusSpy;
315
+ var isPausedSpy;
316
+ var pointerModeSpy;
317
+ var setPointerModeSpy;
318
+ beforeEach(function () {
319
+ focusSpy = jest.spyOn(_spotlight["default"], 'focus').mockImplementation(function () {
320
+ return true;
321
+ });
322
+ isPausedSpy = jest.spyOn(_spotlight["default"], 'isPaused').mockReturnValue(false);
323
+ // Drive the pointer-mode + hover branch of focus restoration;
324
+ pointerModeSpy = jest.spyOn(_spotlight["default"], 'getPointerMode').mockReturnValue(true);
325
+ setPointerModeSpy = jest.spyOn(_spotlight["default"], 'setPointerMode').mockImplementation(function () {});
326
+ // Override the wrapper's getCurrent mock: simulate "focus is on something outside Spotlight's tracking"
327
+ _spotlight["default"].getCurrent = function () {
328
+ return null;
329
+ };
330
+ });
331
+ afterEach(function () {
332
+ focusSpy.mockRestore();
333
+ isPausedSpy.mockRestore();
334
+ pointerModeSpy.mockRestore();
335
+ setPointerModeSpy.mockRestore();
336
+ });
337
+ test('should restore focus exactly once on a true→false transition', function () {
338
+ var _render4 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
339
+ "data-testid": id,
340
+ spotlightDisabled: true
341
+ })),
342
+ rerender = _render4.rerender;
343
+ // isHovered must be true for the pointer-mode restoration branch to fire.
344
+ _react.fireEvent.mouseEnter(_react.screen.getByTestId(id));
345
+ rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
346
+ "data-testid": id,
347
+ spotlightDisabled: false
348
+ }));
349
+ expect(focusSpy).toHaveBeenCalledTimes(1);
350
+ });
351
+ test('should not re-restore focus on no-change rerenders after the transition', function () {
352
+ var _render5 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
353
+ "data-testid": id,
354
+ spotlightDisabled: true
355
+ })),
356
+ rerender = _render5.rerender;
357
+ _react.fireEvent.mouseEnter(_react.screen.getByTestId(id));
358
+
359
+ // Transition true → false: legitimate restore, fires once.
360
+ rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
361
+ "data-testid": id,
362
+ spotlightDisabled: false
363
+ }));
364
+ expect(focusSpy).toHaveBeenCalledTimes(1);
365
+
366
+ // Subsequent no-change rerenders simulate the parent re-rendering for
367
+ // reasons unrelated to spotlightDisabled (e.g. a sibling prop changing_
368
+ rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
369
+ "data-testid": id,
370
+ spotlightDisabled: false
371
+ }));
372
+ rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
373
+ "data-testid": id,
374
+ spotlightDisabled: false
375
+ }));
376
+ rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
377
+ "data-testid": id,
378
+ spotlightDisabled: false
379
+ }));
380
+ expect(focusSpy).toHaveBeenCalledTimes(1);
381
+ });
382
+ test('should restore focus again on a second true→false transition', function () {
383
+ var _render6 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
384
+ "data-testid": id,
385
+ spotlightDisabled: true
386
+ })),
387
+ rerender = _render6.rerender;
388
+ _react.fireEvent.mouseEnter(_react.screen.getByTestId(id));
389
+
390
+ // First transition.
391
+ rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
392
+ "data-testid": id,
393
+ spotlightDisabled: false
394
+ }));
395
+ expect(focusSpy).toHaveBeenCalledTimes(1);
396
+
397
+ // No-change rerender between transitions
398
+ rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
399
+ "data-testid": id,
400
+ spotlightDisabled: false
401
+ }));
402
+ expect(focusSpy).toHaveBeenCalledTimes(1);
403
+
404
+ // Toggle back to disabled (no restoration on this direction).
405
+ rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
406
+ "data-testid": id,
407
+ spotlightDisabled: true
408
+ }));
409
+ expect(focusSpy).toHaveBeenCalledTimes(1);
410
+
411
+ // Second true → false transition — restoration must fire again.
412
+ rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
413
+ "data-testid": id,
414
+ spotlightDisabled: false
415
+ }));
416
+ expect(focusSpy).toHaveBeenCalledTimes(2);
417
+ rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
418
+ "data-testid": id,
419
+ spotlightDisabled: false
420
+ }));
421
+ expect(focusSpy).toHaveBeenCalledTimes(2);
422
+ });
423
+ });
272
424
  });
@@ -74,6 +74,7 @@ var REMOTE_OK_KEY = 16777221;
74
74
  * @private
75
75
  */
76
76
 
77
+ var EMPTY_ATTRIBUTES = {};
77
78
  var useSpottable = exports.useSpottable = function useSpottable() {
78
79
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
79
80
  emulateMouse = _ref.emulateMouse,
@@ -85,22 +86,24 @@ var useSpottable = exports.useSpottable = function useSpottable() {
85
86
  var hook = (0, _useClass["default"])(_SpottableCore.SpottableCore, {
86
87
  emulateMouse: emulateMouse
87
88
  });
88
- var context = (0, _react.useRef)({
89
+ var contextRef = (0, _react.useRef)({
89
90
  prevSpotlightDisabled: spotlightDisabled,
90
91
  spotlightDisabled: spotlightDisabled
91
92
  });
92
- context.current = {
93
- prevSpotlightDisabled: context.current.spotlightDisabled,
94
- spotlightDisabled: spotlightDisabled
95
- };
96
- var attributes = {};
97
- if (props.spotlightId) {
98
- attributes['data-spotlight-id'] = props.spotlightId;
99
- }
93
+ var context = contextRef.current;
94
+ var attributes = props.spotlightId ? {
95
+ 'data-spotlight-id': props.spotlightId
96
+ } : EMPTY_ATTRIBUTES;
97
+
98
+ // Mutate in-place to avoid a new object allocation on every render.
99
+ context.prevSpotlightDisabled = context.spotlightDisabled; // eslint-disable-line react-hooks/refs
100
+ context.spotlightDisabled = spotlightDisabled; // eslint-disable-line react-hooks/refs
101
+
100
102
  hook.setPropsAndContext(_objectSpread({
101
103
  selectionKeys: selectionKeys,
102
104
  spotlightDisabled: spotlightDisabled
103
- }, props), context.current);
105
+ }, props), context); // eslint-disable-line react-hooks/refs
106
+
104
107
  (0, _react.useLayoutEffect)(function () {
105
108
  hook.load(getSpotRef() || null);
106
109
  return function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enact/spotlight",
3
- "version": "5.4.3",
3
+ "version": "5.5.0",
4
4
  "description": "A focus management library",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,12 +25,17 @@
25
25
  }
26
26
  },
27
27
  "dependencies": {
28
- "@enact/core": "^5.4.3",
28
+ "@enact/core": "^5.5.0",
29
29
  "classnames": "^2.5.1",
30
30
  "prop-types": "^15.8.1",
31
31
  "ramda": "^0.32.0",
32
- "react": "^19.2.4",
33
- "react-dom": "^19.2.4",
32
+ "react": "^19.2.6",
33
+ "react-dom": "^19.2.6",
34
34
  "warning": "^4.0.3"
35
+ },
36
+ "overrides": {
37
+ "prop-types": {
38
+ "react-is": "^19.2.3"
39
+ }
35
40
  }
36
41
  }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setFocusEffectClass = exports.getFocusEffectClass = void 0;
7
+ /**
8
+ * Manages the global spotlight focus effect configuration.
9
+ *
10
+ * App developers can set `focusEffectClass` once (e.g. in their app root) to apply a
11
+ * custom CSS class to every focused spottable component.
12
+ *
13
+ * example: const App = SpotlightRootDecorator({ focusEffectClass: css.appFocusClass }, AppBase);
14
+ *
15
+ * @module spotlight/focusEffect
16
+ * @private
17
+ */
18
+
19
+ var focusEffect = {
20
+ className: null
21
+ };
22
+
23
+ /**
24
+ * Sets the global CSS class name to apply to any spottable component when it receives spotlight
25
+ * focus. This acts as an app-wide default.
26
+ *
27
+ * Example:
28
+ * ```js
29
+ * import { setFocusEffectClass } from '@enact/spotlight';
30
+ * setFocusEffectClass(css.appFocusClass);
31
+ * ```
32
+ *
33
+ * @param {String|null} className CSS class to apply when a component is focused. Pass `null` or an empty string to clear.
34
+ * @memberof spotlight/focusEffect
35
+ * @public
36
+ */
37
+ var setFocusEffectClass = exports.setFocusEffectClass = function setFocusEffectClass(className) {
38
+ focusEffect.className = className || null;
39
+ };
40
+
41
+ /**
42
+ * Returns the currently configured global focus effect class, or `null` if none is set.
43
+ *
44
+ * @returns {String|null}
45
+ * @memberof spotlight/focusEffect
46
+ * @private
47
+ */
48
+ var getFocusEffectClass = exports.getFocusEffectClass = function getFocusEffectClass() {
49
+ return focusEffect.className;
50
+ };
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ var _focusEffect = require("../focusEffect");
4
+ describe('focusEffect', function () {
5
+ afterEach(function () {
6
+ (0, _focusEffect.setFocusEffectClass)(null);
7
+ });
8
+ describe('getFocusEffectClass', function () {
9
+ test('should return null by default', function () {
10
+ expect((0, _focusEffect.getFocusEffectClass)()).toBeNull();
11
+ });
12
+ test('should return the class name set by setFocusEffectClass', function () {
13
+ (0, _focusEffect.setFocusEffectClass)('my-focus-class');
14
+ expect((0, _focusEffect.getFocusEffectClass)()).toBe('my-focus-class');
15
+ });
16
+ test('should return updated class after multiple setFocusEffectClass calls', function () {
17
+ (0, _focusEffect.setFocusEffectClass)('first-class');
18
+ (0, _focusEffect.setFocusEffectClass)('second-class');
19
+ expect((0, _focusEffect.getFocusEffectClass)()).toBe('second-class');
20
+ });
21
+ });
22
+ describe('setFocusEffectClass', function () {
23
+ test('should set the focus class', function () {
24
+ (0, _focusEffect.setFocusEffectClass)('custom-class');
25
+ expect((0, _focusEffect.getFocusEffectClass)()).toBe('custom-class');
26
+ });
27
+ test('should clear the focus class when passed null', function () {
28
+ (0, _focusEffect.setFocusEffectClass)('custom-class');
29
+ (0, _focusEffect.setFocusEffectClass)(null);
30
+ expect((0, _focusEffect.getFocusEffectClass)()).toBeNull();
31
+ });
32
+ test('should clear the focus class when passed an empty string', function () {
33
+ (0, _focusEffect.setFocusEffectClass)('custom-class');
34
+ (0, _focusEffect.setFocusEffectClass)('');
35
+ expect((0, _focusEffect.getFocusEffectClass)()).toBeNull();
36
+ });
37
+ test('should support space-separated class names as a single string', function () {
38
+ (0, _focusEffect.setFocusEffectClass)('class-a class-b');
39
+ expect((0, _focusEffect.getFocusEffectClass)()).toBe('class-a class-b');
40
+ });
41
+ });
42
+ });
package/src/utils.js CHANGED
@@ -72,7 +72,7 @@ var testIntersection = function testIntersection(type, containerRect, elementRec
72
72
  t > T - epsilon && t < B + epsilon &&
73
73
  // top
74
74
  b > T - epsilon && b < B + epsilon // bottom
75
- ;
75
+ ;
76
76
  }
77
77
  return true;
78
78
  };