@enact/spotlight 4.1.1 → 4.1.4

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.
@@ -4,14 +4,11 @@ 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 declare class Accelerator {
7
- constructor(
8
- /**
7
+ constructor /**
9
8
  * Controls the frequency with which the acceleration will
10
9
  "freeze". While frozen, the current target item cannot change, and all events are directed
11
10
  to it.
12
- */
13
- frequency: number[]
14
- );
11
+ */(frequency: number[]);
15
12
  /**
16
13
  * Called with the current keydown event and callback, which will be called when the event is
17
14
  allowed through.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,23 @@
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
+ ## [4.1.4] - 2022-03-24
6
+
7
+ No significant changes.
8
+
9
+ ## [4.1.3] - 2022-03-07
10
+
11
+ - Updated to use `forwardCustom` and add `type` when forwarding custom events
12
+
13
+ ### Fixed
14
+
15
+ - `spotlight` to correctly control focus when boundaries of an element are not integers
16
+ - Styles for `debug spotlight` option in samplers to work properly
17
+
18
+ ## [4.1.2] - 2021-12-22
19
+
20
+ No significant changes.
21
+
5
22
  ## [4.1.1] - 2021-11-30
6
23
 
7
24
  No significant changes.
package/Pause/Pause.d.ts CHANGED
@@ -12,12 +12,10 @@ paused spotlight and can be used as an escape hatch to force resumption.
12
12
  */
13
13
 
14
14
  export declare class Pause {
15
- constructor(
16
- /**
17
- * The name of the pause instance
18
- */
19
- name: string
20
- );
15
+ constructor
16
+ /**
17
+ * The name of the pause instance
18
+ */(name: string);
21
19
  /**
22
20
  * Returns `true` when Spotlight is paused by this instance
23
21
  */
package/README.md CHANGED
@@ -43,7 +43,7 @@ Spotlight is based on a fork of [JavaScript SpatialNavigation](https://github.co
43
43
  Unless otherwise specified, all content, including all source code files and
44
44
  documentation files in this repository are:
45
45
 
46
- Copyright (c) 2012-2021 LG Electronics
46
+ Copyright (c) 2012-2022 LG Electronics
47
47
 
48
48
  Unless otherwise specified or set forth in the NOTICE file, all content,
49
49
  including all source code files and documentation files in this repository are:
@@ -1,13 +1,17 @@
1
1
  "use strict";
2
2
 
3
- var _enzyme = require("enzyme");
3
+ require("@testing-library/jest-dom");
4
4
 
5
- var _spotlight = _interopRequireDefault(require("../../src/spotlight"));
5
+ var _react = require("@testing-library/react");
6
6
 
7
- var _pointer = require("../../src/pointer");
7
+ var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
8
8
 
9
9
  var _SpotlightContainerDecorator = _interopRequireDefault(require("../SpotlightContainerDecorator"));
10
10
 
11
+ var _pointer = require("../../src/pointer");
12
+
13
+ var _spotlight = _interopRequireDefault(require("../../src/spotlight"));
14
+
11
15
  var _ElementPrototype = _interopRequireDefault(require("./Element.prototype.closest"));
12
16
 
13
17
  var _jsxRuntime = require("react/jsx-runtime");
@@ -20,6 +24,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
20
24
 
21
25
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
22
26
 
27
+ var testId = 'test-spotlightContainerDecorator';
23
28
  describe('SpotlightContainerDecorator', function () {
24
29
  var hoverPosition = {
25
30
  clientX: 0,
@@ -42,10 +47,15 @@ describe('SpotlightContainerDecorator', function () {
42
47
  });
43
48
  test('should set itself as the active container on mouse enter', function () {
44
49
  var Component = (0, _SpotlightContainerDecorator["default"])(Div);
45
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
50
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
51
+ "data-testid": testId,
46
52
  spotlightId: "test-container"
47
53
  }));
48
- subject.find(Div).prop('onMouseEnter')(hoverPosition);
54
+
55
+ var component = _react.screen.getByTestId(testId);
56
+
57
+ _userEvent["default"].hover(component, hoverPosition);
58
+
49
59
  var expected = 'test-container';
50
60
 
51
61
  var actual = _spotlight["default"].getActiveContainer();
@@ -55,24 +65,25 @@ describe('SpotlightContainerDecorator', function () {
55
65
  test('should set active container to parent container on mouse leave', function () {
56
66
  var Component = (0, _SpotlightContainerDecorator["default"])(Div);
57
67
  var node = document.createElement('div');
58
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
68
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
59
69
  spotlightId: "outer-container",
60
70
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
71
+ "data-testid": testId,
61
72
  spotlightId: "inner-container"
62
73
  })
63
74
  }), {
64
75
  attachTo: node
65
76
  });
66
- var selector = 'div[data-spotlight-id="inner-container"]';
67
- var innerWrapper = subject.find(selector);
68
- var innerNode = node.querySelector(selector); // set inner-container as active
69
77
 
70
- innerWrapper.prop('onMouseEnter')(hoverPosition);
78
+ var component = _react.screen.getByTestId(testId); // set inner-container as active
79
+
80
+
81
+ _userEvent["default"].hover(component, hoverPosition);
82
+
71
83
  (0, _pointer.updatePointerPosition)(0, 1); // leave inner-container
72
84
 
73
- innerWrapper.prop('onMouseLeave')(_objectSpread(_objectSpread({}, unhoverPosition), {}, {
74
- currentTarget: innerNode
75
- }));
85
+ _userEvent["default"].unhover(component, unhoverPosition);
86
+
76
87
  var expected = 'outer-container';
77
88
 
78
89
  var actual = _spotlight["default"].getActiveContainer();
@@ -82,9 +93,10 @@ describe('SpotlightContainerDecorator', function () {
82
93
  test('should not set active container on mouse leave if another container is active', function () {
83
94
  var Component = (0, _SpotlightContainerDecorator["default"])(Div);
84
95
  var node = document.createElement('div');
85
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsxs)(Component, {
96
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsxs)(Component, {
86
97
  spotlightId: "outer-container",
87
98
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
99
+ "data-testid": testId,
88
100
  spotlightId: "inner-container"
89
101
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
90
102
  spotlightId: "self-only-container"
@@ -92,19 +104,19 @@ describe('SpotlightContainerDecorator', function () {
92
104
  }), {
93
105
  attachTo: node
94
106
  });
95
- var selector = 'div[data-spotlight-id="inner-container"]';
96
- var innerWrapper = subject.find(selector);
97
- var innerNode = node.querySelector(selector); // set inner-container as active
98
107
 
99
- innerWrapper.prop('onMouseEnter')(hoverPosition);
108
+ var component = _react.screen.getByTestId(testId); // set inner-container as active
109
+
110
+
111
+ _userEvent["default"].hover(component, hoverPosition);
112
+
100
113
  (0, _pointer.updatePointerPosition)(0, 1); // set another container to be active
101
114
 
102
115
  _spotlight["default"].setActiveContainer('self-only-container'); // leave inner-container
103
116
 
104
117
 
105
- innerWrapper.prop('onMouseLeave')(_objectSpread(_objectSpread({}, unhoverPosition), {}, {
106
- currentTarget: innerNode
107
- }));
118
+ _userEvent["default"].unhover(component, unhoverPosition);
119
+
108
120
  var expected = 'self-only-container';
109
121
 
110
122
  var actual = _spotlight["default"].getActiveContainer();
@@ -119,13 +131,12 @@ describe('SpotlightContainerDecorator', function () {
119
131
  focus = onFocusCapture;
120
132
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
121
133
  });
122
- (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
134
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
123
135
  onFocusCapture: spy
124
136
  }));
125
137
  focus({});
126
138
  var expected = 1;
127
- var actual = spy.mock.calls.length;
128
- expect(actual).toBe(expected);
139
+ expect(spy).toHaveBeenCalledTimes(expected);
129
140
  });
130
141
  test('should suppress onFocusCapture events when spotlightDisabled', function () {
131
142
  var spy = jest.fn();
@@ -135,7 +146,7 @@ describe('SpotlightContainerDecorator', function () {
135
146
  focus = onFocusCapture;
136
147
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
137
148
  });
138
- (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
149
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
139
150
  onFocusCapture: spy,
140
151
  spotlightDisabled: true
141
152
  })); // building out the api called on the event object + target
@@ -150,9 +161,7 @@ describe('SpotlightContainerDecorator', function () {
150
161
  }
151
162
  }
152
163
  });
153
- var expected = 0;
154
- var actual = spy.mock.calls.length;
155
- expect(actual).toBe(expected);
164
+ expect(spy).not.toHaveBeenCalled();
156
165
  });
157
166
  test('should forward onBlurCapture events', function () {
158
167
  var spy = jest.fn();
@@ -164,7 +173,7 @@ describe('SpotlightContainerDecorator', function () {
164
173
  _blur = onBlurCapture;
165
174
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
166
175
  });
167
- (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
176
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
168
177
  onBlurCapture: spy,
169
178
  spotlightDisabled: true
170
179
  })); // building out the api called on the event object + target
@@ -181,15 +190,14 @@ describe('SpotlightContainerDecorator', function () {
181
190
  });
182
191
 
183
192
  var expected = 1;
184
- var actual = spy.mock.calls.length;
185
- expect(actual).toBe(expected);
193
+ expect(spy).toHaveBeenCalledTimes(expected);
186
194
  });
187
195
  test('should suppress onBlurCapture events when focus was suppressed', function () {
188
196
  var spy = jest.fn();
189
- var focus;
190
197
 
191
198
  var _blur2;
192
199
 
200
+ var focus;
193
201
  var Component = (0, _SpotlightContainerDecorator["default"])(function (_ref4) {
194
202
  var onBlurCapture = _ref4.onBlurCapture,
195
203
  onFocusCapture = _ref4.onFocusCapture;
@@ -197,7 +205,7 @@ describe('SpotlightContainerDecorator', function () {
197
205
  focus = onFocusCapture;
198
206
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
199
207
  });
200
- (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
208
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
201
209
  onBlurCapture: spy,
202
210
  spotlightDisabled: true
203
211
  })); // building out the api called on the event object + target
@@ -216,8 +224,6 @@ describe('SpotlightContainerDecorator', function () {
216
224
  }
217
225
  }
218
226
  });
219
- var expected = 0;
220
- var actual = spy.mock.calls.length;
221
- expect(actual).toBe(expected);
227
+ expect(spy).not.toHaveBeenCalled();
222
228
  });
223
229
  });
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
 
3
- var _enzyme = require("enzyme");
3
+ require("@testing-library/jest-dom");
4
4
 
5
- var _spotlight = _interopRequireDefault(require("../../src/spotlight"));
5
+ var _react = require("@testing-library/react");
6
+
7
+ var _useSpotlightContainer = _interopRequireDefault(require("../useSpotlightContainer"));
6
8
 
7
9
  var _container = require("../../src/container");
8
10
 
9
- var _useSpotlightContainer = _interopRequireDefault(require("../useSpotlightContainer"));
11
+ var _spotlight = _interopRequireDefault(require("../../src/spotlight"));
10
12
 
11
13
  var _jsxRuntime = require("react/jsx-runtime");
12
14
 
@@ -26,6 +28,7 @@ function containerExists(id) {
26
28
  return (0, _container.getContainerConfig)(id) != null;
27
29
  }
28
30
 
31
+ var testId = 'test-useSpotlightContainer';
29
32
  describe('useSpotlightContainer', function () {
30
33
  // TODO: Test lifecycle (e.g unload, preserveId)
31
34
  function Component(props) {
@@ -52,77 +55,122 @@ describe('useSpotlightContainer', function () {
52
55
 
53
56
  afterEach(_spotlight["default"].clear);
54
57
  test('should support omitting the config object', function () {
55
- function Comp(props) {
58
+ var Comp = function Comp(props) {
56
59
  var spotlightContainer = (0, _useSpotlightContainer["default"])();
57
60
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, props), spotlightContainer.attributes));
58
- }
61
+ };
62
+
63
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {
64
+ "data-testid": testId
65
+ }));
59
66
 
60
- var subject = (0, _enzyme.shallow)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {}));
61
- var expected = true;
62
- var actual = subject.prop('data-spotlight-container');
63
- expect(actual).toBe(expected);
67
+ var component = _react.screen.getByTestId(testId);
68
+
69
+ var expectedAttribute = 'data-spotlight-container';
70
+ var expectedValue = 'true';
71
+ expect(component).toHaveAttribute(expectedAttribute, expectedValue);
64
72
  });
65
73
  describe('attributes', function () {
66
74
  test('should set `data-spotlight-container` attribute', function () {
67
- var subject = (0, _enzyme.shallow)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
68
- var expected = true;
69
- var actual = subject.prop('data-spotlight-container');
70
- expect(actual).toBe(expected);
75
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
76
+ "data-testid": testId
77
+ }));
78
+
79
+ var component = _react.screen.getByTestId(testId);
80
+
81
+ var expectedAttribute = 'data-spotlight-container';
82
+ var expectedValue = 'true';
83
+ expect(component).toHaveAttribute(expectedAttribute, expectedValue);
71
84
  });
72
85
  test('should generate a `data-spotlight-id` attribute when `id` is unset', function () {
73
- var subject = (0, _enzyme.shallow)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
74
- var expected = /container-\d+/;
75
- var actual = subject.prop('data-spotlight-id');
76
- expect(actual).toMatch(expected);
86
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
87
+ "data-testid": testId
88
+ }));
89
+
90
+ var component = _react.screen.getByTestId(testId);
91
+
92
+ var expectedAttribute = 'data-spotlight-id';
93
+ var expectedValue = expect.stringMatching(/container-\d+/);
94
+ expect(component).toHaveAttribute(expectedAttribute, expectedValue);
77
95
  });
78
96
  test('should reuse the same generated `data-spotlight-id` attribute on re-render', function () {
79
- var subject = (0, _enzyme.shallow)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
80
- var expected = subject.prop('data-spotlight-id');
81
- subject.setProps({});
82
- var actual = subject.prop('data-spotlight-id');
83
- expect(actual).toMatch(expected);
97
+ var _render = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
98
+ "data-testid": testId
99
+ })),
100
+ rerender = _render.rerender;
101
+
102
+ var expected = _react.screen.getByTestId(testId).getAttribute('data-spotlight-id');
103
+
104
+ rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
105
+ "data-testid": testId
106
+ }));
107
+
108
+ var actual = _react.screen.getByTestId(testId).getAttribute('data-spotlight-id');
109
+
110
+ expect(actual).toBe(expected);
84
111
  });
85
112
  test('should set a `data-spotlight-id` attribute when `id` is set', function () {
86
113
  var id = 'my-container';
87
- var subject = (0, _enzyme.shallow)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
114
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
115
+ "data-testid": testId,
88
116
  spotlightId: id
89
117
  }));
90
- var expected = id;
91
- var actual = subject.prop('data-spotlight-id');
92
- expect(actual).toBe(expected);
118
+
119
+ var component = _react.screen.getByTestId(testId);
120
+
121
+ var expectedAttribute = 'data-spotlight-id';
122
+ expect(component).toHaveAttribute(expectedAttribute, id);
93
123
  });
94
124
  test('should set `data-spotlight-container-disabled` attribute to be falsey when `disabled` is unset', function () {
95
- var subject = (0, _enzyme.shallow)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
96
- var actual = subject.prop('data-spotlight-container-disabled');
97
- expect(actual).toBeFalsy();
125
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
126
+ "data-testid": testId
127
+ }));
128
+
129
+ var component = _react.screen.getByTestId(testId);
130
+
131
+ var expectedAttribute = 'data-spotlight-container-disabled';
132
+ expect(component).not.toHaveAttribute(expectedAttribute);
98
133
  });
99
134
  test('should set `data-spotlight-container-disabled` attribute when `disabled` is set', function () {
100
- var subject = (0, _enzyme.shallow)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
135
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
136
+ "data-testid": testId,
101
137
  spotlightDisabled: true
102
138
  }));
103
- var expected = true;
104
- var actual = subject.prop('data-spotlight-container-disabled');
105
- expect(actual).toBe(expected);
139
+
140
+ var component = _react.screen.getByTestId(testId);
141
+
142
+ var expectedAttribute = 'data-spotlight-container-disabled';
143
+ var expectedValue = 'true';
144
+ expect(component).toHaveAttribute(expectedAttribute, expectedValue);
106
145
  });
107
146
  test('should set `data-spotlight-container-muted` attribute to be falsey when `muted` is unset', function () {
108
- var subject = (0, _enzyme.shallow)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
109
- var actual = subject.prop('data-spotlight-container-muted');
110
- expect(actual).toBeFalsy();
147
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
148
+ "data-testid": testId
149
+ }));
150
+
151
+ var component = _react.screen.getByTestId(testId);
152
+
153
+ var expectedAttribute = 'data-spotlight-container-muted';
154
+ expect(component).not.toHaveAttribute(expectedAttribute);
111
155
  });
112
156
  test('should set `data-spotlight-container-muted` attribute when `muted` is set', function () {
113
- var subject = (0, _enzyme.shallow)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
157
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
158
+ "data-testid": testId,
114
159
  spotlightMuted: true
115
160
  }));
116
- var expected = true;
117
- var actual = subject.prop('data-spotlight-container-muted');
118
- expect(actual).toBe(expected);
161
+
162
+ var component = _react.screen.getByTestId(testId);
163
+
164
+ var expectedAttribute = 'data-spotlight-container-muted';
165
+ var expectedValue = 'true';
166
+ expect(component).toHaveAttribute(expectedAttribute, expectedValue);
119
167
  });
120
168
  });
121
169
  describe('Spotlight configuration', function () {
122
170
  test('should create a new container with the specified id', function () {
123
171
  var id = 'my-container';
124
172
  expect(containerExists(id)).toBeFalsy();
125
- (0, _enzyme.shallow)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
173
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
126
174
  spotlightId: id
127
175
  }));
128
176
  var expected = true;
@@ -136,12 +184,12 @@ describe('useSpotlightContainer', function () {
136
184
  restrict: 'self-only',
137
185
  defaultElement: 'my-element'
138
186
  };
139
- (0, _enzyme.shallow)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
140
- spotlightId: id,
141
- spotlightRestrict: config.restrict,
187
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
142
188
  containerConfig: {
143
189
  defaultElement: config.defaultElement
144
- }
190
+ },
191
+ spotlightId: id,
192
+ spotlightRestrict: config.restrict
145
193
  }));
146
194
  var expected = config;
147
195
  var actual = (0, _container.getContainerConfig)(id);
@@ -149,13 +197,17 @@ describe('useSpotlightContainer', function () {
149
197
  });
150
198
  test('should update restrict value', function () {
151
199
  var id = 'my-container';
152
- var subject = (0, _enzyme.shallow)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
200
+
201
+ var _render2 = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
153
202
  spotlightId: id,
154
203
  spotlightRestrict: "self-only"
204
+ })),
205
+ rerender = _render2.rerender;
206
+
207
+ rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
208
+ spotlightId: id,
209
+ spotlightRestrict: "self-first"
155
210
  }));
156
- subject.setProps({
157
- spotlightRestrict: 'self-first'
158
- });
159
211
  var expected = {
160
212
  restrict: 'self-first'
161
213
  };
@@ -189,13 +189,6 @@ var SpotlightRootDecorator = (0, _hoc["default"])(defaultConfig, function (confi
189
189
  }
190
190
  };
191
191
 
192
- _this.navigableFilter = function (elem) {
193
- while (elem && elem !== document && elem.nodeType === 1) {
194
- if (elem.getAttribute('data-spotlight-container-disabled') === 'true') return false;
195
- elem = elem.parentNode;
196
- }
197
- };
198
-
199
192
  _this.containerNode = null;
200
193
 
201
194
  if (typeof window === 'object') {
@@ -59,7 +59,7 @@ var SpottableCore = /*#__PURE__*/function () {
59
59
 
60
60
  if (_this.isFocused && _this.props.disabled && lastSelectTarget === _this && !selectCancelled) {
61
61
  selectCancelled = true;
62
- (0, _handle.forward)('onSelectionCancel', null, _this.props);
62
+ (0, _handle.forwardCustom)('onSelectionCancel')(null, _this.props);
63
63
  } // if the component became enabled, notify spotlight to enable restoring "lost" focus
64
64
 
65
65
 
@@ -263,7 +263,7 @@ var SpottableCore = /*#__PURE__*/function () {
263
263
  key: "unload",
264
264
  value: function unload() {
265
265
  if (this.isFocused) {
266
- (0, _handle.forward)('onSpotlightDisappear', null, this.props);
266
+ (0, _handle.forwardCustom)('onSpotlightDisappear')(null, this.props);
267
267
  }
268
268
 
269
269
  if (lastSelectTarget === this) {
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
 
3
- var _enzyme = require("enzyme");
3
+ require("@testing-library/jest-dom");
4
+
5
+ var _react = require("@testing-library/react");
4
6
 
5
7
  var _Spottable = _interopRequireDefault(require("../Spottable"));
6
8
 
@@ -14,43 +16,62 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
14
16
 
15
17
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
18
 
19
+ var id = 'test-spottable';
17
20
  describe('Spottable', function () {
18
21
  test('should add the spottable class', function () {
19
22
  var Component = (0, _Spottable["default"])('div');
20
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
21
- var expected = 'spottable';
22
- var actual = subject.find('div').prop('className');
23
- expect(actual).toEqual(expected);
23
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
24
+ "data-testid": id
25
+ }));
26
+
27
+ var div = _react.screen.getByTestId(id);
28
+
29
+ var expectedClass = 'spottable';
30
+ expect(div).toHaveClass(expectedClass);
24
31
  });
25
32
  test('should add the spottable class to a {disabled} component', function () {
26
33
  var Component = (0, _Spottable["default"])('div');
27
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
34
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
35
+ "data-testid": id,
28
36
  disabled: true
29
37
  }));
30
- var expected = 'spottable';
31
- var actual = subject.find('div').prop('className');
32
- expect(actual).toEqual(expected);
38
+
39
+ var div = _react.screen.getByTestId(id);
40
+
41
+ var expectedClass = 'spottable';
42
+ expect(div).toHaveClass(expectedClass);
33
43
  });
34
44
  test('should not add the spottable class to a {spotlightDisabled} component', function () {
35
45
  var Component = (0, _Spottable["default"])('div');
36
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
46
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
47
+ "data-testid": id,
37
48
  spotlightDisabled: true
38
49
  }));
39
- var expected = 'spottable';
40
- var actual = subject.find('div').prop('className');
41
- expect(actual).not.toEqual(expected);
50
+
51
+ var div = _react.screen.getByTestId(id);
52
+
53
+ var expectedClass = 'spottable';
54
+ expect(div).not.toHaveClass(expectedClass);
42
55
  });
43
56
  test('should emit {onSpotlightDisappear} when unmounted while focused', function () {
44
57
  var spy = jest.fn();
45
58
  var Component = (0, _Spottable["default"])('div');
46
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
59
+
60
+ var _render = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
61
+ "data-testid": id,
47
62
  onSpotlightDisappear: spy
48
- }));
49
- subject.simulate('focus');
50
- subject.unmount();
63
+ })),
64
+ unmount = _render.unmount;
65
+
66
+ var div = _react.screen.getByTestId(id);
67
+
68
+ div.focus();
69
+ unmount();
51
70
  var expected = 1;
52
- var actual = spy.mock.calls.length;
53
- expect(actual).toEqual(expected);
71
+ expect(spy).toHaveBeenCalledTimes(expected);
72
+ expect(spy).toBeCalledWith({
73
+ type: 'onSpotlightDisappear'
74
+ });
54
75
  });
55
76
  describe('shouldComponentUpdate', function () {
56
77
  test('should re-render when a non-Spottable prop changes', function () {
@@ -58,39 +79,47 @@ describe('Spottable', function () {
58
79
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
59
80
  });
60
81
  var Component = (0, _Spottable["default"])(spy);
61
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
62
- subject.setProps({
63
- 'data-id': '123'
64
- });
82
+
83
+ var _render2 = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {})),
84
+ rerender = _render2.rerender;
85
+
86
+ rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
87
+ "data-id": "123"
88
+ }));
65
89
  var expected = 3;
66
- var actual = spy.mock.calls.length;
67
- expect(actual).toEqual(expected);
90
+ expect(spy).toHaveBeenCalledTimes(expected);
68
91
  });
69
92
  test('should re-render when {selectionKeys} changes', function () {
70
93
  var spy = jest.fn(function (props) {
71
94
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
72
95
  });
73
96
  var Component = (0, _Spottable["default"])(spy);
74
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
97
+
98
+ var _render3 = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
75
99
  selectionKeys: [1, 2, 3]
76
- }));
77
- subject.setProps({
100
+ })),
101
+ rerender = _render3.rerender;
102
+
103
+ rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
78
104
  selectionKeys: [2, 1, 3]
79
- });
105
+ }));
80
106
  var expected = 3;
81
- var actual = spy.mock.calls.length;
82
- expect(actual).toEqual(expected);
107
+ expect(spy).toHaveBeenCalledTimes(expected);
83
108
  });
84
109
  test('should not re-render when focused', function () {
85
110
  var spy = jest.fn(function (props) {
86
111
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
87
112
  });
88
113
  var Component = (0, _Spottable["default"])(spy);
89
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
90
- subject.simulate('focus');
114
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
115
+ "data-testid": id
116
+ }));
117
+
118
+ var div = _react.screen.getByTestId(id);
119
+
120
+ div.focus();
91
121
  var expected = 2;
92
- var actual = spy.mock.calls.length;
93
- expect(actual).toEqual(expected);
122
+ expect(spy).toHaveBeenCalledTimes(expected);
94
123
  });
95
124
  });
96
125
  });
@@ -4,11 +4,13 @@ var _handle = _interopRequireWildcard(require("@enact/core/handle"));
4
4
 
5
5
  var _useHandlers = _interopRequireDefault(require("@enact/core/useHandlers"));
6
6
 
7
- var _classnames = _interopRequireDefault(require("classnames"));
7
+ require("@testing-library/jest-dom");
8
+
9
+ var _react = require("@testing-library/react");
8
10
 
9
- var _enzyme = require("enzyme");
11
+ var _classnames = _interopRequireDefault(require("classnames"));
10
12
 
11
- var _react = require("react");
13
+ var _react2 = require("react");
12
14
 
13
15
  var _reactDom = _interopRequireDefault(require("react-dom"));
14
16
 
@@ -57,7 +59,8 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
57
59
  var forwardMouseUp = (0, _handle.forward)('onMouseUp'),
58
60
  forwardMouseDown = (0, _handle.forward)('onMouseDown'),
59
61
  forwardKeyDown = (0, _handle.forward)('onKeyDown'),
60
- forwardKeyUp = (0, _handle.forward)('onKeyUp');
62
+ forwardKeyUp = (0, _handle.forward)('onKeyUp'),
63
+ id = 'test-useSpot';
61
64
 
62
65
  var makeKeyEvent = function makeKeyEvent(keyCode) {
63
66
  return {
@@ -158,7 +161,7 @@ describe('useSpottable', function () {
158
161
  }]);
159
162
 
160
163
  return SpottableComponent;
161
- }(_react.Component);
164
+ }(_react2.Component);
162
165
 
163
166
  beforeEach(function () {
164
167
  // Spotlight.getCurrent() did not work in unit tests. It always returns `undefined`.
@@ -172,92 +175,127 @@ describe('useSpottable', function () {
172
175
  _spotlight["default"].getCurrent = getCurrent;
173
176
  });
174
177
  test('should add the spottable class', function () {
175
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {}));
178
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
179
+ "data-testid": id
180
+ }));
181
+
182
+ var div = _react.screen.getByTestId(id);
183
+
176
184
  var expected = 'spottable';
177
- var actual = subject.find('div').prop('className');
178
- expect(actual).toEqual(expected);
185
+ expect(div).toHaveClass(expected);
179
186
  });
180
187
  test('should add the spottable class to a {disabled} component', function () {
181
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
188
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
189
+ "data-testid": id,
182
190
  disabled: true
183
191
  }));
192
+
193
+ var div = _react.screen.getByTestId(id);
194
+
184
195
  var expected = 'spottable';
185
- var actual = subject.find('div').prop('className');
186
- expect(actual).toEqual(expected);
196
+ expect(div).toHaveClass(expected);
187
197
  });
188
198
  test('should not add the spottable class to a {spotlightDisabled} component', function () {
189
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
199
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
200
+ "data-testid": id,
190
201
  spotlightDisabled: true
191
202
  }));
203
+
204
+ var div = _react.screen.getByTestId(id);
205
+
192
206
  var expected = 'spottable';
193
- var actual = subject.find('div').prop('className');
194
- expect(actual).not.toEqual(expected);
207
+ expect(div).not.toHaveClass(expected);
195
208
  });
196
209
  describe('should emit event properly', function () {
197
210
  test('should emit {onSpotlightUp} when the the {keydown} is emitted with 38 keycode', function () {
198
211
  var spy = jest.fn();
199
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
212
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
213
+ "data-testid": id,
200
214
  onSpotlightUp: spy
201
215
  }));
202
- subject.simulate('keydown', makeKeyEvent(38));
216
+
217
+ var div = _react.screen.getByTestId(id);
218
+
219
+ _react.fireEvent.keyDown(div, makeKeyEvent(38));
220
+
203
221
  var expected = 1;
204
- var actual = spy.mock.calls.length;
205
- expect(actual).toEqual(expected);
222
+ expect(spy).toHaveBeenCalledTimes(expected);
206
223
  });
207
224
  test('should emit {onSpotlightDown} when the the {keydown} is emitted with 40 keycode', function () {
208
225
  var spy = jest.fn();
209
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
226
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
227
+ "data-testid": id,
210
228
  onSpotlightDown: spy
211
229
  }));
212
- subject.simulate('keydown', makeKeyEvent(40));
230
+
231
+ var div = _react.screen.getByTestId(id);
232
+
233
+ _react.fireEvent.keyDown(div, makeKeyEvent(40));
234
+
213
235
  var expected = 1;
214
- var actual = spy.mock.calls.length;
215
- expect(actual).toEqual(expected);
236
+ expect(spy).toHaveBeenCalledTimes(expected);
216
237
  });
217
238
  test('should emit {onSpotlightLeft} when the the {keydown} is emitted with 37 keycode', function () {
218
239
  var spy = jest.fn();
219
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
240
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
241
+ "data-testid": id,
220
242
  onSpotlightLeft: spy
221
243
  }));
222
- subject.simulate('keydown', makeKeyEvent(37));
244
+
245
+ var div = _react.screen.getByTestId(id);
246
+
247
+ _react.fireEvent.keyDown(div, makeKeyEvent(37));
248
+
223
249
  var expected = 1;
224
- var actual = spy.mock.calls.length;
225
- expect(actual).toEqual(expected);
250
+ expect(spy).toHaveBeenCalledTimes(expected);
226
251
  });
227
252
  test('should emit {onSpotlightRight} when the the {keydown} is emitted with 39 keycode', function () {
228
253
  var spy = jest.fn();
229
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
254
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
255
+ "data-testid": id,
230
256
  onSpotlightRight: spy
231
257
  }));
232
- subject.simulate('keydown', makeKeyEvent(39));
258
+
259
+ var div = _react.screen.getByTestId(id);
260
+
261
+ _react.fireEvent.keyDown(div, makeKeyEvent(39));
262
+
233
263
  var expected = 1;
234
- var actual = spy.mock.calls.length;
235
- expect(actual).toEqual(expected);
264
+ expect(spy).toHaveBeenCalledTimes(expected);
236
265
  });
237
266
  test('should emulate {onMouseDown} when REMOTE_OK_KEY key is pressed', function () {
238
267
  var spy = jest.fn();
239
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
268
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
269
+ "data-testid": id,
240
270
  emulateMouse: true,
241
271
  onMouseDown: spy,
242
272
  selectionKeys: [13]
243
273
  }));
244
- subject.simulate('keydown', makeKeyEvent(REMOTE_OK_KEY));
274
+
275
+ var div = _react.screen.getByTestId(id);
276
+
277
+ _react.fireEvent.keyDown(div, makeKeyEvent(REMOTE_OK_KEY));
278
+
245
279
  var expected = 1;
246
- var actual = spy.mock.calls.length;
247
- expect(actual).toEqual(expected);
280
+ expect(spy).toHaveBeenCalledTimes(expected);
248
281
  });
249
282
  test('should emulate {onMouseUp} when {REMOTE_OK_KEY} key is pressed and released', function () {
250
283
  var spy = jest.fn();
251
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
284
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
285
+ "data-testid": id,
252
286
  emulateMouse: true,
253
287
  onMouseUp: spy,
254
288
  selectionKeys: [13]
255
289
  }));
256
- subject.simulate('keydown', makeKeyEvent(REMOTE_OK_KEY));
257
- subject.simulate('keyup', makeKeyEvent(REMOTE_OK_KEY));
290
+
291
+ var div = _react.screen.getByTestId(id);
292
+
293
+ _react.fireEvent.keyDown(div, makeKeyEvent(REMOTE_OK_KEY));
294
+
295
+ _react.fireEvent.keyUp(div, makeKeyEvent(REMOTE_OK_KEY));
296
+
258
297
  var expected = 1;
259
- var actual = spy.mock.calls.length;
260
- expect(actual).toEqual(expected);
298
+ expect(spy).toHaveBeenCalledTimes(expected);
261
299
  });
262
300
  test('should not emulate {onMouseUp} if the default behavior is prevented even though {REMOTE_OK_KEY} key is pressed', function () {
263
301
  var spy = jest.fn();
@@ -266,17 +304,21 @@ describe('useSpottable', function () {
266
304
  ev.preventDefault();
267
305
  }
268
306
 
269
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
307
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
308
+ "data-testid": id,
270
309
  emulateMouse: true,
271
310
  onKeyUp: onKeyUp,
272
311
  onMouseUp: spy,
273
312
  selectionKeys: [13]
274
313
  }));
275
- subject.simulate('keydown', makeKeyEvent(REMOTE_OK_KEY));
276
- subject.simulate('keyup', makeKeyEvent(REMOTE_OK_KEY));
277
- var expected = 0;
278
- var actual = spy.mock.calls.length;
279
- expect(actual).toEqual(expected);
314
+
315
+ var div = _react.screen.getByTestId(id);
316
+
317
+ _react.fireEvent.keyDown(div, makeKeyEvent(REMOTE_OK_KEY));
318
+
319
+ _react.fireEvent.keyUp(div, makeKeyEvent(REMOTE_OK_KEY));
320
+
321
+ expect(spy).not.toHaveBeenCalled();
280
322
  });
281
323
  });
282
324
  describe('shouldComponentUpdate', function () {
@@ -284,42 +326,55 @@ describe('useSpottable', function () {
284
326
  var spy = jest.fn(function (props) {
285
327
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
286
328
  });
287
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
288
- component: spy
329
+
330
+ var _render = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
331
+ component: spy,
332
+ "data-testid": id
333
+ })),
334
+ rerender = _render.rerender;
335
+
336
+ rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
337
+ component: spy,
338
+ "data-id": "123",
339
+ "data-testid": id
289
340
  }));
290
- subject.setProps({
291
- 'data-id': '123'
292
- });
293
341
  var expected = 2;
294
- var actual = spy.mock.calls.length;
295
- expect(actual).toEqual(expected);
342
+ expect(spy).toHaveBeenCalledTimes(expected);
296
343
  });
297
344
  test('should re-render when {selectionKeys} changes', function () {
298
345
  var spy = jest.fn(function (props) {
299
346
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
300
347
  });
301
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
348
+
349
+ var _render2 = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
302
350
  component: spy,
351
+ "data-testid": id,
303
352
  selectionKeys: [1, 2, 3]
304
- }));
305
- subject.setProps({
353
+ })),
354
+ rerender = _render2.rerender;
355
+
356
+ rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
357
+ component: spy,
358
+ "data-testid": id,
306
359
  selectionKeys: [2, 1, 3]
307
- });
360
+ }));
308
361
  var expected = 2;
309
- var actual = spy.mock.calls.length;
310
- expect(actual).toEqual(expected);
362
+ expect(spy).toHaveBeenCalledTimes(expected);
311
363
  });
312
364
  test('should not re-render when focused', function () {
313
365
  var spy = jest.fn(function (props) {
314
366
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
315
367
  });
316
- var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
317
- component: spy
368
+ (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
369
+ component: spy,
370
+ "data-testid": id
318
371
  }));
319
- subject.simulate('focus');
372
+
373
+ var div = _react.screen.getByTestId(id);
374
+
375
+ div.focus();
320
376
  var expected = 1;
321
- var actual = spy.mock.calls.length;
322
- expect(actual).toEqual(expected);
377
+ expect(spy).toHaveBeenCalledTimes(expected);
323
378
  });
324
379
  });
325
380
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enact/spotlight",
3
- "version": "4.1.1",
3
+ "version": "4.1.4",
4
4
  "description": "A focus management library",
5
5
  "main": "src/spotlight.js",
6
6
  "scripts": {
@@ -18,12 +18,12 @@
18
18
  }
19
19
  },
20
20
  "dependencies": {
21
- "@enact/core": "^4.1.1",
22
- "classnames": "^2.2.6",
23
- "prop-types": "^15.7.2",
24
- "ramda": "^0.24.1",
25
- "react": "^17.0.1",
26
- "react-dom": "^17.0.1",
27
- "warning": "^3.0.0"
21
+ "@enact/core": "^4.1.4",
22
+ "classnames": "^2.3.1",
23
+ "prop-types": "^15.8.0",
24
+ "ramda": "^0.27.1",
25
+ "react": "^17.0.2",
26
+ "react-dom": "^17.0.2",
27
+ "warning": "^4.0.3"
28
28
  }
29
29
  }
package/src/utils.js CHANGED
@@ -67,17 +67,18 @@ var testIntersection = function testIntersection(type, containerRect, elementRec
67
67
  r = elementRect.right,
68
68
  t = elementRect.top,
69
69
  b = elementRect.bottom;
70
- var right = r >= L && r <= R;
71
- var left = l >= L && l <= R;
72
- var top = t >= T && t <= B;
73
- var bottom = b >= T && b <= B;
74
70
 
75
71
  if (type === 'intersects') {
76
- var aroundV = t < T && b > B;
77
- var aroundH = l < L && r > R;
78
- return (top || bottom || aroundV) && (left || right || aroundH);
72
+ // Test intersection by eliminating the area of the element that is outside of the container
73
+ return !(b < T || t > B || r < L || l > R);
79
74
  } else if (type === 'contains') {
80
- return top && bottom && left && right;
75
+ var epsilon = 1; // Test whether all bounds are within the container
76
+
77
+ return r > L - epsilon && r < R + epsilon && // right
78
+ l > L - epsilon && l < R + epsilon && // left
79
+ t > T - epsilon && t < B + epsilon && // top
80
+ b > T - epsilon && b < B + epsilon // bottom
81
+ ;
81
82
  }
82
83
 
83
84
  return true;
package/styles/debug.less CHANGED
@@ -2,96 +2,94 @@
2
2
  // Spotlight Debug
3
3
  //
4
4
 
5
- :global {
6
- .debug.spotlight {
7
- @debug-color-up: hsla(0, 100%, 72%, 1);
8
- @debug-color-right: hsla(90, 100%, 72%, 1);
9
- @debug-color-down: hsla(180, 100%, 72%, 1);
10
- @debug-color-left: hsla(240, 100%, 72%, 1);
5
+ .debug.spotlight {
6
+ @debug-color-up: hsla(0, 100%, 72%, 1);
7
+ @debug-color-right: hsla(90, 100%, 72%, 1);
8
+ @debug-color-down: hsla(180, 100%, 72%, 1);
9
+ @debug-color-left: hsla(240, 100%, 72%, 1);
11
10
 
12
- .spottable-next-up,
13
- .spottable-next-right,
14
- .spottable-next-down,
15
- .spottable-next-left {
16
- // outline: 3px dotted transparent;
17
- // box-shadow: 0;
11
+ .spottable-next-up,
12
+ .spottable-next-right,
13
+ .spottable-next-down,
14
+ .spottable-next-left {
15
+ // outline: 3px dotted transparent;
16
+ // box-shadow: 0;
18
17
 
19
- &::after {
20
- content: '';
21
- position: absolute;
22
- top: 0;
23
- border-width: 0 1px 1px 0;
24
- border-style: solid;
25
- border-bottom-right-radius: 0.5ex;
26
- // font-family: "Moonstone Miso";
27
- font-size: 15px;
28
- line-height: 18px;
29
- padding: 0 1ex;
30
- left: 0;
18
+ &::after {
19
+ content: '';
20
+ position: absolute;
21
+ top: 0;
22
+ border-width: 0 1px 1px 0;
23
+ border-style: solid;
24
+ border-bottom-right-radius: 0.5ex;
25
+ // font-family: "Moonstone Miso";
26
+ font-size: 15px;
27
+ line-height: 18px;
28
+ padding: 0 1ex;
29
+ left: 0;
31
30
 
32
- border-width: 0 1px 1px 1px;
33
- border-bottom-right-radius: 0.5ex;
34
- border-bottom-left-radius: 0.5ex;
35
- left: 50%;
36
- transform: translateX(-50%);
37
- }
31
+ border-width: 0 1px 1px 1px;
32
+ border-bottom-right-radius: 0.5ex;
33
+ border-bottom-left-radius: 0.5ex;
34
+ left: 50%;
35
+ transform: translateX(-50%);
38
36
  }
37
+ }
39
38
 
40
- .spottable-next-up { box-shadow: 0 12px 9px -3px @debug-color-up, 0 0 1px 3px @debug-color-up; &::after { content: 'Spotlight next: up'; color: @debug-color-up; }}
41
- .spottable-next-right { box-shadow: -12px 0 9px -3px @debug-color-right, 0 0 1px 3px @debug-color-right; &::after { content: 'Spotlight next: right'; color: @debug-color-right; }}
42
- .spottable-next-down { box-shadow: 0 -12px 9px -3px @debug-color-down, 0 0 1px 3px @debug-color-down; &::after { content: 'Spotlight next: down'; color: @debug-color-down; }}
43
- .spottable-next-left { box-shadow: 12px 0 9px -3px @debug-color-left, 0 0 1px 3px @debug-color-left; &::after { content: 'Spotlight next: left'; color: @debug-color-left; }}
39
+ .spottable-next-up { box-shadow: 0 12px 9px -3px @debug-color-up, 0 0 1px 3px @debug-color-up; &::after { content: 'Spotlight next: up'; color: @debug-color-up; }}
40
+ .spottable-next-right { box-shadow: -12px 0 9px -3px @debug-color-right, 0 0 1px 3px @debug-color-right; &::after { content: 'Spotlight next: right'; color: @debug-color-right; }}
41
+ .spottable-next-down { box-shadow: 0 -12px 9px -3px @debug-color-down, 0 0 1px 3px @debug-color-down; &::after { content: 'Spotlight next: down'; color: @debug-color-down; }}
42
+ .spottable-next-left { box-shadow: 12px 0 9px -3px @debug-color-left, 0 0 1px 3px @debug-color-left; &::after { content: 'Spotlight next: left'; color: @debug-color-left; }}
44
43
 
45
44
 
46
- // Below are some alternative visuals still being worked out.
45
+ // Below are some alternative visuals still being worked out.
47
46
 
48
- //
49
- // Crisp shadow-arrows
50
- //
51
- // .spottable-next-up { box-shadow:
52
- // 0 3px 1px -1px @debug-color-up,
53
- // 0 12px 1px -3px @debug-color-up,
54
- // 0 21px 1px -9px @debug-color-up,
55
- // 0 30px 1px -15px @debug-color-up,
56
- // 0 39px 1px -21px @debug-color-up,
57
- // 0 0 1px 3px @debug-color-up;
58
- // &::after { content: 'Spotlight next: up'; color: @debug-color-up; }
59
- // }
60
- // .spottable-next-right { box-shadow:
61
- // -3px 0 1px -1px @debug-color-right,
62
- // -12px 0 1px -3px @debug-color-right,
63
- // -21px 0 1px -9px @debug-color-right,
64
- // -30px 0 1px -15px @debug-color-right,
65
- // -39px 0 1px -21px @debug-color-right,
66
- // 0 0 1px 3px @debug-color-right;
67
- // &::after { content: 'Spotlight next: right'; color: @debug-color-right; }
68
- // }
69
- // .spottable-next-down { box-shadow:
70
- // 0 -3px 1px -1px @debug-color-down,
71
- // 0 -12px 1px -3px @debug-color-down,
72
- // 0 -21px 1px -9px @debug-color-down,
73
- // 0 -30px 1px -15px @debug-color-down,
74
- // 0 -39px 1px -21px @debug-color-down,
75
- // 0 0 1px 3px @debug-color-down;
76
- // &::after { content: 'Spotlight next: down'; color: @debug-color-down; }
77
- // }
78
- // .spottable-next-left { box-shadow:
79
- // 3px 0 1px -1px @debug-color-left,
80
- // 12px 0 1px -3px @debug-color-left,
81
- // 21px 0 1px -9px @debug-color-left,
82
- // 30px 0 1px -15px @debug-color-left,
83
- // 39px 0 1px -21px @debug-color-left,
84
- // 0 0 1px 3px @debug-color-left;
85
- // &::after { content: 'Spotlight next: left'; color: @debug-color-left; }
86
- // }
47
+ //
48
+ // Crisp shadow-arrows
49
+ //
50
+ // .spottable-next-up { box-shadow:
51
+ // 0 3px 1px -1px @debug-color-up,
52
+ // 0 12px 1px -3px @debug-color-up,
53
+ // 0 21px 1px -9px @debug-color-up,
54
+ // 0 30px 1px -15px @debug-color-up,
55
+ // 0 39px 1px -21px @debug-color-up,
56
+ // 0 0 1px 3px @debug-color-up;
57
+ // &::after { content: 'Spotlight next: up'; color: @debug-color-up; }
58
+ // }
59
+ // .spottable-next-right { box-shadow:
60
+ // -3px 0 1px -1px @debug-color-right,
61
+ // -12px 0 1px -3px @debug-color-right,
62
+ // -21px 0 1px -9px @debug-color-right,
63
+ // -30px 0 1px -15px @debug-color-right,
64
+ // -39px 0 1px -21px @debug-color-right,
65
+ // 0 0 1px 3px @debug-color-right;
66
+ // &::after { content: 'Spotlight next: right'; color: @debug-color-right; }
67
+ // }
68
+ // .spottable-next-down { box-shadow:
69
+ // 0 -3px 1px -1px @debug-color-down,
70
+ // 0 -12px 1px -3px @debug-color-down,
71
+ // 0 -21px 1px -9px @debug-color-down,
72
+ // 0 -30px 1px -15px @debug-color-down,
73
+ // 0 -39px 1px -21px @debug-color-down,
74
+ // 0 0 1px 3px @debug-color-down;
75
+ // &::after { content: 'Spotlight next: down'; color: @debug-color-down; }
76
+ // }
77
+ // .spottable-next-left { box-shadow:
78
+ // 3px 0 1px -1px @debug-color-left,
79
+ // 12px 0 1px -3px @debug-color-left,
80
+ // 21px 0 1px -9px @debug-color-left,
81
+ // 30px 0 1px -15px @debug-color-left,
82
+ // 39px 0 1px -21px @debug-color-left,
83
+ // 0 0 1px 3px @debug-color-left;
84
+ // &::after { content: 'Spotlight next: left'; color: @debug-color-left; }
85
+ // }
87
86
 
88
- //
89
- // Plain Boxy Outlines
90
- //
91
- // .spottable-next-up { outline-color: @debug-color-up; &::after { content: 'Spotlight next: up'; color: @debug-color-up; }}
92
- // .spottable-next-right { outline-color: @debug-color-right; &::after { content: 'Spotlight next: right'; color: @debug-color-right; }}
93
- // .spottable-next-down { outline-color: @debug-color-down; &::after { content: 'Spotlight next: down'; color: @debug-color-down; }}
94
- // .spottable-next-left { outline-color: @debug-color-left; &::after { content: 'Spotlight next: left'; color: @debug-color-left; }}
95
- }
87
+ //
88
+ // Plain Boxy Outlines
89
+ //
90
+ // .spottable-next-up { outline-color: @debug-color-up; &::after { content: 'Spotlight next: up'; color: @debug-color-up; }}
91
+ // .spottable-next-right { outline-color: @debug-color-right; &::after { content: 'Spotlight next: right'; color: @debug-color-right; }}
92
+ // .spottable-next-down { outline-color: @debug-color-down; &::after { content: 'Spotlight next: down'; color: @debug-color-down; }}
93
+ // .spottable-next-left { outline-color: @debug-color-left; &::after { content: 'Spotlight next: left'; color: @debug-color-left; }}
96
94
  }
97
95