@enact/spotlight 5.0.0-alpha.3 → 5.0.0-alpha.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.
- package/Accelerator/tests/Accelerrator-specs.js +2 -2
- package/CHANGELOG.md +10 -0
- package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +7 -7
- package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +14 -14
- package/SpotlightRootDecorator/tests/SpotlightRootDecorator-specs.js +3 -3
- package/Spottable/tests/Spottable-specs.js +9 -9
- package/Spottable/tests/useSpot-specs.js +15 -15
- package/package.json +4 -4
- package/src/container.js +6 -6
- package/src/spotlight.d.ts +1 -1
- package/src/spotlight.js +15 -12
- package/src/tests/spotlight-specs.js +9 -0
|
@@ -11,7 +11,7 @@ describe('Accelerator', function () {
|
|
|
11
11
|
var handleKeyDown = function handleKeyDown(ev) {
|
|
12
12
|
SpotlightAccelerator.processKey(ev, acceleratorCallback);
|
|
13
13
|
};
|
|
14
|
-
(0, _react.render)(
|
|
14
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
15
15
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
16
16
|
onKeyDown: handleKeyDown,
|
|
17
17
|
children: "button"
|
|
@@ -32,7 +32,7 @@ describe('Accelerator', function () {
|
|
|
32
32
|
var handleKeyDown = function handleKeyDown(ev) {
|
|
33
33
|
SpotlightAccelerator.processKey(ev, acceleratorCallback);
|
|
34
34
|
};
|
|
35
|
-
(0, _react.render)(
|
|
35
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
36
36
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
37
37
|
onKeyDown: handleKeyDown,
|
|
38
38
|
children: "button"
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
The following is a curated list of changes in the Enact spotlight module, newest changes on the top.
|
|
4
4
|
|
|
5
|
+
## [5.0.0-alpha.4] - 2024-01-21
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `spotlight` an optional `options.preventScroll` parameter to `focus` function to prevent scrolling by focus
|
|
10
|
+
|
|
11
|
+
## [4.9.5] - 2024-12-11
|
|
12
|
+
|
|
13
|
+
No significant changes.
|
|
14
|
+
|
|
5
15
|
## [5.0.0-alpha.3] - 2024-12-02
|
|
6
16
|
|
|
7
17
|
No significant changes.
|
|
@@ -37,7 +37,7 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
37
37
|
test('should set itself as the active container on mouse enter', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
38
38
|
var Component = (0, _SpotlightContainerDecorator["default"])(Div);
|
|
39
39
|
var user = _userEvent["default"].setup();
|
|
40
|
-
(0, _react.render)(
|
|
40
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
41
41
|
"data-testid": testId,
|
|
42
42
|
spotlightId: "test-container"
|
|
43
43
|
}));
|
|
@@ -54,7 +54,7 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
54
54
|
var Component = (0, _SpotlightContainerDecorator["default"])(Div);
|
|
55
55
|
var node = document.createElement('div');
|
|
56
56
|
var user = _userEvent["default"].setup();
|
|
57
|
-
(0, _react.render)(
|
|
57
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
58
58
|
spotlightId: "outer-container",
|
|
59
59
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
60
60
|
"data-testid": testId,
|
|
@@ -85,7 +85,7 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
85
85
|
var Component = (0, _SpotlightContainerDecorator["default"])(Div);
|
|
86
86
|
var node = document.createElement('div');
|
|
87
87
|
var user = _userEvent["default"].setup();
|
|
88
|
-
(0, _react.render)(
|
|
88
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsxs)(Component, {
|
|
89
89
|
spotlightId: "outer-container",
|
|
90
90
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
91
91
|
"data-testid": testId,
|
|
@@ -122,7 +122,7 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
122
122
|
focus = onFocusCapture;
|
|
123
123
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
|
|
124
124
|
});
|
|
125
|
-
(0, _react.render)(
|
|
125
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
126
126
|
onFocusCapture: spy
|
|
127
127
|
}));
|
|
128
128
|
focus({});
|
|
@@ -137,7 +137,7 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
137
137
|
focus = onFocusCapture;
|
|
138
138
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
|
|
139
139
|
});
|
|
140
|
-
(0, _react.render)(
|
|
140
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
141
141
|
onFocusCapture: spy,
|
|
142
142
|
spotlightDisabled: true
|
|
143
143
|
}));
|
|
@@ -163,7 +163,7 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
163
163
|
_blur = onBlurCapture;
|
|
164
164
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
|
|
165
165
|
});
|
|
166
|
-
(0, _react.render)(
|
|
166
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
167
167
|
onBlurCapture: spy,
|
|
168
168
|
spotlightDisabled: true
|
|
169
169
|
}));
|
|
@@ -193,7 +193,7 @@ describe('SpotlightContainerDecorator', function () {
|
|
|
193
193
|
focus = onFocusCapture;
|
|
194
194
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
|
|
195
195
|
});
|
|
196
|
-
(0, _react.render)(
|
|
196
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
197
197
|
onBlurCapture: spy,
|
|
198
198
|
spotlightDisabled: true
|
|
199
199
|
}));
|
|
@@ -49,7 +49,7 @@ describe('useSpotlightContainer', function () {
|
|
|
49
49
|
var spotlightContainer = (0, _useSpotlightContainer["default"])();
|
|
50
50
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, props), spotlightContainer.attributes));
|
|
51
51
|
};
|
|
52
|
-
(0, _react.render)(
|
|
52
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {
|
|
53
53
|
"data-testid": testId
|
|
54
54
|
}));
|
|
55
55
|
var component = _react.screen.getByTestId(testId);
|
|
@@ -59,7 +59,7 @@ describe('useSpotlightContainer', function () {
|
|
|
59
59
|
});
|
|
60
60
|
describe('attributes', function () {
|
|
61
61
|
test('should set `data-spotlight-container` attribute', function () {
|
|
62
|
-
(0, _react.render)(
|
|
62
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
63
63
|
"data-testid": testId
|
|
64
64
|
}));
|
|
65
65
|
var component = _react.screen.getByTestId(testId);
|
|
@@ -68,7 +68,7 @@ describe('useSpotlightContainer', function () {
|
|
|
68
68
|
expect(component).toHaveAttribute(expectedAttribute, expectedValue);
|
|
69
69
|
});
|
|
70
70
|
test('should generate a `data-spotlight-id` attribute when `id` is unset', function () {
|
|
71
|
-
(0, _react.render)(
|
|
71
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
72
72
|
"data-testid": testId
|
|
73
73
|
}));
|
|
74
74
|
var component = _react.screen.getByTestId(testId);
|
|
@@ -77,12 +77,12 @@ describe('useSpotlightContainer', function () {
|
|
|
77
77
|
expect(component).toHaveAttribute(expectedAttribute, expectedValue);
|
|
78
78
|
});
|
|
79
79
|
test('should reuse the same generated `data-spotlight-id` attribute on re-render', function () {
|
|
80
|
-
var _render = (0, _react.render)(
|
|
80
|
+
var _render = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
81
81
|
"data-testid": testId
|
|
82
82
|
})),
|
|
83
83
|
rerender = _render.rerender;
|
|
84
84
|
var expected = _react.screen.getByTestId(testId).getAttribute('data-spotlight-id');
|
|
85
|
-
rerender(
|
|
85
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
86
86
|
"data-testid": testId
|
|
87
87
|
}));
|
|
88
88
|
var actual = _react.screen.getByTestId(testId).getAttribute('data-spotlight-id');
|
|
@@ -90,7 +90,7 @@ describe('useSpotlightContainer', function () {
|
|
|
90
90
|
});
|
|
91
91
|
test('should set a `data-spotlight-id` attribute when `id` is set', function () {
|
|
92
92
|
var id = 'my-container';
|
|
93
|
-
(0, _react.render)(
|
|
93
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
94
94
|
"data-testid": testId,
|
|
95
95
|
spotlightId: id
|
|
96
96
|
}));
|
|
@@ -99,7 +99,7 @@ describe('useSpotlightContainer', function () {
|
|
|
99
99
|
expect(component).toHaveAttribute(expectedAttribute, id);
|
|
100
100
|
});
|
|
101
101
|
test('should set `data-spotlight-container-disabled` attribute to be falsey when `disabled` is unset', function () {
|
|
102
|
-
(0, _react.render)(
|
|
102
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
103
103
|
"data-testid": testId
|
|
104
104
|
}));
|
|
105
105
|
var component = _react.screen.getByTestId(testId);
|
|
@@ -107,7 +107,7 @@ describe('useSpotlightContainer', function () {
|
|
|
107
107
|
expect(component).not.toHaveAttribute(expectedAttribute);
|
|
108
108
|
});
|
|
109
109
|
test('should set `data-spotlight-container-disabled` attribute when `disabled` is set', function () {
|
|
110
|
-
(0, _react.render)(
|
|
110
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
111
111
|
"data-testid": testId,
|
|
112
112
|
spotlightDisabled: true
|
|
113
113
|
}));
|
|
@@ -117,7 +117,7 @@ describe('useSpotlightContainer', function () {
|
|
|
117
117
|
expect(component).toHaveAttribute(expectedAttribute, expectedValue);
|
|
118
118
|
});
|
|
119
119
|
test('should set `data-spotlight-container-muted` attribute to be falsey when `muted` is unset', function () {
|
|
120
|
-
(0, _react.render)(
|
|
120
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
121
121
|
"data-testid": testId
|
|
122
122
|
}));
|
|
123
123
|
var component = _react.screen.getByTestId(testId);
|
|
@@ -125,7 +125,7 @@ describe('useSpotlightContainer', function () {
|
|
|
125
125
|
expect(component).not.toHaveAttribute(expectedAttribute);
|
|
126
126
|
});
|
|
127
127
|
test('should set `data-spotlight-container-muted` attribute when `muted` is set', function () {
|
|
128
|
-
(0, _react.render)(
|
|
128
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
129
129
|
"data-testid": testId,
|
|
130
130
|
spotlightMuted: true
|
|
131
131
|
}));
|
|
@@ -139,7 +139,7 @@ describe('useSpotlightContainer', function () {
|
|
|
139
139
|
test('should create a new container with the specified id', function () {
|
|
140
140
|
var id = 'my-container';
|
|
141
141
|
expect(containerExists(id)).toBeFalsy();
|
|
142
|
-
(0, _react.render)(
|
|
142
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
143
143
|
spotlightId: id
|
|
144
144
|
}));
|
|
145
145
|
var expected = true;
|
|
@@ -153,7 +153,7 @@ describe('useSpotlightContainer', function () {
|
|
|
153
153
|
restrict: 'self-only',
|
|
154
154
|
defaultElement: 'my-element'
|
|
155
155
|
};
|
|
156
|
-
(0, _react.render)(
|
|
156
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
157
157
|
containerConfig: {
|
|
158
158
|
defaultElement: config.defaultElement
|
|
159
159
|
},
|
|
@@ -166,12 +166,12 @@ describe('useSpotlightContainer', function () {
|
|
|
166
166
|
});
|
|
167
167
|
test('should update restrict value', function () {
|
|
168
168
|
var id = 'my-container';
|
|
169
|
-
var _render2 = (0, _react.render)(
|
|
169
|
+
var _render2 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
170
170
|
spotlightId: id,
|
|
171
171
|
spotlightRestrict: "self-only"
|
|
172
172
|
})),
|
|
173
173
|
rerender = _render2.rerender;
|
|
174
|
-
rerender(
|
|
174
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
175
175
|
spotlightId: id,
|
|
176
176
|
spotlightRestrict: "self-first"
|
|
177
177
|
}));
|
|
@@ -23,7 +23,7 @@ describe('SpotlightRootDecorator', function () {
|
|
|
23
23
|
};
|
|
24
24
|
test('should set `spotlight-input-key` class when the app is focused for the first time', function () {
|
|
25
25
|
var App = (0, _SpotlightRootDecorator.SpotlightRootDecorator)(AppBase);
|
|
26
|
-
(0, _react.render)(
|
|
26
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(App, {}));
|
|
27
27
|
var button = _react.screen.queryByText('123');
|
|
28
28
|
var element = _react.screen.getByTestId('root');
|
|
29
29
|
_react.fireEvent.focus(button);
|
|
@@ -32,7 +32,7 @@ describe('SpotlightRootDecorator', function () {
|
|
|
32
32
|
});
|
|
33
33
|
test('should set input type properly in internal variable', function () {
|
|
34
34
|
var App = (0, _SpotlightRootDecorator.SpotlightRootDecorator)(AppBase);
|
|
35
|
-
(0, _react.render)(
|
|
35
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(App, {}));
|
|
36
36
|
(0, _SpotlightRootDecorator.setInputType)('touch');
|
|
37
37
|
var expected = 'touch';
|
|
38
38
|
var actual = (0, _SpotlightRootDecorator.getInputType)();
|
|
@@ -40,7 +40,7 @@ describe('SpotlightRootDecorator', function () {
|
|
|
40
40
|
});
|
|
41
41
|
test('should set spotlightRootDecorator container enterTo config to `null` by default', function () {
|
|
42
42
|
var App = (0, _SpotlightRootDecorator.SpotlightRootDecorator)(AppBase);
|
|
43
|
-
(0, _react.render)(
|
|
43
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(App, {}));
|
|
44
44
|
var containerConfig = (0, _container.getContainerConfig)('spotlightRootDecorator');
|
|
45
45
|
var expected = null;
|
|
46
46
|
var actual = containerConfig.enterTo;
|
|
@@ -14,7 +14,7 @@ var id = 'test-spottable';
|
|
|
14
14
|
describe('Spottable', function () {
|
|
15
15
|
test('should add the spottable class', function () {
|
|
16
16
|
var Component = (0, _Spottable["default"])('div');
|
|
17
|
-
(0, _react.render)(
|
|
17
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
18
18
|
"data-testid": id
|
|
19
19
|
}));
|
|
20
20
|
var div = _react.screen.getByTestId(id);
|
|
@@ -23,7 +23,7 @@ describe('Spottable', function () {
|
|
|
23
23
|
});
|
|
24
24
|
test('should add the spottable class to a {disabled} component', function () {
|
|
25
25
|
var Component = (0, _Spottable["default"])('div');
|
|
26
|
-
(0, _react.render)(
|
|
26
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
27
27
|
"data-testid": id,
|
|
28
28
|
disabled: true
|
|
29
29
|
}));
|
|
@@ -33,7 +33,7 @@ describe('Spottable', function () {
|
|
|
33
33
|
});
|
|
34
34
|
test('should not add the spottable class to a {spotlightDisabled} component', function () {
|
|
35
35
|
var Component = (0, _Spottable["default"])('div');
|
|
36
|
-
(0, _react.render)(
|
|
36
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
37
37
|
"data-testid": id,
|
|
38
38
|
spotlightDisabled: true
|
|
39
39
|
}));
|
|
@@ -44,7 +44,7 @@ describe('Spottable', function () {
|
|
|
44
44
|
test('should emit {onSpotlightDisappear} when unmounted while focused', function () {
|
|
45
45
|
var spy = jest.fn();
|
|
46
46
|
var Component = (0, _Spottable["default"])('div');
|
|
47
|
-
var _render = (0, _react.render)(
|
|
47
|
+
var _render = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
48
48
|
"data-testid": id,
|
|
49
49
|
onSpotlightDisappear: spy
|
|
50
50
|
})),
|
|
@@ -64,9 +64,9 @@ describe('Spottable', function () {
|
|
|
64
64
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
|
|
65
65
|
});
|
|
66
66
|
var Component = (0, _Spottable["default"])(spy);
|
|
67
|
-
var _render2 = (0, _react.render)(
|
|
67
|
+
var _render2 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {})),
|
|
68
68
|
rerender = _render2.rerender;
|
|
69
|
-
rerender(
|
|
69
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
70
70
|
"data-id": "123"
|
|
71
71
|
}));
|
|
72
72
|
var expected = 3;
|
|
@@ -77,11 +77,11 @@ describe('Spottable', function () {
|
|
|
77
77
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
|
|
78
78
|
});
|
|
79
79
|
var Component = (0, _Spottable["default"])(spy);
|
|
80
|
-
var _render3 = (0, _react.render)(
|
|
80
|
+
var _render3 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
81
81
|
selectionKeys: [1, 2, 3]
|
|
82
82
|
})),
|
|
83
83
|
rerender = _render3.rerender;
|
|
84
|
-
rerender(
|
|
84
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
85
85
|
selectionKeys: [2, 1, 3]
|
|
86
86
|
}));
|
|
87
87
|
var expected = 3;
|
|
@@ -92,7 +92,7 @@ describe('Spottable', function () {
|
|
|
92
92
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
|
|
93
93
|
});
|
|
94
94
|
var Component = (0, _Spottable["default"])(spy);
|
|
95
|
-
(0, _react.render)(
|
|
95
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
96
96
|
"data-testid": id
|
|
97
97
|
}));
|
|
98
98
|
var div = _react.screen.getByTestId(id);
|
|
@@ -105,7 +105,7 @@ describe('useSpottable', function () {
|
|
|
105
105
|
_spotlight["default"].getCurrent = getCurrent;
|
|
106
106
|
});
|
|
107
107
|
test('should add the spottable class', function () {
|
|
108
|
-
(0, _react.render)(
|
|
108
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
109
109
|
"data-testid": id
|
|
110
110
|
}));
|
|
111
111
|
var div = _react.screen.getByTestId(id);
|
|
@@ -113,7 +113,7 @@ describe('useSpottable', function () {
|
|
|
113
113
|
expect(div).toHaveClass(expected);
|
|
114
114
|
});
|
|
115
115
|
test('should add the spottable class to a {disabled} component', function () {
|
|
116
|
-
(0, _react.render)(
|
|
116
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
117
117
|
"data-testid": id,
|
|
118
118
|
disabled: true
|
|
119
119
|
}));
|
|
@@ -122,7 +122,7 @@ describe('useSpottable', function () {
|
|
|
122
122
|
expect(div).toHaveClass(expected);
|
|
123
123
|
});
|
|
124
124
|
test('should not add the spottable class to a {spotlightDisabled} component', function () {
|
|
125
|
-
(0, _react.render)(
|
|
125
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
126
126
|
"data-testid": id,
|
|
127
127
|
spotlightDisabled: true
|
|
128
128
|
}));
|
|
@@ -133,7 +133,7 @@ describe('useSpottable', function () {
|
|
|
133
133
|
describe('should emit event properly', function () {
|
|
134
134
|
test('should emit {onSpotlightUp} when the the {keydown} is emitted with 38 keycode', function () {
|
|
135
135
|
var spy = jest.fn();
|
|
136
|
-
(0, _react.render)(
|
|
136
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
137
137
|
"data-testid": id,
|
|
138
138
|
onSpotlightUp: spy
|
|
139
139
|
}));
|
|
@@ -144,7 +144,7 @@ describe('useSpottable', function () {
|
|
|
144
144
|
});
|
|
145
145
|
test('should emit {onSpotlightDown} when the the {keydown} is emitted with 40 keycode', function () {
|
|
146
146
|
var spy = jest.fn();
|
|
147
|
-
(0, _react.render)(
|
|
147
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
148
148
|
"data-testid": id,
|
|
149
149
|
onSpotlightDown: spy
|
|
150
150
|
}));
|
|
@@ -155,7 +155,7 @@ describe('useSpottable', function () {
|
|
|
155
155
|
});
|
|
156
156
|
test('should emit {onSpotlightLeft} when the the {keydown} is emitted with 37 keycode', function () {
|
|
157
157
|
var spy = jest.fn();
|
|
158
|
-
(0, _react.render)(
|
|
158
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
159
159
|
"data-testid": id,
|
|
160
160
|
onSpotlightLeft: spy
|
|
161
161
|
}));
|
|
@@ -166,7 +166,7 @@ describe('useSpottable', function () {
|
|
|
166
166
|
});
|
|
167
167
|
test('should emit {onSpotlightRight} when the the {keydown} is emitted with 39 keycode', function () {
|
|
168
168
|
var spy = jest.fn();
|
|
169
|
-
(0, _react.render)(
|
|
169
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
170
170
|
"data-testid": id,
|
|
171
171
|
onSpotlightRight: spy
|
|
172
172
|
}));
|
|
@@ -177,7 +177,7 @@ describe('useSpottable', function () {
|
|
|
177
177
|
});
|
|
178
178
|
test('should emulate {onMouseDown} when REMOTE_OK_KEY key is pressed', function () {
|
|
179
179
|
var spy = jest.fn();
|
|
180
|
-
(0, _react.render)(
|
|
180
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
181
181
|
"data-testid": id,
|
|
182
182
|
emulateMouse: true,
|
|
183
183
|
onMouseDown: spy,
|
|
@@ -190,7 +190,7 @@ describe('useSpottable', function () {
|
|
|
190
190
|
});
|
|
191
191
|
test('should emulate {onMouseUp} when {REMOTE_OK_KEY} key is pressed and released', function () {
|
|
192
192
|
var spy = jest.fn();
|
|
193
|
-
(0, _react.render)(
|
|
193
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
194
194
|
"data-testid": id,
|
|
195
195
|
emulateMouse: true,
|
|
196
196
|
onMouseUp: spy,
|
|
@@ -207,7 +207,7 @@ describe('useSpottable', function () {
|
|
|
207
207
|
function onKeyUp(ev) {
|
|
208
208
|
ev.preventDefault();
|
|
209
209
|
}
|
|
210
|
-
(0, _react.render)(
|
|
210
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
211
211
|
"data-testid": id,
|
|
212
212
|
emulateMouse: true,
|
|
213
213
|
onKeyUp: onKeyUp,
|
|
@@ -225,12 +225,12 @@ describe('useSpottable', function () {
|
|
|
225
225
|
var spy = jest.fn(function (props) {
|
|
226
226
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
|
|
227
227
|
});
|
|
228
|
-
var _render = (0, _react.render)(
|
|
228
|
+
var _render = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
229
229
|
component: spy,
|
|
230
230
|
"data-testid": id
|
|
231
231
|
})),
|
|
232
232
|
rerender = _render.rerender;
|
|
233
|
-
rerender(
|
|
233
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
234
234
|
component: spy,
|
|
235
235
|
"data-id": "123",
|
|
236
236
|
"data-testid": id
|
|
@@ -242,13 +242,13 @@ describe('useSpottable', function () {
|
|
|
242
242
|
var spy = jest.fn(function (props) {
|
|
243
243
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
|
|
244
244
|
});
|
|
245
|
-
var _render2 = (0, _react.render)(
|
|
245
|
+
var _render2 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
246
246
|
component: spy,
|
|
247
247
|
"data-testid": id,
|
|
248
248
|
selectionKeys: [1, 2, 3]
|
|
249
249
|
})),
|
|
250
250
|
rerender = _render2.rerender;
|
|
251
|
-
rerender(
|
|
251
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
252
252
|
component: spy,
|
|
253
253
|
"data-testid": id,
|
|
254
254
|
selectionKeys: [2, 1, 3]
|
|
@@ -260,7 +260,7 @@ describe('useSpottable', function () {
|
|
|
260
260
|
var spy = jest.fn(function (props) {
|
|
261
261
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, props));
|
|
262
262
|
});
|
|
263
|
-
(0, _react.render)(
|
|
263
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableComponent, {
|
|
264
264
|
component: spy,
|
|
265
265
|
"data-testid": id
|
|
266
266
|
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enact/spotlight",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.4",
|
|
4
4
|
"description": "A focus management library",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@enact/core": "^5.0.0-alpha.
|
|
28
|
+
"@enact/core": "^5.0.0-alpha.4",
|
|
29
29
|
"classnames": "^2.5.1",
|
|
30
30
|
"prop-types": "^15.8.1",
|
|
31
31
|
"ramda": "^0.30.1",
|
|
32
|
-
"react": "^
|
|
33
|
-
"react-dom": "^
|
|
32
|
+
"react": "^19.0.0",
|
|
33
|
+
"react-dom": "^19.0.0",
|
|
34
34
|
"warning": "^4.0.3"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/src/container.js
CHANGED
|
@@ -387,7 +387,7 @@ var getSpottableDescendants = exports.getSpottableDescendants = function getSpot
|
|
|
387
387
|
* @memberof spotlight/container
|
|
388
388
|
* @private
|
|
389
389
|
*/
|
|
390
|
-
var
|
|
390
|
+
var _getDeepSpottableDescendants = exports.getDeepSpottableDescendants = function getDeepSpottableDescendants(containerId, excludedContainers) {
|
|
391
391
|
return getSpottableDescendants(containerId).map(function (n) {
|
|
392
392
|
if (isContainer(n)) {
|
|
393
393
|
var id = getContainerId(n);
|
|
@@ -395,7 +395,7 @@ var getDeepSpottableDescendants = exports.getDeepSpottableDescendants = function
|
|
|
395
395
|
if (excludedContainers && excludedContainers.indexOf(id) >= 0) {
|
|
396
396
|
return [];
|
|
397
397
|
} else if (config && !config.enterTo) {
|
|
398
|
-
return
|
|
398
|
+
return _getDeepSpottableDescendants(id, excludedContainers);
|
|
399
399
|
}
|
|
400
400
|
}
|
|
401
401
|
return [n];
|
|
@@ -666,7 +666,7 @@ function getContainerDefaultElement(containerId, preferredEnterTo) {
|
|
|
666
666
|
if (preferredEnterTo && typeof preferredEnterTo === 'string' && preferredEnterTo !== 'default-element') {
|
|
667
667
|
defaultElementSelector.unshift(preferredEnterTo);
|
|
668
668
|
}
|
|
669
|
-
var spottables =
|
|
669
|
+
var spottables = _getDeepSpottableDescendants(containerId);
|
|
670
670
|
return defaultElementSelector.reduce(function (result, selector) {
|
|
671
671
|
if (result) {
|
|
672
672
|
return result;
|
|
@@ -770,7 +770,7 @@ function getContainerNavigableElements(containerId, preferredEnterTo) {
|
|
|
770
770
|
var spottables = overflow ?
|
|
771
771
|
// overflow requires deep recursion to handle selecting the children of unrestricted
|
|
772
772
|
// containers or restricted containers larger than the container
|
|
773
|
-
|
|
773
|
+
_getDeepSpottableDescendants(containerId) : getSpottableDescendants(containerId);
|
|
774
774
|
|
|
775
775
|
// if there isn't a preferred entry on an overflow container, filter the visible elements
|
|
776
776
|
if (overflow) {
|
|
@@ -858,7 +858,7 @@ function persistLastFocusedElement(containerId) {
|
|
|
858
858
|
if (cfg) {
|
|
859
859
|
var lastFocusedElement = cfg.lastFocusedElement;
|
|
860
860
|
if (lastFocusedElement) {
|
|
861
|
-
var all =
|
|
861
|
+
var all = _getDeepSpottableDescendants(containerId);
|
|
862
862
|
var lastFocusedKey = cfg.lastFocusedPersist(lastFocusedElement, all);
|
|
863
863
|
|
|
864
864
|
// store lastFocusedKey and release node reference to lastFocusedElement
|
|
@@ -881,7 +881,7 @@ function persistLastFocusedElement(containerId) {
|
|
|
881
881
|
function restoreLastFocusedElement(containerId) {
|
|
882
882
|
var cfg = getContainerConfig(containerId);
|
|
883
883
|
if (cfg && cfg.lastFocusedKey) {
|
|
884
|
-
var all =
|
|
884
|
+
var all = _getDeepSpottableDescendants(containerId);
|
|
885
885
|
var lastFocusedElement = cfg.lastFocusedRestore(cfg.lastFocusedKey, all);
|
|
886
886
|
|
|
887
887
|
// restore lastFocusedElement and release lastFocusedKey
|
package/src/spotlight.d.ts
CHANGED
|
@@ -68,7 +68,7 @@ container.
|
|
|
68
68
|
* If Spotlight is in pointer mode, focus is not changed but `elem` will be set as the last
|
|
69
69
|
focused element of its spotlight containers.
|
|
70
70
|
*/
|
|
71
|
-
focus(elem?: string | React.ReactNode,
|
|
71
|
+
focus(elem?: string | React.ReactNode, options?: object): boolean;
|
|
72
72
|
/**
|
|
73
73
|
* Moves focus to the next spottable control in the direction specified. Optionally, a source
|
|
74
74
|
element selector may be supplied as the starting point.
|
package/src/spotlight.js
CHANGED
|
@@ -141,7 +141,7 @@ var Spotlight = exports.Spotlight = function () {
|
|
|
141
141
|
(0, _pointer.setPointerMode)(webOSSystem.cursor.visibility);
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
function focusElement(elem, containerIds, fromPointer) {
|
|
144
|
+
function focusElement(elem, containerIds, fromPointer, preventScroll) {
|
|
145
145
|
var _window$webOSSystem2, _webOSSystem$cursor;
|
|
146
146
|
if (!elem) {
|
|
147
147
|
return false;
|
|
@@ -155,7 +155,7 @@ var Spotlight = exports.Spotlight = function () {
|
|
|
155
155
|
if (elem === currentFocusedElement) {
|
|
156
156
|
return true;
|
|
157
157
|
}
|
|
158
|
-
var focusOptions = (0, _container.isWithinOverflowContainer)(elem, containerIds) ? {
|
|
158
|
+
var focusOptions = preventScroll || (0, _container.isWithinOverflowContainer)(elem, containerIds) ? {
|
|
159
159
|
preventScroll: true
|
|
160
160
|
} : null;
|
|
161
161
|
var silentFocus = function silentFocus() {
|
|
@@ -610,17 +610,20 @@ var Spotlight = exports.Spotlight = function () {
|
|
|
610
610
|
* @param {String|Node} [elem] The spotlight ID or selector for either a spottable
|
|
611
611
|
* component or a spotlight container, or spottable node. If not supplied, the default
|
|
612
612
|
* container will be focused.
|
|
613
|
-
* @param {Object} [
|
|
614
|
-
*
|
|
615
|
-
*
|
|
613
|
+
* @param {Object} [options] The object including `enterTo`, `toOuterContainer`, and `preventScroll`.
|
|
614
|
+
* `enterTo` and `toOuterContainer` work when the first parameter `elem` is either
|
|
615
|
+
* a spotlight container ID or a spotlight container node.
|
|
616
|
+
* @param {('last-focused'|'default-element'|'topmost')} [options.enterTo] Specifies preferred
|
|
616
617
|
* `enterTo` configuration.
|
|
617
|
-
* @param {Boolean} [
|
|
618
|
+
* @param {Boolean} [options.toOuterContainer] If the proper target is not found, search one
|
|
618
619
|
* recursively to outer container.
|
|
620
|
+
* @param {Boolean} [options.preventScroll] Prevents the focused element from an automatic scrolling
|
|
621
|
+
* into view after focusing the element.
|
|
619
622
|
* @returns {Boolean} `true` if focus successful, `false` if not.
|
|
620
623
|
* @public
|
|
621
624
|
*/
|
|
622
625
|
focus: function focus(elem) {
|
|
623
|
-
var
|
|
626
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
624
627
|
var target = elem;
|
|
625
628
|
var wasContainerId = false;
|
|
626
629
|
var currentContainerNode = null;
|
|
@@ -628,7 +631,7 @@ var Spotlight = exports.Spotlight = function () {
|
|
|
628
631
|
target = (0, _target.getTargetByContainer)();
|
|
629
632
|
} else if (typeof elem === 'string') {
|
|
630
633
|
if ((0, _container.getContainerConfig)(elem)) {
|
|
631
|
-
target = (0, _target.getTargetByContainer)(elem,
|
|
634
|
+
target = (0, _target.getTargetByContainer)(elem, options.enterTo);
|
|
632
635
|
wasContainerId = true;
|
|
633
636
|
currentContainerNode = (0, _container.getContainerNode)(elem);
|
|
634
637
|
} else if (/^[\w\d-]+$/.test(elem)) {
|
|
@@ -638,13 +641,13 @@ var Spotlight = exports.Spotlight = function () {
|
|
|
638
641
|
target = (0, _target.getTargetBySelector)(elem);
|
|
639
642
|
}
|
|
640
643
|
} else if ((0, _container.isContainer)(elem)) {
|
|
641
|
-
target = (0, _target.getTargetByContainer)((0, _container.getContainerId)(elem),
|
|
644
|
+
target = (0, _target.getTargetByContainer)((0, _container.getContainerId)(elem), options.enterTo);
|
|
642
645
|
currentContainerNode = elem;
|
|
643
646
|
}
|
|
644
647
|
var nextContainerIds = (0, _container.getContainersForNode)(target);
|
|
645
648
|
var nextContainerId = (0, _last["default"])(nextContainerIds);
|
|
646
649
|
if ((0, _container.isNavigable)(target, nextContainerId, true)) {
|
|
647
|
-
var focused = focusElement(target, nextContainerIds);
|
|
650
|
+
var focused = focusElement(target, nextContainerIds, false, options.preventScroll);
|
|
648
651
|
if (!focused && wasContainerId) {
|
|
649
652
|
(0, _container.setLastContainer)(elem);
|
|
650
653
|
}
|
|
@@ -654,10 +657,10 @@ var Spotlight = exports.Spotlight = function () {
|
|
|
654
657
|
// it as the active container to allow it to focus itself if its contents change
|
|
655
658
|
(0, _container.setLastContainer)(elem);
|
|
656
659
|
}
|
|
657
|
-
if (
|
|
660
|
+
if (options.toOuterContainer && currentContainerNode) {
|
|
658
661
|
var outerContainer = (0, _container.getContainersForNode)(currentContainerNode.parentElement).pop();
|
|
659
662
|
if (outerContainer) {
|
|
660
|
-
return this.focus(outerContainer,
|
|
663
|
+
return this.focus(outerContainer, options);
|
|
661
664
|
}
|
|
662
665
|
}
|
|
663
666
|
return false;
|
|
@@ -85,6 +85,15 @@ describe('Spotlight', function () {
|
|
|
85
85
|
_spotlight["default"].focus('[data-spotlight-id="first-container"]');
|
|
86
86
|
expect(fn).toBeCalled();
|
|
87
87
|
}));
|
|
88
|
+
test('should pass preventScroll option', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
|
|
89
|
+
var fn = mockFocus(root.querySelector('[data-spotlight-id="s1"]'));
|
|
90
|
+
_spotlight["default"].focus('s1', {
|
|
91
|
+
preventScroll: true
|
|
92
|
+
});
|
|
93
|
+
expect(fn).toHaveBeenCalledWith({
|
|
94
|
+
preventScroll: true
|
|
95
|
+
});
|
|
96
|
+
}));
|
|
88
97
|
});
|
|
89
98
|
describe('#move', function () {
|
|
90
99
|
beforeEach(setupContainers);
|