@enact/spotlight 4.1.0 → 4.1.3
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/Accelerator/Accelerator.d.ts +2 -5
- package/CHANGELOG.md +17 -0
- package/Pause/Pause.d.ts +4 -6
- package/README.md +1 -1
- package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +42 -36
- package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +101 -49
- package/SpotlightRootDecorator/SpotlightRootDecorator.js +9 -16
- package/Spottable/SpottableCore.js +2 -2
- package/Spottable/tests/Spottable-specs.js +64 -35
- package/Spottable/tests/useSpot-specs.js +118 -63
- package/package.json +8 -8
- package/src/utils.js +9 -8
- package/styles/debug.less +80 -82
|
@@ -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.3] - 2022-03-07
|
|
6
|
+
|
|
7
|
+
- Updated to use `forwardCustom` and add `type` when forwarding custom events
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- `spotlight` to correctly control focus when boundaries of an element are not integers
|
|
12
|
+
- Styles for `debug spotlight` option in samplers to work properly
|
|
13
|
+
|
|
14
|
+
## [4.1.2] - 2021-12-22
|
|
15
|
+
|
|
16
|
+
No significant changes.
|
|
17
|
+
|
|
18
|
+
## [4.1.1] - 2021-11-30
|
|
19
|
+
|
|
20
|
+
No significant changes.
|
|
21
|
+
|
|
5
22
|
## [4.1.0] - 2021-11-04
|
|
6
23
|
|
|
7
24
|
### Fixed
|
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
|
-
|
|
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-
|
|
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
|
-
|
|
3
|
+
require("@testing-library/jest-dom");
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _react = require("@testing-library/react");
|
|
6
6
|
|
|
7
|
-
var
|
|
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
|
-
|
|
50
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
51
|
+
"data-testid": testId,
|
|
46
52
|
spotlightId: "test-container"
|
|
47
53
|
}));
|
|
48
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
74
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
106
|
-
|
|
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,
|
|
134
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
123
135
|
onFocusCapture: spy
|
|
124
136
|
}));
|
|
125
137
|
focus({});
|
|
126
138
|
var expected = 1;
|
|
127
|
-
|
|
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,
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
3
|
+
require("@testing-library/jest-dom");
|
|
4
4
|
|
|
5
|
-
var
|
|
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
|
|
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
|
|
61
|
-
|
|
62
|
-
var
|
|
63
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
114
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
115
|
+
"data-testid": testId,
|
|
88
116
|
spotlightId: id
|
|
89
117
|
}));
|
|
90
|
-
|
|
91
|
-
var
|
|
92
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
135
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
136
|
+
"data-testid": testId,
|
|
101
137
|
spotlightDisabled: true
|
|
102
138
|
}));
|
|
103
|
-
|
|
104
|
-
var
|
|
105
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
157
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
158
|
+
"data-testid": testId,
|
|
114
159
|
spotlightMuted: true
|
|
115
160
|
}));
|
|
116
|
-
|
|
117
|
-
var
|
|
118
|
-
|
|
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,
|
|
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,
|
|
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
|
-
|
|
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') {
|
|
@@ -206,13 +199,14 @@ var SpotlightRootDecorator = (0, _hoc["default"])(defaultConfig, function (confi
|
|
|
206
199
|
|
|
207
200
|
_spotlight["default"].set(_container.rootContainerId, {
|
|
208
201
|
overflow: true
|
|
209
|
-
});
|
|
210
|
-
} // Sometimes the focusin event is fired before componentDidMount.
|
|
202
|
+
}); // Sometimes the focusin event is fired before componentDidMount.
|
|
211
203
|
|
|
212
204
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
205
|
+
document.addEventListener('focusin', _this.handleFocusInBeforeMount, {
|
|
206
|
+
capture: true
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
216
210
|
return _this;
|
|
217
211
|
}
|
|
218
212
|
|
|
@@ -237,12 +231,11 @@ var SpotlightRootDecorator = (0, _hoc["default"])(defaultConfig, function (confi
|
|
|
237
231
|
document.addEventListener('pointerover', this.handlePointerOver, {
|
|
238
232
|
capture: true
|
|
239
233
|
});
|
|
234
|
+
document.removeEventListener('focusin', this.handleFocusInBeforeMount, {
|
|
235
|
+
capture: true
|
|
236
|
+
});
|
|
240
237
|
}
|
|
241
238
|
|
|
242
|
-
document.removeEventListener('focusin', this.handleFocusInBeforeMount, {
|
|
243
|
-
capture: true
|
|
244
|
-
});
|
|
245
|
-
|
|
246
239
|
if (this.hasFocusedIn) {
|
|
247
240
|
this.hasFocusedIn = false;
|
|
248
241
|
this.handleFocusIn();
|
|
@@ -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.
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
34
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
35
|
+
"data-testid": id,
|
|
28
36
|
disabled: true
|
|
29
37
|
}));
|
|
30
|
-
|
|
31
|
-
var
|
|
32
|
-
|
|
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
|
-
|
|
46
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
47
|
+
"data-testid": id,
|
|
37
48
|
spotlightDisabled: true
|
|
38
49
|
}));
|
|
39
|
-
|
|
40
|
-
var
|
|
41
|
-
|
|
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
|
-
|
|
59
|
+
|
|
60
|
+
var _render = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
61
|
+
"data-testid": id,
|
|
47
62
|
onSpotlightDisappear: spy
|
|
48
|
-
}))
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
53
|
-
expect(
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
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
|
-
|
|
97
|
+
|
|
98
|
+
var _render3 = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
75
99
|
selectionKeys: [1, 2, 3]
|
|
76
|
-
}))
|
|
77
|
-
|
|
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
|
-
|
|
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
|
-
|
|
90
|
-
|
|
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
|
-
|
|
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
|
-
|
|
7
|
+
require("@testing-library/jest-dom");
|
|
8
|
+
|
|
9
|
+
var _react = require("@testing-library/react");
|
|
8
10
|
|
|
9
|
-
var
|
|
11
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
12
|
|
|
11
|
-
var
|
|
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
|
-
}(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
212
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
213
|
+
"data-testid": id,
|
|
200
214
|
onSpotlightUp: spy
|
|
201
215
|
}));
|
|
202
|
-
|
|
216
|
+
|
|
217
|
+
var div = _react.screen.getByTestId(id);
|
|
218
|
+
|
|
219
|
+
_react.fireEvent.keyDown(div, makeKeyEvent(38));
|
|
220
|
+
|
|
203
221
|
var expected = 1;
|
|
204
|
-
|
|
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
|
-
|
|
226
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
227
|
+
"data-testid": id,
|
|
210
228
|
onSpotlightDown: spy
|
|
211
229
|
}));
|
|
212
|
-
|
|
230
|
+
|
|
231
|
+
var div = _react.screen.getByTestId(id);
|
|
232
|
+
|
|
233
|
+
_react.fireEvent.keyDown(div, makeKeyEvent(40));
|
|
234
|
+
|
|
213
235
|
var expected = 1;
|
|
214
|
-
|
|
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
|
-
|
|
240
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
241
|
+
"data-testid": id,
|
|
220
242
|
onSpotlightLeft: spy
|
|
221
243
|
}));
|
|
222
|
-
|
|
244
|
+
|
|
245
|
+
var div = _react.screen.getByTestId(id);
|
|
246
|
+
|
|
247
|
+
_react.fireEvent.keyDown(div, makeKeyEvent(37));
|
|
248
|
+
|
|
223
249
|
var expected = 1;
|
|
224
|
-
|
|
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
|
-
|
|
254
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
255
|
+
"data-testid": id,
|
|
230
256
|
onSpotlightRight: spy
|
|
231
257
|
}));
|
|
232
|
-
|
|
258
|
+
|
|
259
|
+
var div = _react.screen.getByTestId(id);
|
|
260
|
+
|
|
261
|
+
_react.fireEvent.keyDown(div, makeKeyEvent(39));
|
|
262
|
+
|
|
233
263
|
var expected = 1;
|
|
234
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
257
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
-
|
|
288
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
317
|
-
component: spy
|
|
368
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
369
|
+
component: spy,
|
|
370
|
+
"data-testid": id
|
|
318
371
|
}));
|
|
319
|
-
|
|
372
|
+
|
|
373
|
+
var div = _react.screen.getByTestId(id);
|
|
374
|
+
|
|
375
|
+
div.focus();
|
|
320
376
|
var expected = 1;
|
|
321
|
-
|
|
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.
|
|
3
|
+
"version": "4.1.3",
|
|
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.
|
|
22
|
-
"classnames": "^2.
|
|
23
|
-
"prop-types": "^15.
|
|
24
|
-
"ramda": "^0.
|
|
25
|
-
"react": "^17.0.
|
|
26
|
-
"react-dom": "^17.0.
|
|
27
|
-
"warning": "^
|
|
21
|
+
"@enact/core": "^4.1.3",
|
|
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
|
-
|
|
77
|
-
|
|
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
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
45
|
+
// Below are some alternative visuals still being worked out.
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
|