@enact/spotlight 3.4.9-experimental-3 → 3.4.9-experimental-7

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.
Files changed (68) hide show
  1. package/{build/Accelerator → Accelerator}/Accelerator.d.ts +0 -0
  2. package/Accelerator/Accelerator.js +149 -156
  3. package/CHANGELOG.md +22 -0
  4. package/{build/Pause → Pause}/Pause.d.ts +0 -0
  5. package/Pause/Pause.js +102 -80
  6. package/Pause/tests/Pause-specs.js +65 -97
  7. package/SpotlightContainerDecorator/SpotlightContainer.js +175 -140
  8. package/{build/SpotlightContainerDecorator → SpotlightContainerDecorator}/SpotlightContainerDecorator.d.ts +0 -0
  9. package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +222 -176
  10. package/SpotlightContainerDecorator/tests/Element.prototype.closest.js +44 -40
  11. package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +221 -210
  12. package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +150 -243
  13. package/SpotlightContainerDecorator/useSpotlightContainer.js +47 -28
  14. package/{build/SpotlightRootDecorator → SpotlightRootDecorator}/SpotlightRootDecorator.d.ts +0 -0
  15. package/SpotlightRootDecorator/SpotlightRootDecorator.js +206 -111
  16. package/{build/Spottable → Spottable}/Spottable.d.ts +0 -0
  17. package/Spottable/Spottable.js +448 -410
  18. package/Spottable/tests/Spottable-specs.js +90 -117
  19. package/package.json +3 -2
  20. package/src/container.js +718 -653
  21. package/src/navigate.js +406 -491
  22. package/src/pointer.js +86 -78
  23. package/{build/src → src}/spotlight.d.ts +0 -0
  24. package/src/spotlight.js +846 -885
  25. package/src/target.js +448 -474
  26. package/src/tests/container-specs.js +643 -1251
  27. package/src/tests/navigate-specs.js +77 -134
  28. package/src/tests/pointer-specs.js +126 -182
  29. package/src/tests/spotlight-specs.js +103 -133
  30. package/src/tests/target-specs.js +597 -960
  31. package/src/tests/utils.js +89 -67
  32. package/src/utils.js +155 -158
  33. package/build/Accelerator/Accelerator.js +0 -162
  34. package/build/Accelerator/package.json +0 -3
  35. package/build/CHANGELOG.md +0 -838
  36. package/build/Pause/Pause.js +0 -164
  37. package/build/Pause/package.json +0 -3
  38. package/build/Pause/tests/Pause-specs.js +0 -65
  39. package/build/README.md +0 -61
  40. package/build/SpotlightContainerDecorator/SpotlightContainer.js +0 -176
  41. package/build/SpotlightContainerDecorator/SpotlightContainerDecorator.js +0 -282
  42. package/build/SpotlightContainerDecorator/package.json +0 -3
  43. package/build/SpotlightContainerDecorator/tests/Element.prototype.closest.js +0 -45
  44. package/build/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +0 -221
  45. package/build/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +0 -160
  46. package/build/SpotlightContainerDecorator/useSpotlightContainer.js +0 -133
  47. package/build/SpotlightRootDecorator/SpotlightRootDecorator.js +0 -189
  48. package/build/SpotlightRootDecorator/package.json +0 -3
  49. package/build/Spottable/Spottable.js +0 -491
  50. package/build/Spottable/package.json +0 -3
  51. package/build/Spottable/tests/Spottable-specs.js +0 -90
  52. package/build/package-lock.json +0 -229
  53. package/build/package.json +0 -28
  54. package/build/src/container.js +0 -1201
  55. package/build/src/navigate.js +0 -419
  56. package/build/src/pointer.js +0 -183
  57. package/build/src/spotlight.js +0 -896
  58. package/build/src/target.js +0 -507
  59. package/build/src/tests/container-specs.js +0 -653
  60. package/build/src/tests/navigate-specs.js +0 -87
  61. package/build/src/tests/pointer-specs.js +0 -130
  62. package/build/src/tests/spotlight-specs.js +0 -112
  63. package/build/src/tests/target-specs.js +0 -614
  64. package/build/src/tests/utils.js +0 -104
  65. package/build/src/utils.js +0 -180
  66. package/build/styles/debug.less +0 -97
  67. package/build/styles/mixins.less +0 -63
  68. package/docs/index.md +0 -364
@@ -1,491 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.spottableClass = exports.Spottable = exports["default"] = void 0;
7
-
8
- var _handle = require("@enact/core/handle");
9
-
10
- var _hoc = _interopRequireDefault(require("@enact/core/hoc"));
11
-
12
- var _keymap = require("@enact/core/keymap");
13
-
14
- var _propTypes = _interopRequireDefault(require("prop-types"));
15
-
16
- var _react = _interopRequireDefault(require("react"));
17
-
18
- var _reactDom = _interopRequireDefault(require("react-dom"));
19
-
20
- var _container = require("../src/container");
21
-
22
- var _spotlight = require("../src/spotlight");
23
-
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
25
-
26
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
27
-
28
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
29
-
30
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
31
-
32
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
33
-
34
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
35
-
36
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
37
-
38
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
39
-
40
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
41
-
42
- function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
43
-
44
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
45
-
46
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
47
-
48
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
49
-
50
- /**
51
- * The class name for spottable components. In general, you do not need to directly access this class
52
- *
53
- * @memberof spotlight/Spottable
54
- * @public
55
- */
56
- var spottableClass = 'spottable';
57
- exports.spottableClass = spottableClass;
58
- var ENTER_KEY = 13;
59
- var REMOTE_OK_KEY = 16777221;
60
-
61
- var isKeyboardAccessible = function isKeyboardAccessible(node) {
62
- if (!node) return false;
63
- var name = node.nodeName.toUpperCase();
64
- var type = node.type ? node.type.toUpperCase() : null;
65
- return name === 'BUTTON' || name === 'A' || name === 'INPUT' && (type === 'BUTTON' || type === 'CHECKBOX' || type === 'IMAGE' || type === 'RADIO' || type === 'RESET' || type === 'SUBMIT');
66
- };
67
-
68
- var isSpottable = function isSpottable(props) {
69
- return !props.spotlightDisabled;
70
- }; // Last instance of spottable to be focused
71
-
72
-
73
- var lastSelectTarget = null; // Should we prevent select being passed through
74
-
75
- var selectCancelled = false;
76
- /**
77
- * Default configuration for Spottable
78
- *
79
- * @hocconfig
80
- * @memberof spotlight/Spottable.Spottable
81
- */
82
-
83
- var defaultConfig = {
84
- /**
85
- * Whether or not the component should emulate mouse events as a response
86
- * to Spotlight 5-way events.
87
- *
88
- * @type {Boolean}
89
- * @default false
90
- * @public
91
- * @memberof spotlight/Spottable.Spottable.defaultConfig
92
- */
93
- emulateMouse: true
94
- };
95
- /**
96
- * Constructs a Spotlight 5-way navigation-enabled higher-order component.
97
- *
98
- * Note: This HoC passes a number of props to the wrapped component that should be passed to the
99
- * main DOM node.
100
- *
101
- * Example:
102
- * ```
103
- * const Component = ({myProp, ...rest}) => (
104
- * <div {...rest}>{myProp}</div>
105
- * );
106
- * ...
107
- * const SpottableComponent = Spottable(Component);
108
- * ```
109
- * @class Spottable
110
- * @memberof spotlight/Spottable
111
- * @param {Object} defaultConfig Set of default configuration parameters
112
- * @param {Function} Wrapped Component to wrap
113
- *
114
- * @hoc
115
- * @returns {Function} Spottable
116
- */
117
-
118
- var Spottable = (0, _hoc["default"])(defaultConfig, function (config, Wrapped) {
119
- var _class, _temp;
120
-
121
- var emulateMouse = config.emulateMouse;
122
- return _temp = _class = /*#__PURE__*/function (_React$Component) {
123
- _inherits(_class, _React$Component);
124
-
125
- var _super = _createSuper(_class);
126
-
127
- function _class(_props) {
128
- var _this;
129
-
130
- _classCallCheck(this, _class);
131
-
132
- _this = _super.call(this, _props);
133
-
134
- _this.shouldEmulateMouse = function (ev, props) {
135
- if (!emulateMouse) {
136
- return;
137
- }
138
-
139
- var currentTarget = ev.currentTarget,
140
- repeat = ev.repeat,
141
- type = ev.type,
142
- which = ev.which;
143
- var selectionKeys = props.selectionKeys;
144
- var keyboardAccessible = isKeyboardAccessible(currentTarget);
145
- var keyCode = selectionKeys.find(function (value) {
146
- return (// emulate mouse events for any remote okay button event
147
- which === REMOTE_OK_KEY || // or a non-keypress selection event or any selection event on a non-keyboard accessible
148
- // control
149
- which === value && (type !== 'keypress' || !keyboardAccessible)
150
- );
151
- });
152
-
153
- if ((0, _spotlight.getDirection)(keyCode)) {
154
- (0, _handle.preventDefault)(ev);
155
- (0, _handle.stop)(ev);
156
- } else if (keyCode && keyboardAccessible) {
157
- (0, _handle.preventDefault)(ev);
158
- }
159
-
160
- return keyCode && !repeat;
161
- };
162
-
163
- _this.forwardSpotlightEvents = function (ev, _ref) {
164
- var onSpotlightDown = _ref.onSpotlightDown,
165
- onSpotlightLeft = _ref.onSpotlightLeft,
166
- onSpotlightRight = _ref.onSpotlightRight,
167
- onSpotlightUp = _ref.onSpotlightUp;
168
- var keyCode = ev.keyCode;
169
-
170
- if (onSpotlightDown && (0, _keymap.is)('down', keyCode)) {
171
- onSpotlightDown(ev);
172
- } else if (onSpotlightLeft && (0, _keymap.is)('left', keyCode)) {
173
- onSpotlightLeft(ev);
174
- } else if (onSpotlightRight && (0, _keymap.is)('right', keyCode)) {
175
- onSpotlightRight(ev);
176
- } else if (onSpotlightUp && (0, _keymap.is)('up', keyCode)) {
177
- onSpotlightUp(ev);
178
- }
179
-
180
- return true;
181
- };
182
-
183
- _this.handleSelect = function (_ref2, props) {
184
- var which = _ref2.which;
185
- var selectionKeys = props.selectionKeys; // Only apply accelerator if handling a selection key
186
-
187
- if (selectionKeys.find(function (value) {
188
- return which === value;
189
- })) {
190
- if (selectCancelled || lastSelectTarget && lastSelectTarget !== _assertThisInitialized(_this)) {
191
- return false;
192
- }
193
-
194
- lastSelectTarget = _assertThisInitialized(_this);
195
- }
196
-
197
- return true;
198
- };
199
-
200
- _this.forwardAndResetLastSelectTarget = function (ev, props) {
201
- var keyCode = ev.keyCode;
202
- var selectionKeys = props.selectionKeys;
203
- var key = selectionKeys.find(function (value) {
204
- return keyCode === value;
205
- }); // FIXME: temporary patch to maintain compatibility with moonstone 3.2.5 which
206
- // deconstructs `preventDefault` from the event which is incompatible with React's
207
- // synthetic event.
208
-
209
- ev.preventDefault = ev.preventDefault.bind(ev);
210
- (0, _handle.forward)('onKeyUp', ev, props);
211
- var notPrevented = !ev.defaultPrevented; // bail early for non-selection keyup to avoid clearing lastSelectTarget prematurely
212
-
213
- if (!key && (!(0, _keymap.is)('enter', keyCode) || !(0, _spotlight.getDirection)(keyCode))) {
214
- return notPrevented;
215
- }
216
-
217
- var allow = lastSelectTarget === _assertThisInitialized(_this);
218
-
219
- selectCancelled = false;
220
- lastSelectTarget = null;
221
- return notPrevented && allow;
222
- };
223
-
224
- _this.isActionable = function (ev, props) {
225
- return isSpottable(props);
226
- };
227
-
228
- _this.handle = _handle.handle.bind(_assertThisInitialized(_this));
229
- _this.handleKeyDown = _this.handle((0, _handle.forward)('onKeyDown'), function (ev) {
230
- return !ev.defaultPrevented;
231
- }, _this.forwardSpotlightEvents, _this.isActionable, _this.handleSelect, _this.shouldEmulateMouse, (0, _handle.forward)('onMouseDown'));
232
- _this.handleKeyUp = _this.handle(_this.forwardAndResetLastSelectTarget, _this.isActionable, _this.shouldEmulateMouse, (0, _handle.forward)('onMouseUp'), (0, _handle.forward)('onClick'));
233
-
234
- _this.handleBlur = function (ev) {
235
- if (_this.shouldPreventBlur) return;
236
-
237
- if (ev.currentTarget === ev.target) {
238
- _this.isFocused = false;
239
-
240
- if (_this.focusedWhenDisabled) {
241
- _this.focusedWhenDisabled = false; // We only need to trigger a rerender if a focused item becomes disabled and still needs its focus.
242
- // Once it blurs we need to rerender to remove the spottable class so it will not spot again.
243
- // The reason we don't use state is for performance reasons to avoid updates.
244
-
245
- _this.forceUpdate();
246
- }
247
- }
248
-
249
- if (_spotlight.Spotlight.isMuted(ev.target)) {
250
- ev.stopPropagation();
251
- } else {
252
- (0, _handle.forward)('onBlur', ev, _this.props);
253
- }
254
- };
255
-
256
- _this.handleFocus = function (ev) {
257
- if (_this.props.spotlightDisabled) {
258
- _this.shouldPreventBlur = true;
259
- ev.target.blur();
260
- _this.shouldPreventBlur = false;
261
- return;
262
- }
263
-
264
- if (ev.currentTarget === ev.target) {
265
- _this.isFocused = true;
266
- }
267
-
268
- if (_spotlight.Spotlight.isMuted(ev.target)) {
269
- ev.stopPropagation();
270
- } else {
271
- (0, _handle.forward)('onFocus', ev, _this.props);
272
- }
273
- };
274
-
275
- _this.handleEnter = function (ev) {
276
- (0, _handle.forward)('onMouseEnter', ev, _this.props);
277
- _this.isHovered = true;
278
- };
279
-
280
- _this.handleLeave = function (ev) {
281
- (0, _handle.forward)('onMouseLeave', ev, _this.props);
282
- _this.isHovered = false;
283
- };
284
-
285
- _this.isHovered = false; // Used to indicate that we want to stop propagation on blur events that occur as a
286
- // result of this component imperatively blurring itself on focus when spotlightDisabled
287
-
288
- _this.shouldPreventBlur = false;
289
- _this.isFocused = false;
290
- _this.focusedWhenDisabled = false;
291
- return _this;
292
- }
293
-
294
- _createClass(_class, [{
295
- key: "componentDidMount",
296
- value: function componentDidMount() {
297
- // eslint-disable-next-line react/no-find-dom-node
298
- this.node = _reactDom["default"].findDOMNode(this);
299
- }
300
- }, {
301
- key: "componentDidUpdate",
302
- value: function componentDidUpdate(prevProps) {
303
- this.isFocused = this.node && _spotlight.Spotlight.getCurrent() === this.node; // if the component is focused and became disabled
304
-
305
- if (this.isFocused && this.props.disabled && lastSelectTarget === this && !selectCancelled) {
306
- selectCancelled = true;
307
- (0, _handle.forward)('onMouseUp', null, this.props);
308
- } // if the component became enabled, notify spotlight to enable restoring "lost" focus
309
-
310
-
311
- if (isSpottable(this.props) && !isSpottable(prevProps) && !_spotlight.Spotlight.isPaused()) {
312
- if (_spotlight.Spotlight.getPointerMode()) {
313
- if (this.isHovered) {
314
- _spotlight.Spotlight.setPointerMode(false);
315
-
316
- _spotlight.Spotlight.focus(this.node);
317
-
318
- _spotlight.Spotlight.setPointerMode(true);
319
- }
320
- } else if (!_spotlight.Spotlight.getCurrent()) {
321
- var containers = (0, _container.getContainersForNode)(this.node);
322
-
323
- var containerId = _spotlight.Spotlight.getActiveContainer();
324
-
325
- if (containers.indexOf(containerId) >= 0) {
326
- _spotlight.Spotlight.focus(containerId);
327
- }
328
- }
329
- }
330
- }
331
- }, {
332
- key: "componentWillUnmount",
333
- value: function componentWillUnmount() {
334
- if (this.isFocused) {
335
- (0, _handle.forward)('onSpotlightDisappear', null, this.props);
336
- }
337
-
338
- if (lastSelectTarget === this) {
339
- lastSelectTarget = null;
340
- }
341
- }
342
- }, {
343
- key: "render",
344
- value: function render() {
345
- var _this$props = this.props,
346
- disabled = _this$props.disabled,
347
- spotlightId = _this$props.spotlightId,
348
- spotlightDisabled = _this$props.spotlightDisabled,
349
- rest = _objectWithoutProperties(_this$props, ["disabled", "spotlightId", "spotlightDisabled"]);
350
-
351
- this.focusedWhenDisabled = this.isFocused && spotlightDisabled;
352
- var spottable = this.focusedWhenDisabled || isSpottable(this.props);
353
- var tabIndex = rest.tabIndex;
354
- delete rest.onSpotlightDisappear;
355
- delete rest.onSpotlightDown;
356
- delete rest.onSpotlightLeft;
357
- delete rest.onSpotlightRight;
358
- delete rest.onSpotlightUp;
359
- delete rest.selectionKeys;
360
- delete rest.spotlightDisabled;
361
-
362
- if (tabIndex == null) {
363
- tabIndex = -1;
364
- }
365
-
366
- if (spottable) {
367
- if (rest.className) {
368
- rest.className += ' ' + spottableClass;
369
- } else {
370
- rest.className = spottableClass;
371
- }
372
- }
373
-
374
- if (spotlightId) {
375
- rest['data-spotlight-id'] = spotlightId;
376
- }
377
-
378
- return /*#__PURE__*/_react["default"].createElement(Wrapped, Object.assign({}, rest, {
379
- onBlur: this.handleBlur,
380
- onFocus: this.handleFocus,
381
- onMouseEnter: this.handleEnter,
382
- onMouseLeave: this.handleLeave,
383
- onKeyDown: this.handleKeyDown,
384
- onKeyUp: this.handleKeyUp,
385
- disabled: disabled,
386
- tabIndex: tabIndex
387
- }));
388
- }
389
- }]);
390
-
391
- return _class;
392
- }(_react["default"].Component), _class.displayName = 'Spottable', _class.propTypes =
393
- /** @lends spotlight/Spottable.Spottable.prototype */
394
- {
395
- /**
396
- * Whether or not the component is in a disabled state.
397
- *
398
- * @type {Boolean}
399
- * @default false
400
- * @public
401
- */
402
- disabled: _propTypes["default"].bool,
403
-
404
- /**
405
- * The handler to run when the component is removed while retaining focus.
406
- *
407
- * @type {Function}
408
- * @param {Object} event
409
- * @public
410
- */
411
- onSpotlightDisappear: _propTypes["default"].func,
412
-
413
- /**
414
- * The handler to run when the 5-way down key is pressed.
415
- *
416
- * @type {Function}
417
- * @param {Object} event
418
- * @public
419
- */
420
- onSpotlightDown: _propTypes["default"].func,
421
-
422
- /**
423
- * The handler to run when the 5-way left key is pressed.
424
- *
425
- * @type {Function}
426
- * @param {Object} event
427
- * @public
428
- */
429
- onSpotlightLeft: _propTypes["default"].func,
430
-
431
- /**
432
- * The handler to run when the 5-way right key is pressed.
433
- *
434
- * @type {Function}
435
- * @param {Object} event
436
- * @public
437
- */
438
- onSpotlightRight: _propTypes["default"].func,
439
-
440
- /**
441
- * The handler to run when the 5-way up key is pressed.
442
- *
443
- * @type {Function}
444
- * @param {Object} event
445
- * @public
446
- */
447
- onSpotlightUp: _propTypes["default"].func,
448
-
449
- /**
450
- * An array of numbers representing keyCodes that should trigger mouse event
451
- * emulation when `emulateMouse` is `true`. If a keyCode equals a directional
452
- * key, then default 5-way navigation will be prevented when that key is pressed.
453
- *
454
- * @type {Number[]}
455
- * @default [13, 16777221]
456
- * @public
457
- */
458
- selectionKeys: _propTypes["default"].arrayOf(_propTypes["default"].number),
459
-
460
- /**
461
- * When `true`, the component cannot be navigated using spotlight.
462
- *
463
- * @type {Boolean}
464
- * @default false
465
- * @public
466
- */
467
- spotlightDisabled: _propTypes["default"].bool,
468
-
469
- /**
470
- * Used to identify this component within the Spotlight system
471
- *
472
- * @type {String}
473
- * @public
474
- */
475
- spotlightId: _propTypes["default"].string,
476
-
477
- /**
478
- * The tabIndex of the component. This value will default to -1 if left
479
- * unset and the control is spottable.
480
- *
481
- * @type {Number}
482
- * @public
483
- */
484
- tabIndex: _propTypes["default"].number
485
- }, _class.defaultProps = {
486
- selectionKeys: [ENTER_KEY, REMOTE_OK_KEY]
487
- }, _temp;
488
- });
489
- exports.Spottable = Spottable;
490
- var _default = Spottable;
491
- exports["default"] = _default;
@@ -1,3 +0,0 @@
1
- {
2
- "main": "Spottable.js"
3
- }
@@ -1,90 +0,0 @@
1
- "use strict";
2
-
3
- var _enzyme = require("enzyme");
4
-
5
- var _react = _interopRequireDefault(require("react"));
6
-
7
- var _Spottable = _interopRequireDefault(require("../Spottable"));
8
-
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
-
11
- describe('Spottable', function () {
12
- test('should add the spottable class', function () {
13
- var Component = (0, _Spottable["default"])('div');
14
- var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, null));
15
- var expected = 'spottable';
16
- var actual = subject.find('div').prop('className');
17
- expect(actual).toEqual(expected);
18
- });
19
- test('should add the spottable class to a {disabled} component', function () {
20
- var Component = (0, _Spottable["default"])('div');
21
- var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, {
22
- disabled: true
23
- }));
24
- var expected = 'spottable';
25
- var actual = subject.find('div').prop('className');
26
- expect(actual).toEqual(expected);
27
- });
28
- test('should not add the spottable class to a {spotlightDisabled} component', function () {
29
- var Component = (0, _Spottable["default"])('div');
30
- var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, {
31
- spotlightDisabled: true
32
- }));
33
- var expected = 'spottable';
34
- var actual = subject.find('div').prop('className');
35
- expect(actual).not.toEqual(expected);
36
- });
37
- test('should emit {onSpotlightDisappear} when unmounted while focused', function () {
38
- var spy = jest.fn();
39
- var Component = (0, _Spottable["default"])('div');
40
- var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, {
41
- onSpotlightDisappear: spy
42
- }));
43
- subject.simulate('focus');
44
- subject.unmount();
45
- var expected = 1;
46
- var actual = spy.mock.calls.length;
47
- expect(actual).toEqual(expected);
48
- });
49
- describe('shouldComponentUpdate', function () {
50
- test('should re-render when a non-Spottable prop changes', function () {
51
- var spy = jest.fn(function (props) {
52
- return /*#__PURE__*/_react["default"].createElement("div", props);
53
- });
54
- var Component = (0, _Spottable["default"])(spy);
55
- var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, null));
56
- subject.setProps({
57
- 'data-id': '123'
58
- });
59
- var expected = 2;
60
- var actual = spy.mock.calls.length;
61
- expect(actual).toEqual(expected);
62
- });
63
- test('should re-render when {selectionKeys} changes', function () {
64
- var spy = jest.fn(function (props) {
65
- return /*#__PURE__*/_react["default"].createElement("div", props);
66
- });
67
- var Component = (0, _Spottable["default"])(spy);
68
- var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, {
69
- selectionKeys: [1, 2, 3]
70
- }));
71
- subject.setProps({
72
- selectionKeys: [2, 1, 3]
73
- });
74
- var expected = 2;
75
- var actual = spy.mock.calls.length;
76
- expect(actual).toEqual(expected);
77
- });
78
- test('should not re-render when focused', function () {
79
- var spy = jest.fn(function (props) {
80
- return /*#__PURE__*/_react["default"].createElement("div", props);
81
- });
82
- var Component = (0, _Spottable["default"])(spy);
83
- var subject = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(Component, null));
84
- subject.simulate('focus');
85
- var expected = 1;
86
- var actual = spy.mock.calls.length;
87
- expect(actual).toEqual(expected);
88
- });
89
- });
90
- });