@enact/spotlight 4.8.0 → 4.9.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +7 -9
- package/SpotlightRootDecorator/SpotlightRootDecorator.js +1 -1
- package/SpotlightRootDecorator/tests/SpotlightRootDecorator-specs.js +9 -0
- package/Spottable/Spottable.js +1 -1
- package/Spottable/tests/useSpot-specs.js +1 -1
- package/package.json +4 -4
- package/src/container.js +23 -2
- package/src/spotlight.js +4 -4
- package/src/target.js +14 -4
- package/src/tests/container-specs.js +190 -170
- package/src/tests/inputType-specs.js +11 -0
- package/src/tests/utils-specs.js +76 -0
- package/src/utils.js +29 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
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.9.0-alpha.2] - 2024-05-24
|
|
6
|
+
|
|
7
|
+
No significant changes.
|
|
8
|
+
|
|
9
|
+
## [4.0.14] - 2024-05-14
|
|
10
|
+
|
|
11
|
+
No significant changes.
|
|
12
|
+
|
|
13
|
+
## [4.7.11] - 2024-05-13
|
|
14
|
+
|
|
15
|
+
No significant changes.
|
|
16
|
+
|
|
17
|
+
## [4.9.0-alpha.1] - 2024-04-09
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- `spotlight` navigation from the focused element clipped by an overflow container
|
|
22
|
+
|
|
23
|
+
## [4.7.10] - 2024-03-05
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- `spotlight` navigation from the focused element clipped by an overflow container
|
|
28
|
+
|
|
5
29
|
## [4.8.0] - 2024-02-08
|
|
6
30
|
|
|
7
31
|
No significant changes.
|
|
@@ -36,7 +36,7 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Objec
|
|
|
36
36
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
37
37
|
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
38
38
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
39
|
-
function _isNativeReflectConstruct() {
|
|
39
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
40
40
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
41
41
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
42
42
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -200,10 +200,13 @@ var SpotlightContainerDecorator = exports.SpotlightContainerDecorator = (0, _hoc
|
|
|
200
200
|
|
|
201
201
|
// eslint-disable-next-line no-shadow
|
|
202
202
|
function SpotlightContainerDecorator(props) {
|
|
203
|
-
var
|
|
203
|
+
var _props$spotlightDisab = props.spotlightDisabled,
|
|
204
|
+
spotlightDisabled = _props$spotlightDisab === void 0 ? false : _props$spotlightDisab,
|
|
204
205
|
spotlightId = props.spotlightId,
|
|
205
|
-
spotlightMuted = props.spotlightMuted,
|
|
206
|
-
|
|
206
|
+
_props$spotlightMuted = props.spotlightMuted,
|
|
207
|
+
spotlightMuted = _props$spotlightMuted === void 0 ? false : _props$spotlightMuted,
|
|
208
|
+
_props$spotlightRestr = props.spotlightRestrict,
|
|
209
|
+
spotlightRestrict = _props$spotlightRestr === void 0 ? 'self-first' : _props$spotlightRestr,
|
|
207
210
|
rest = _objectWithoutProperties(props, _excluded2);
|
|
208
211
|
var spotlightContainer = (0, _useSpotlightContainer["default"])({
|
|
209
212
|
id: spotlightId,
|
|
@@ -265,11 +268,6 @@ var SpotlightContainerDecorator = exports.SpotlightContainerDecorator = (0, _hoc
|
|
|
265
268
|
*/
|
|
266
269
|
spotlightRestrict: _propTypes["default"].oneOf(['none', 'self-first', 'self-only'])
|
|
267
270
|
};
|
|
268
|
-
SpotlightContainerDecorator.defaultProps = {
|
|
269
|
-
spotlightDisabled: false,
|
|
270
|
-
spotlightMuted: false,
|
|
271
|
-
spotlightRestrict: 'self-first'
|
|
272
|
-
};
|
|
273
271
|
|
|
274
272
|
// Wrapping with a React.Component to maintain ref support
|
|
275
273
|
return /*#__PURE__*/function (_Component) {
|
|
@@ -46,7 +46,7 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Objec
|
|
|
46
46
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
47
47
|
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
48
48
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
49
|
-
function _isNativeReflectConstruct() {
|
|
49
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
50
50
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /**
|
|
51
51
|
* Exports the {@link spotlight/SpotlightRootDecorator.SpotlightRootDecorator}
|
|
52
52
|
* higher-order component.
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require("@testing-library/jest-dom");
|
|
4
4
|
var _react = require("@testing-library/react");
|
|
5
5
|
var _SpotlightRootDecorator = require("../SpotlightRootDecorator");
|
|
6
|
+
var _container = require("../../src/container");
|
|
6
7
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
7
8
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
8
9
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -37,4 +38,12 @@ describe('SpotlightRootDecorator', function () {
|
|
|
37
38
|
var actual = (0, _SpotlightRootDecorator.getInputType)();
|
|
38
39
|
expect(actual).toBe(expected);
|
|
39
40
|
});
|
|
41
|
+
test('should set spotlightRootDecorator container enterTo config to `null` by default', function () {
|
|
42
|
+
var App = (0, _SpotlightRootDecorator.SpotlightRootDecorator)(AppBase);
|
|
43
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(App, {}));
|
|
44
|
+
var containerConfig = (0, _container.getContainerConfig)('spotlightRootDecorator');
|
|
45
|
+
var expected = null;
|
|
46
|
+
var actual = containerConfig.enterTo;
|
|
47
|
+
expect(actual).toBe(expected);
|
|
48
|
+
});
|
|
40
49
|
});
|
package/Spottable/Spottable.js
CHANGED
|
@@ -45,7 +45,7 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Objec
|
|
|
45
45
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
46
46
|
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
47
47
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
48
|
-
function _isNativeReflectConstruct() {
|
|
48
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
49
49
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
50
50
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
51
51
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -22,7 +22,7 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Objec
|
|
|
22
22
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
23
23
|
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
24
24
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
25
|
-
function _isNativeReflectConstruct() {
|
|
25
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
26
26
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
27
27
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
28
28
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enact/spotlight",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.9.0-alpha.2",
|
|
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": "^4.
|
|
28
|
+
"@enact/core": "^4.9.0-alpha.2",
|
|
29
29
|
"classnames": "^2.5.1",
|
|
30
30
|
"prop-types": "^15.8.1",
|
|
31
31
|
"ramda": "^0.29.1",
|
|
32
|
-
"react": "^18.
|
|
33
|
-
"react-dom": "^18.
|
|
32
|
+
"react": "^18.3.1",
|
|
33
|
+
"react-dom": "^18.3.1",
|
|
34
34
|
"warning": "^4.0.3"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/src/container.js
CHANGED
|
@@ -16,6 +16,7 @@ exports.getDeepSpottableDescendants = void 0;
|
|
|
16
16
|
exports.getDefaultContainer = getDefaultContainer;
|
|
17
17
|
exports.getLastContainer = getLastContainer;
|
|
18
18
|
exports.getNavigableContainersForNode = getNavigableContainersForNode;
|
|
19
|
+
exports.getPositionTargetOnFocus = getPositionTargetOnFocus;
|
|
19
20
|
exports.isNavigable = exports.isContainer5WayHoldable = exports.isContainer = exports.getSpottableDescendants = void 0;
|
|
20
21
|
exports.isWithinOverflowContainer = isWithinOverflowContainer;
|
|
21
22
|
exports.mayActivateContainer = mayActivateContainer;
|
|
@@ -84,8 +85,8 @@ var GlobalConfig = {
|
|
|
84
85
|
continue5WayHold: false,
|
|
85
86
|
defaultElement: '',
|
|
86
87
|
// <extSelector> except "@" syntax.
|
|
87
|
-
enterTo:
|
|
88
|
-
//
|
|
88
|
+
enterTo: null,
|
|
89
|
+
// null, 'last-focused', 'default-element'
|
|
89
90
|
isStandardFocusableMode: false,
|
|
90
91
|
// @private - set to true to focus standard focusable element
|
|
91
92
|
lastFocusedElement: null,
|
|
@@ -116,6 +117,8 @@ var GlobalConfig = {
|
|
|
116
117
|
overflow: false,
|
|
117
118
|
partition: false,
|
|
118
119
|
// use the container bounds for partitioning when leaving
|
|
120
|
+
positionTargetOnFocus: false,
|
|
121
|
+
// @private - use the container for the position target when its descendants is focused
|
|
119
122
|
rememberSource: false,
|
|
120
123
|
restrict: 'self-first',
|
|
121
124
|
// 'self-first', 'self-only', 'none'
|
|
@@ -1082,4 +1085,22 @@ function notifyEnterContainer(direction, previous, previousContainerIds, current
|
|
|
1082
1085
|
}
|
|
1083
1086
|
}
|
|
1084
1087
|
});
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* Returns the closest container that wrap the element and has positionTargetOnFocus configured
|
|
1092
|
+
*
|
|
1093
|
+
* @param {Node} spotItem Focused element
|
|
1094
|
+
* @param {String[]} containerIds Ids for containers that wrap the spotItem element
|
|
1095
|
+
* @private
|
|
1096
|
+
*/
|
|
1097
|
+
function getPositionTargetOnFocus(spotItem) {
|
|
1098
|
+
var containerIds = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getContainersForNode(spotItem);
|
|
1099
|
+
return containerIds.reduce(function (result, containerId) {
|
|
1100
|
+
var _getContainerConfig;
|
|
1101
|
+
if ((_getContainerConfig = getContainerConfig(containerId)) !== null && _getContainerConfig !== void 0 && _getContainerConfig.positionTargetOnFocus) {
|
|
1102
|
+
result = getContainerNode(containerId);
|
|
1103
|
+
}
|
|
1104
|
+
return result;
|
|
1105
|
+
}, spotItem);
|
|
1085
1106
|
}
|
package/src/spotlight.js
CHANGED
|
@@ -442,10 +442,10 @@ var Spotlight = exports.Spotlight = function () {
|
|
|
442
442
|
window.addEventListener('keyup', onKeyUp);
|
|
443
443
|
window.addEventListener('mouseover', onMouseOver);
|
|
444
444
|
window.addEventListener('mousemove', onMouseMove);
|
|
445
|
-
if (_platform["default"].
|
|
445
|
+
if (_platform["default"].touchEvent) {
|
|
446
446
|
window.addEventListener('touchend', onTouchEnd);
|
|
447
447
|
}
|
|
448
|
-
if (_platform["default"].webos) {
|
|
448
|
+
if (_platform["default"].type === 'webos') {
|
|
449
449
|
window.top.document.addEventListener('webOSMouse', handleWebOSMouseEvent);
|
|
450
450
|
window.top.document.addEventListener('keyboardStateChange', handleKeyboardStateChangeEvent);
|
|
451
451
|
}
|
|
@@ -475,10 +475,10 @@ var Spotlight = exports.Spotlight = function () {
|
|
|
475
475
|
window.removeEventListener('keyup', onKeyUp);
|
|
476
476
|
window.removeEventListener('mouseover', onMouseOver);
|
|
477
477
|
window.removeEventListener('mousemove', onMouseMove);
|
|
478
|
-
if (_platform["default"].
|
|
478
|
+
if (_platform["default"].touchEvent) {
|
|
479
479
|
window.removeEventListener('touchend', onTouchEnd);
|
|
480
480
|
}
|
|
481
|
-
if (_platform["default"].webos) {
|
|
481
|
+
if (_platform["default"].type === 'webos') {
|
|
482
482
|
window.top.document.removeEventListener('webOSMouse', handleWebOSMouseEvent);
|
|
483
483
|
window.top.document.removeEventListener('keyboardStateChange', handleKeyboardStateChangeEvent);
|
|
484
484
|
}
|
package/src/target.js
CHANGED
|
@@ -296,13 +296,15 @@ function getTargetInContainerByDirectionFromElement(direction, containerId, elem
|
|
|
296
296
|
return next;
|
|
297
297
|
}
|
|
298
298
|
function getTargetByDirectionFromElement(direction, element) {
|
|
299
|
+
var _getContainerConfig;
|
|
300
|
+
var getIntersectRectOfElem = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
299
301
|
var extSelector = element.getAttribute('data-spot-' + direction);
|
|
300
302
|
if (typeof extSelector === 'string') {
|
|
301
303
|
return getTargetBySelector(extSelector);
|
|
302
304
|
}
|
|
303
|
-
var
|
|
305
|
+
var elementContainerId = (0, _container.getContainersForNode)(element).pop();
|
|
304
306
|
var next = (0, _container.getNavigableContainersForNode)(element).reduceRight(function (result, containerId, index, elementContainerIds) {
|
|
305
|
-
result = result || getTargetInContainerByDirectionFromElement(direction, containerId, element,
|
|
307
|
+
result = result || getTargetInContainerByDirectionFromElement(direction, containerId, element, getIntersectRectOfElem ? (0, _utils.getIntersectionRect)((0, _container.getContainerNode)(elementContainerId), element) : (0, _utils.getRect)(element), elementContainerIds);
|
|
306
308
|
if (!result) {
|
|
307
309
|
result = getLeaveForTarget(containerId, direction);
|
|
308
310
|
|
|
@@ -316,9 +318,17 @@ function getTargetByDirectionFromElement(direction, element) {
|
|
|
316
318
|
return result;
|
|
317
319
|
}, null);
|
|
318
320
|
|
|
319
|
-
//
|
|
321
|
+
// If the reduce above returns the original element,
|
|
322
|
+
// check if the element is clipped by an overflow container. If true, find the target by direction with the intersection rect of the element.
|
|
323
|
+
// If the reduce above returns the original element again, it means it hit a `leaveFor` config that
|
|
320
324
|
// prevents navigation so we enforce that here by returning null.
|
|
321
|
-
|
|
325
|
+
if (next !== element) {
|
|
326
|
+
return next;
|
|
327
|
+
} else if (elementContainerId !== _container.rootContainerId && (_getContainerConfig = (0, _container.getContainerConfig)(elementContainerId)) !== null && _getContainerConfig !== void 0 && _getContainerConfig.overflow && !getIntersectRectOfElem) {
|
|
328
|
+
return getTargetByDirectionFromElement(direction, element, true);
|
|
329
|
+
} else {
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
322
332
|
}
|
|
323
333
|
function getTargetByDirectionFromPosition(direction, position, containerId) {
|
|
324
334
|
var pointerRect = (0, _utils.getPointRect)(position);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _container19 = require("../container");
|
|
4
4
|
var _utils = require("./utils");
|
|
5
5
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
@@ -16,24 +16,24 @@ var scenarios = {
|
|
|
16
16
|
spottableAndContainers: (0, _utils.someSpottablesAndContainers)(5),
|
|
17
17
|
nonSpottableSiblings: (0, _utils.join)((0, _utils.someSpottables)(5), (0, _utils.someNodes)(nonSpottable, 5)),
|
|
18
18
|
nestedContainers: (0, _utils.container)((0, _utils.container)((0, _utils.container)())),
|
|
19
|
-
disabledContainers: (0, _utils.join)((0, _utils.someSpottables)(5), (0, _utils.someContainers)(5), (0, _utils.node)(_defineProperty(_defineProperty({},
|
|
19
|
+
disabledContainers: (0, _utils.join)((0, _utils.someSpottables)(5), (0, _utils.someContainers)(5), (0, _utils.node)(_defineProperty(_defineProperty({}, _container19.containerAttribute, 'disabled-container'), 'data-spotlight-container-disabled', true))),
|
|
20
20
|
nestedContainersWithSpottables: (0, _utils.join)((0, _utils.someSpottables)(5), (0, _utils.container)({
|
|
21
21
|
children: (0, _utils.someSpottables)(5)
|
|
22
22
|
})),
|
|
23
|
-
siblingContainers: (0, _utils.join)((0, _utils.container)(_defineProperty(_defineProperty({},
|
|
24
|
-
mixedOrder: (0, _utils.join)((0, _utils.container)(_defineProperty(_defineProperty({},
|
|
23
|
+
siblingContainers: (0, _utils.join)((0, _utils.container)(_defineProperty(_defineProperty({}, _container19.containerAttribute, 'first'), "children", (0, _utils.someSpottables)(5))), (0, _utils.container)(_defineProperty(_defineProperty({}, _container19.containerAttribute, 'second'), "children", (0, _utils.someSpottables)(5)))),
|
|
24
|
+
mixedOrder: (0, _utils.join)((0, _utils.container)(_defineProperty(_defineProperty({}, _container19.containerAttribute, 'first'), "name", 'c1')), (0, _utils.spottable)({
|
|
25
25
|
name: 's1'
|
|
26
|
-
}), (0, _utils.container)(_defineProperty(_defineProperty({},
|
|
26
|
+
}), (0, _utils.container)(_defineProperty(_defineProperty({}, _container19.containerAttribute, 'second'), "name", 'c2')), (0, _utils.spottable)({
|
|
27
27
|
name: 's2'
|
|
28
28
|
})),
|
|
29
|
-
complexTree: (0, _utils.join)((0, _utils.spottable)(nonSpottable()), (0, _utils.container)(_defineProperty(_defineProperty({},
|
|
29
|
+
complexTree: (0, _utils.join)((0, _utils.spottable)(nonSpottable()), (0, _utils.container)(_defineProperty(_defineProperty({}, _container19.containerAttribute, 'first-container'), "children", (0, _utils.join)((0, _utils.someSpottables)(2), (0, _utils.container)(_defineProperty(_defineProperty({}, _container19.containerAttribute, 'second-container'), "children", (0, _utils.join)((0, _utils.spottable)({
|
|
30
30
|
id: 'secondContainerFirstSpottable'
|
|
31
|
-
}), (0, _utils.someSpottables)(2), (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({},
|
|
31
|
+
}), (0, _utils.someSpottables)(2), (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({}, _container19.containerAttribute, 'third-container'), 'data-spotlight-container-disabled', true), "children", (0, _utils.join)((0, _utils.someSpottables)(4), (0, _utils.node)({
|
|
32
32
|
id: 'child-of-third'
|
|
33
33
|
}))))))))))),
|
|
34
|
-
spottablesInDisabledContainer: (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({},
|
|
35
|
-
spottablesInNestedDisabledContainer: (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({},
|
|
36
|
-
containerWithDefaultAndLastFocused: (0, _utils.container)(_defineProperty(_defineProperty({},
|
|
34
|
+
spottablesInDisabledContainer: (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({}, _container19.containerAttribute, 'container'), 'data-spotlight-container-disabled', true), "children", (0, _utils.someSpottables)(5))),
|
|
35
|
+
spottablesInNestedDisabledContainer: (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({}, _container19.containerAttribute, 'container'), 'data-spotlight-container-disabled', true), "children", (0, _utils.container)(_defineProperty(_defineProperty({}, _container19.containerAttribute, 'child'), "children", (0, _utils.someSpottables)(5))))),
|
|
36
|
+
containerWithDefaultAndLastFocused: (0, _utils.container)(_defineProperty(_defineProperty({}, _container19.containerAttribute, 'container'), "children", (0, _utils.join)((0, _utils.spottable)({
|
|
37
37
|
id: 'firstSpottable'
|
|
38
38
|
}), (0, _utils.someSpottables)(5), (0, _utils.node)({
|
|
39
39
|
id: 'spottableDefault',
|
|
@@ -41,36 +41,41 @@ var scenarios = {
|
|
|
41
41
|
}), (0, _utils.spottable)({
|
|
42
42
|
id: 'lastFocused'
|
|
43
43
|
})))),
|
|
44
|
-
nestedContainersWithDefaultAndLastFocused: (0, _utils.container)(_defineProperty(_defineProperty({},
|
|
44
|
+
nestedContainersWithDefaultAndLastFocused: (0, _utils.container)(_defineProperty(_defineProperty({}, _container19.containerAttribute, 'container'), "children", (0, _utils.join)((0, _utils.spottable)({
|
|
45
45
|
id: 'firstSpottable'
|
|
46
|
-
}), (0, _utils.someSpottables)(5), (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty(_defineProperty({},
|
|
46
|
+
}), (0, _utils.someSpottables)(5), (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, _container19.containerAttribute, 'child'), "id", 'spottableDefault'), "className", 'spottable-default'), "children", (0, _utils.join)((0, _utils.spottable)({
|
|
47
47
|
id: 'firstChildSpottable'
|
|
48
48
|
}), (0, _utils.someSpottables)(5), (0, _utils.spottable)({
|
|
49
49
|
id: 'lastChildFocused'
|
|
50
50
|
})))), (0, _utils.spottable)({
|
|
51
51
|
id: 'lastFocused'
|
|
52
52
|
})))),
|
|
53
|
-
emptySubcontainer: (0, _utils.container)(_defineProperty(_defineProperty({},
|
|
53
|
+
emptySubcontainer: (0, _utils.container)(_defineProperty(_defineProperty({}, _container19.containerAttribute, 'container'), "children", (0, _utils.join)((0, _utils.container)(_defineProperty({}, _container19.containerAttribute, 'subcontainer')), (0, _utils.spottable)({
|
|
54
54
|
id: 'afterSubcontainer'
|
|
55
55
|
})))),
|
|
56
56
|
owned: (0, _utils.join)((0, _utils.spottable)({
|
|
57
57
|
id: 's1'
|
|
58
58
|
}), (0, _utils.node)({
|
|
59
59
|
id: 'n1'
|
|
60
|
-
}), (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({},
|
|
60
|
+
}), (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({}, _container19.containerAttribute, 'container'), 'aria-owns', 's1 n1'), "children", (0, _utils.spottable)({
|
|
61
61
|
id: 's2'
|
|
62
|
-
}))))
|
|
62
|
+
})))),
|
|
63
|
+
positionTargetOnFocusContainer: (0, _utils.container)(_defineProperty(_defineProperty({
|
|
64
|
+
id: 'positionTargetContainer'
|
|
65
|
+
}, _container19.containerAttribute, 'positionTargetContainer'), "children", (0, _utils.join)((0, _utils.container)(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, _container19.containerAttribute, 'child'), "id", 'spottableDefault'), "className", 'spottable-default'), "children", (0, _utils.join)((0, _utils.spottable)({
|
|
66
|
+
id: 'firstChildSpottable'
|
|
67
|
+
})))))))
|
|
63
68
|
};
|
|
64
69
|
var setupContainers = function setupContainers() {
|
|
65
|
-
(0,
|
|
70
|
+
(0, _container19.configureDefaults)({
|
|
66
71
|
selector: '.spottable'
|
|
67
72
|
});
|
|
68
|
-
(0,
|
|
69
|
-
(0,
|
|
73
|
+
(0, _container19.configureContainer)(_container19.rootContainerId);
|
|
74
|
+
(0, _container19.setLastContainer)(_container19.rootContainerId);
|
|
70
75
|
};
|
|
71
76
|
var teardownContainers = function teardownContainers() {
|
|
72
77
|
// clean up any containers we create for safe tests
|
|
73
|
-
(0,
|
|
78
|
+
(0, _container19.removeAllContainers)();
|
|
74
79
|
};
|
|
75
80
|
describe('container', function () {
|
|
76
81
|
describe('#getSpottableDescendants', function () {
|
|
@@ -78,79 +83,79 @@ describe('container', function () {
|
|
|
78
83
|
afterEach(teardownContainers);
|
|
79
84
|
test('should find spottables', (0, _utils.testScenario)(scenarios.onlySpottables, function () {
|
|
80
85
|
var expected = 5;
|
|
81
|
-
var actual = (0,
|
|
86
|
+
var actual = (0, _container19.getSpottableDescendants)(_container19.rootContainerId).length;
|
|
82
87
|
expect(actual).toBe(expected);
|
|
83
88
|
}));
|
|
84
89
|
test('should find containers', (0, _utils.testScenario)(scenarios.onlyContainers, function () {
|
|
85
90
|
var expected = 5;
|
|
86
|
-
var actual = (0,
|
|
91
|
+
var actual = (0, _container19.getSpottableDescendants)(_container19.rootContainerId).length;
|
|
87
92
|
expect(actual).toBe(expected);
|
|
88
93
|
}));
|
|
89
94
|
test('should find spottables and containers', (0, _utils.testScenario)(scenarios.spottableAndContainers, function () {
|
|
90
95
|
var expected = 10;
|
|
91
|
-
var actual = (0,
|
|
96
|
+
var actual = (0, _container19.getSpottableDescendants)(_container19.rootContainerId).length;
|
|
92
97
|
expect(actual).toBe(expected);
|
|
93
98
|
}));
|
|
94
99
|
test('should only find spottables with non-spottable siblings', (0, _utils.testScenario)(scenarios.nonSpottableSiblings, function () {
|
|
95
100
|
var expected = 5;
|
|
96
|
-
var actual = (0,
|
|
101
|
+
var actual = (0, _container19.getSpottableDescendants)(_container19.rootContainerId).length;
|
|
97
102
|
expect(actual).toBe(expected);
|
|
98
103
|
}));
|
|
99
104
|
test('should only find top-level containers', (0, _utils.testScenario)(scenarios.nestedContainers, function () {
|
|
100
105
|
var expected = 1;
|
|
101
|
-
var actual = (0,
|
|
106
|
+
var actual = (0, _container19.getSpottableDescendants)(_container19.rootContainerId).length;
|
|
102
107
|
expect(actual).toBe(expected);
|
|
103
108
|
}));
|
|
104
109
|
test('should only find top-level containers and spottables', (0, _utils.testScenario)(scenarios.nestedContainersWithSpottables, function () {
|
|
105
110
|
var expected = 6;
|
|
106
|
-
var actual = (0,
|
|
111
|
+
var actual = (0, _container19.getSpottableDescendants)(_container19.rootContainerId).length;
|
|
107
112
|
expect(actual).toBe(expected);
|
|
108
113
|
}));
|
|
109
114
|
test('should not find spottables in sibling containers', (0, _utils.testScenario)(scenarios.siblingContainers, function () {
|
|
110
|
-
(0,
|
|
115
|
+
(0, _container19.configureContainer)('first');
|
|
111
116
|
var expected = 5;
|
|
112
|
-
var actual = (0,
|
|
117
|
+
var actual = (0, _container19.getSpottableDescendants)('first').length;
|
|
113
118
|
expect(actual).toBe(expected);
|
|
114
119
|
}));
|
|
115
120
|
test('should not find spottables in descendant containers', (0, _utils.testScenario)(scenarios.complexTree, function () {
|
|
116
|
-
(0,
|
|
121
|
+
(0, _container19.configureContainer)('first-container');
|
|
117
122
|
var expected = 3;
|
|
118
|
-
var actual = (0,
|
|
123
|
+
var actual = (0, _container19.getSpottableDescendants)('first-container').length;
|
|
119
124
|
expect(actual).toBe(expected);
|
|
120
125
|
}));
|
|
121
126
|
test('should not find containers that are disabled', (0, _utils.testScenario)(scenarios.complexTree, function () {
|
|
122
|
-
(0,
|
|
123
|
-
(0,
|
|
127
|
+
(0, _container19.configureContainer)('first-container');
|
|
128
|
+
(0, _container19.configureContainer)('second-container');
|
|
124
129
|
var expected = 3;
|
|
125
|
-
var actual = (0,
|
|
130
|
+
var actual = (0, _container19.getSpottableDescendants)('second-container').length;
|
|
126
131
|
expect(actual).toBe(expected);
|
|
127
132
|
}));
|
|
128
133
|
test('should not any spottables within a disabled container', (0, _utils.testScenario)(scenarios.spottablesInDisabledContainer, function () {
|
|
129
|
-
(0,
|
|
134
|
+
(0, _container19.configureContainer)('container');
|
|
130
135
|
var expected = 0;
|
|
131
|
-
var actual = (0,
|
|
136
|
+
var actual = (0, _container19.getSpottableDescendants)('container').length;
|
|
132
137
|
expect(actual).toBe(expected);
|
|
133
138
|
}));
|
|
134
139
|
test('should not any spottables within a disabled ancestor container', (0, _utils.testScenario)(scenarios.spottablesInNestedDisabledContainer, function () {
|
|
135
|
-
(0,
|
|
136
|
-
(0,
|
|
140
|
+
(0, _container19.configureContainer)('container');
|
|
141
|
+
(0, _container19.configureContainer)('child');
|
|
137
142
|
var expected = 0;
|
|
138
|
-
var actual = (0,
|
|
143
|
+
var actual = (0, _container19.getSpottableDescendants)('child').length;
|
|
139
144
|
expect(actual).toBe(expected);
|
|
140
145
|
}));
|
|
141
146
|
test('should return spottables and containers in source order', (0, _utils.testScenario)(scenarios.mixedOrder, function () {
|
|
142
147
|
var expected = ['c1', 's1', 'c2', 's2'];
|
|
143
|
-
var actual = (0,
|
|
148
|
+
var actual = (0, _container19.getSpottableDescendants)(_container19.rootContainerId).map(function (n) {
|
|
144
149
|
return n.getAttribute('name');
|
|
145
150
|
});
|
|
146
151
|
expect(actual).toEqual(expected);
|
|
147
152
|
}));
|
|
148
153
|
test('should include owned nodes', (0, _utils.testScenario)(scenarios.owned, function () {
|
|
149
|
-
(0,
|
|
154
|
+
(0, _container19.configureContainer)('container');
|
|
150
155
|
|
|
151
156
|
// owned nodes follow internal nodes
|
|
152
157
|
var expected = ['s2', 's1'];
|
|
153
|
-
var actual = (0,
|
|
158
|
+
var actual = (0, _container19.getSpottableDescendants)('container').map(function (n) {
|
|
154
159
|
return n.getAttribute('id');
|
|
155
160
|
});
|
|
156
161
|
expect(actual).toEqual(expected);
|
|
@@ -158,51 +163,51 @@ describe('container', function () {
|
|
|
158
163
|
});
|
|
159
164
|
describe('#getContainersForNode', function () {
|
|
160
165
|
test('should return the rootContainerId when no other containers exist', (0, _utils.testScenario)(scenarios.onlySpottables, function (root) {
|
|
161
|
-
var expected = [
|
|
162
|
-
var actual = (0,
|
|
166
|
+
var expected = [_container19.rootContainerId];
|
|
167
|
+
var actual = (0, _container19.getContainersForNode)(root.lastChild);
|
|
163
168
|
expect(actual).toEqual(expected);
|
|
164
169
|
}));
|
|
165
170
|
test('should return all ancestor container ids', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
|
|
166
171
|
var childOfThird = root.querySelector('#child-of-third');
|
|
167
|
-
var expected = [
|
|
168
|
-
var actual = (0,
|
|
172
|
+
var expected = [_container19.rootContainerId, 'first-container', 'second-container', 'third-container'];
|
|
173
|
+
var actual = (0, _container19.getContainersForNode)(childOfThird);
|
|
169
174
|
expect(actual).toEqual(expected);
|
|
170
175
|
}));
|
|
171
176
|
test('should return immediate container id as last in list', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
|
|
172
177
|
var childOfThird = root.querySelector('#child-of-third');
|
|
173
178
|
var expected = 'third-container';
|
|
174
|
-
var actual = (0,
|
|
179
|
+
var actual = (0, _container19.getContainersForNode)(childOfThird).pop();
|
|
175
180
|
expect(actual).toEqual(expected);
|
|
176
181
|
}));
|
|
177
182
|
});
|
|
178
183
|
describe('#isContainer', function () {
|
|
179
184
|
beforeEach(function () {
|
|
180
|
-
(0,
|
|
185
|
+
(0, _container19.configureContainer)('test-container');
|
|
181
186
|
});
|
|
182
187
|
afterEach(function () {
|
|
183
|
-
(0,
|
|
188
|
+
(0, _container19.removeContainer)('test-container');
|
|
184
189
|
});
|
|
185
190
|
test('should return true for nodes that have the container attribute', function () {
|
|
186
191
|
var div = document.createElement('div');
|
|
187
192
|
div.setAttribute('data-spotlight-container', 'my-container');
|
|
188
193
|
var expected = true;
|
|
189
|
-
var actual = (0,
|
|
194
|
+
var actual = (0, _container19.isContainer)(div);
|
|
190
195
|
expect(actual).toBe(expected);
|
|
191
196
|
});
|
|
192
197
|
test('should return false for nodes that do not have the container attribute', function () {
|
|
193
198
|
var div = document.createElement('div');
|
|
194
199
|
var expected = false;
|
|
195
|
-
var actual = (0,
|
|
200
|
+
var actual = (0, _container19.isContainer)(div);
|
|
196
201
|
expect(actual).toBe(expected);
|
|
197
202
|
});
|
|
198
203
|
test('should return true for a configured container id', function () {
|
|
199
204
|
var expected = true;
|
|
200
|
-
var actual = (0,
|
|
205
|
+
var actual = (0, _container19.isContainer)('test-container');
|
|
201
206
|
expect(actual).toBe(expected);
|
|
202
207
|
});
|
|
203
208
|
test('should return false for a unconfigured container id', function () {
|
|
204
209
|
var expected = false;
|
|
205
|
-
var actual = (0,
|
|
210
|
+
var actual = (0, _container19.isContainer)('unconfigured-container');
|
|
206
211
|
expect(actual).toBe(expected);
|
|
207
212
|
});
|
|
208
213
|
});
|
|
@@ -210,160 +215,160 @@ describe('container', function () {
|
|
|
210
215
|
beforeEach(setupContainers);
|
|
211
216
|
afterEach(teardownContainers);
|
|
212
217
|
test('should return the last focused element when enterTo is "last-focused"', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function (root) {
|
|
213
|
-
(0,
|
|
218
|
+
(0, _container19.configureContainer)('container', {
|
|
214
219
|
enterTo: 'last-focused',
|
|
215
220
|
defaultElement: '.spottable-default'
|
|
216
221
|
});
|
|
217
|
-
(0,
|
|
222
|
+
(0, _container19.setContainerLastFocusedElement)(root.querySelector('#lastFocused'), ['container']);
|
|
218
223
|
var expected = 'lastFocused';
|
|
219
|
-
var actual = (0,
|
|
224
|
+
var actual = (0, _container19.getContainerFocusTarget)('container').id;
|
|
220
225
|
expect(actual).toBe(expected);
|
|
221
226
|
}));
|
|
222
227
|
test('should return the default spottable element when enterTo is "last-focused" but no element has been focused', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function () {
|
|
223
|
-
(0,
|
|
228
|
+
(0, _container19.configureContainer)('container', {
|
|
224
229
|
enterTo: 'last-focused',
|
|
225
230
|
defaultElement: '.spottable-default'
|
|
226
231
|
});
|
|
227
232
|
var expected = 'spottableDefault';
|
|
228
|
-
var actual = (0,
|
|
233
|
+
var actual = (0, _container19.getContainerFocusTarget)('container').id;
|
|
229
234
|
expect(actual).toBe(expected);
|
|
230
235
|
}));
|
|
231
236
|
test('should return the first spottable element when enterTo is "last-focused" and defaultElement is not configured', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function () {
|
|
232
|
-
(0,
|
|
237
|
+
(0, _container19.configureContainer)('container', {
|
|
233
238
|
enterTo: 'last-focused'
|
|
234
239
|
});
|
|
235
240
|
var expected = 'firstSpottable';
|
|
236
|
-
var actual = (0,
|
|
241
|
+
var actual = (0, _container19.getContainerFocusTarget)('container').id;
|
|
237
242
|
expect(actual).toBe(expected);
|
|
238
243
|
}));
|
|
239
244
|
test('should return the first spottable element when enterTo is "last-focused" and defaultElement is not found', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function () {
|
|
240
|
-
(0,
|
|
245
|
+
(0, _container19.configureContainer)('container', {
|
|
241
246
|
enterTo: 'last-focused',
|
|
242
247
|
// configured, but not found
|
|
243
248
|
defaultElement: '[data-default-spottable]'
|
|
244
249
|
});
|
|
245
250
|
var expected = 'firstSpottable';
|
|
246
|
-
var actual = (0,
|
|
251
|
+
var actual = (0, _container19.getContainerFocusTarget)('container').id;
|
|
247
252
|
expect(actual).toBe(expected);
|
|
248
253
|
}));
|
|
249
254
|
test('should return the default spottable element when enterTo is "default-element"', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function () {
|
|
250
|
-
(0,
|
|
255
|
+
(0, _container19.configureContainer)('container', {
|
|
251
256
|
enterTo: 'default-element',
|
|
252
257
|
defaultElement: '.spottable-default'
|
|
253
258
|
});
|
|
254
259
|
var expected = 'spottableDefault';
|
|
255
|
-
var actual = (0,
|
|
260
|
+
var actual = (0, _container19.getContainerFocusTarget)('container').id;
|
|
256
261
|
expect(actual).toBe(expected);
|
|
257
262
|
}));
|
|
258
263
|
test('should return the default spottable element when enterTo is "default-element" and defaultElement contains an array of selectors', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function () {
|
|
259
|
-
(0,
|
|
264
|
+
(0, _container19.configureContainer)('container', {
|
|
260
265
|
enterTo: 'default-element',
|
|
261
266
|
defaultElement: ['.does-not-exist', '.spottable-default']
|
|
262
267
|
});
|
|
263
268
|
var expected = 'spottableDefault';
|
|
264
|
-
var actual = (0,
|
|
269
|
+
var actual = (0, _container19.getContainerFocusTarget)('container').id;
|
|
265
270
|
expect(actual).toBe(expected);
|
|
266
271
|
}));
|
|
267
272
|
|
|
268
273
|
// FIXME: This is testing a previously supported feature (setting a node as defaultElement)
|
|
269
274
|
// which was never documented and should be removed in a future release.
|
|
270
275
|
test('should return the default spottable element when enterTo is "default-element" and defaultElement contains an array of selectors wiht a node reference', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function (root) {
|
|
271
|
-
(0,
|
|
276
|
+
(0, _container19.configureContainer)('container', {
|
|
272
277
|
enterTo: 'default-element',
|
|
273
278
|
defaultElement: [root.querySelector('#lastFocused'), '.spottable-default']
|
|
274
279
|
});
|
|
275
280
|
var expected = 'lastFocused';
|
|
276
|
-
var actual = (0,
|
|
281
|
+
var actual = (0, _container19.getContainerFocusTarget)('container').id;
|
|
277
282
|
expect(actual).toBe(expected);
|
|
278
283
|
}));
|
|
279
284
|
test('should return the first spottable element when enterTo is "default-element" but defaultElement is not configured', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function () {
|
|
280
|
-
(0,
|
|
285
|
+
(0, _container19.configureContainer)('container', {
|
|
281
286
|
enterTo: 'default-element'
|
|
282
287
|
});
|
|
283
288
|
var expected = 'firstSpottable';
|
|
284
|
-
var actual = (0,
|
|
289
|
+
var actual = (0, _container19.getContainerFocusTarget)('container').id;
|
|
285
290
|
expect(actual).toBe(expected);
|
|
286
291
|
}));
|
|
287
292
|
test('should return the first spottable element when enterTo is "default-element" but defaultElement is not found', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function () {
|
|
288
|
-
(0,
|
|
293
|
+
(0, _container19.configureContainer)('container', {
|
|
289
294
|
enterTo: 'default-element',
|
|
290
295
|
defaultElement: '[data-default-spottable]'
|
|
291
296
|
});
|
|
292
297
|
var expected = 'firstSpottable';
|
|
293
|
-
var actual = (0,
|
|
298
|
+
var actual = (0, _container19.getContainerFocusTarget)('container').id;
|
|
294
299
|
expect(actual).toBe(expected);
|
|
295
300
|
}));
|
|
296
301
|
test('should return the default element when enterTo is "default-element" and defaultElement is within a subcontainer', (0, _utils.testScenario)(scenarios.complexTree, function () {
|
|
297
|
-
(0,
|
|
302
|
+
(0, _container19.configureContainer)('first-container', {
|
|
298
303
|
enterTo: 'default-element',
|
|
299
|
-
defaultElement: "[".concat(
|
|
304
|
+
defaultElement: "[".concat(_container19.containerAttribute, "='second-container'] > .spottable")
|
|
300
305
|
});
|
|
301
|
-
(0,
|
|
306
|
+
(0, _container19.configureContainer)('second-container');
|
|
302
307
|
var expected = 'second-container';
|
|
303
|
-
var actual = (0,
|
|
308
|
+
var actual = (0, _container19.getContainerFocusTarget)('first-container').parentNode.dataset.spotlightId;
|
|
304
309
|
expect(actual).toBe(expected);
|
|
305
310
|
}));
|
|
306
311
|
test('should return the first spottable element when enterTo is "default-element" and defaultElement is within a disabled subcontainer', (0, _utils.testScenario)(scenarios.complexTree, function () {
|
|
307
|
-
(0,
|
|
312
|
+
(0, _container19.configureContainer)('second-container', {
|
|
308
313
|
enterTo: 'default-element',
|
|
309
|
-
defaultElement: "[".concat(
|
|
314
|
+
defaultElement: "[".concat(_container19.containerAttribute, "='third-container'] > .spottable")
|
|
310
315
|
});
|
|
311
|
-
(0,
|
|
316
|
+
(0, _container19.configureContainer)('third-container');
|
|
312
317
|
var expected = 'secondContainerFirstSpottable';
|
|
313
|
-
var actual = (0,
|
|
318
|
+
var actual = (0, _container19.getContainerFocusTarget)('second-container').id;
|
|
314
319
|
expect(actual).toBe(expected);
|
|
315
320
|
}));
|
|
316
321
|
test('should return the first spottable element when enterTo is not configured', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function () {
|
|
317
|
-
(0,
|
|
322
|
+
(0, _container19.configureContainer)('container');
|
|
318
323
|
var expected = 'firstSpottable';
|
|
319
|
-
var actual = (0,
|
|
324
|
+
var actual = (0, _container19.getContainerFocusTarget)('container').id;
|
|
320
325
|
expect(actual).toBe(expected);
|
|
321
326
|
}));
|
|
322
327
|
test('should return the default element when enterTo is not configured and defaultElement is configured', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function () {
|
|
323
|
-
(0,
|
|
328
|
+
(0, _container19.configureContainer)('container', {
|
|
324
329
|
defaultElement: '.spottable-default'
|
|
325
330
|
});
|
|
326
331
|
var expected = 'spottableDefault';
|
|
327
|
-
var actual = (0,
|
|
332
|
+
var actual = (0, _container19.getContainerFocusTarget)('container').id;
|
|
328
333
|
expect(actual).toBe(expected);
|
|
329
334
|
}));
|
|
330
335
|
test('should cascade search into child containers with', (0, _utils.testScenario)(scenarios.nestedContainersWithDefaultAndLastFocused, function (root) {
|
|
331
|
-
(0,
|
|
336
|
+
(0, _container19.configureContainer)('container', {
|
|
332
337
|
defaultElement: '.spottable-default'
|
|
333
338
|
});
|
|
334
|
-
(0,
|
|
339
|
+
(0, _container19.configureContainer)('child', {
|
|
335
340
|
enterTo: 'last-focused',
|
|
336
341
|
defaultElement: '.spottable-default'
|
|
337
342
|
});
|
|
338
|
-
(0,
|
|
343
|
+
(0, _container19.setContainerLastFocusedElement)(root.querySelector('#lastChildFocused'), [_container19.rootContainerId, 'container', 'child']);
|
|
339
344
|
var expected = 'lastChildFocused';
|
|
340
|
-
var actual = (0,
|
|
345
|
+
var actual = (0, _container19.getContainerFocusTarget)('container').id;
|
|
341
346
|
expect(actual).toBe(expected);
|
|
342
347
|
}));
|
|
343
348
|
test('should cascade search into child containers when multiple containers have enterTo configured', (0, _utils.testScenario)(scenarios.nestedContainersWithDefaultAndLastFocused, function (root) {
|
|
344
|
-
(0,
|
|
349
|
+
(0, _container19.configureContainer)('container', {
|
|
345
350
|
enterTo: 'last-focused',
|
|
346
351
|
defaultElement: '.spottable-default'
|
|
347
352
|
});
|
|
348
|
-
(0,
|
|
353
|
+
(0, _container19.configureContainer)('child', {
|
|
349
354
|
enterTo: 'last-focused',
|
|
350
355
|
defaultElement: '.spottable-default'
|
|
351
356
|
});
|
|
352
|
-
(0,
|
|
357
|
+
(0, _container19.setContainerLastFocusedElement)(root.querySelector('#lastChildFocused'), [_container19.rootContainerId, 'container', 'child']);
|
|
353
358
|
var expected = 'lastChildFocused';
|
|
354
|
-
var actual = (0,
|
|
359
|
+
var actual = (0, _container19.getContainerFocusTarget)('container').id;
|
|
355
360
|
expect(actual).toBe(expected);
|
|
356
361
|
}));
|
|
357
362
|
test('should skip empty subcontainers', (0, _utils.testScenario)(scenarios.emptySubcontainer, function () {
|
|
358
|
-
(0,
|
|
359
|
-
(0,
|
|
363
|
+
(0, _container19.configureContainer)('container');
|
|
364
|
+
(0, _container19.configureContainer)('subcontainer');
|
|
360
365
|
var expected = 'afterSubcontainer';
|
|
361
|
-
var actual = (0,
|
|
366
|
+
var actual = (0, _container19.getContainerFocusTarget)('container').id;
|
|
362
367
|
expect(actual).toBe(expected);
|
|
363
368
|
}));
|
|
364
369
|
test('should return null for an unconfigured container', (0, _utils.testScenario)(scenarios.complexTree, function () {
|
|
365
370
|
var expected = null;
|
|
366
|
-
var actual = (0,
|
|
371
|
+
var actual = (0, _container19.getContainerFocusTarget)('first-container');
|
|
367
372
|
expect(actual).toBe(expected);
|
|
368
373
|
}));
|
|
369
374
|
});
|
|
@@ -372,33 +377,33 @@ describe('container', function () {
|
|
|
372
377
|
afterEach(teardownContainers);
|
|
373
378
|
test('should return false a null node', function () {
|
|
374
379
|
var expected = false;
|
|
375
|
-
var actual = (0,
|
|
380
|
+
var actual = (0, _container19.isNavigable)(null, _container19.rootContainerId);
|
|
376
381
|
expect(actual).toBe(expected);
|
|
377
382
|
});
|
|
378
383
|
test('should return true for any node when not verifying selector and without a navigableFilter', (0, _utils.testScenario)(scenarios.nonSpottableSiblings, function (root) {
|
|
379
384
|
var expected = true;
|
|
380
|
-
var actual = (0,
|
|
385
|
+
var actual = (0, _container19.isNavigable)(root.querySelector('.other'), _container19.rootContainerId);
|
|
381
386
|
expect(actual).toBe(expected);
|
|
382
387
|
}));
|
|
383
388
|
test('should return true for spottable children when verifying selector', (0, _utils.testScenario)(scenarios.onlySpottables, function (root) {
|
|
384
389
|
var expected = true;
|
|
385
|
-
var actual = (0,
|
|
390
|
+
var actual = (0, _container19.isNavigable)(root.querySelector('.spottable'), _container19.rootContainerId, true);
|
|
386
391
|
expect(actual).toBe(expected);
|
|
387
392
|
}));
|
|
388
393
|
test('should return true for containers', (0, _utils.testScenario)(scenarios.onlyContainers, function (root) {
|
|
389
394
|
var expected = true;
|
|
390
|
-
var actual = (0,
|
|
395
|
+
var actual = (0, _container19.isNavigable)(root.querySelector("[".concat(_container19.containerAttribute, "]")), _container19.rootContainerId, true);
|
|
391
396
|
expect(actual).toBe(expected);
|
|
392
397
|
}));
|
|
393
398
|
test('should filter the node with navigableFilter', (0, _utils.testScenario)(scenarios.spottableAndContainers, function (root) {
|
|
394
|
-
(0,
|
|
399
|
+
(0, _container19.configureContainer)(_container19.rootContainerId, {
|
|
395
400
|
// test filter which makes containers non-navigable
|
|
396
401
|
navigableFilter: function navigableFilter(n) {
|
|
397
|
-
return !(0,
|
|
402
|
+
return !(0, _container19.isContainer)(n);
|
|
398
403
|
}
|
|
399
404
|
});
|
|
400
405
|
var expected = false;
|
|
401
|
-
var actual = (0,
|
|
406
|
+
var actual = (0, _container19.isNavigable)(root.querySelector("[".concat(_container19.containerAttribute, "]")), _container19.rootContainerId, true);
|
|
402
407
|
expect(actual).toBe(expected);
|
|
403
408
|
}));
|
|
404
409
|
});
|
|
@@ -407,36 +412,36 @@ describe('container', function () {
|
|
|
407
412
|
afterEach(teardownContainers);
|
|
408
413
|
test('should update lastFocusedElement for a single container', (0, _utils.testScenario)(scenarios.onlySpottables, function (root) {
|
|
409
414
|
var item = root.querySelectorAll('.spottable').item(3);
|
|
410
|
-
(0,
|
|
415
|
+
(0, _container19.setContainerLastFocusedElement)(item, (0, _container19.getContainersForNode)(item));
|
|
411
416
|
var expected = item;
|
|
412
|
-
var actual = (0,
|
|
417
|
+
var actual = (0, _container19.getContainerConfig)(_container19.rootContainerId).lastFocusedElement;
|
|
413
418
|
expect(actual).toBe(expected);
|
|
414
419
|
}));
|
|
415
420
|
test('should update lastFocusedElement to the node\'s container id when element is within a container with enterTo configured', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
|
|
416
|
-
var item = root.querySelectorAll("[".concat(
|
|
417
|
-
(0,
|
|
421
|
+
var item = root.querySelectorAll("[".concat(_container19.containerAttribute, "='first-container'] .spottable")).item(0);
|
|
422
|
+
(0, _container19.configureContainer)('first-container', {
|
|
418
423
|
enterTo: 'last-focused'
|
|
419
424
|
});
|
|
420
|
-
(0,
|
|
425
|
+
(0, _container19.setContainerLastFocusedElement)(item, (0, _container19.getContainersForNode)(item));
|
|
421
426
|
var expected = 'first-container';
|
|
422
|
-
var actual = (0,
|
|
427
|
+
var actual = (0, _container19.getContainerConfig)(_container19.rootContainerId).lastFocusedElement;
|
|
423
428
|
expect(actual).toBe(expected);
|
|
424
429
|
}));
|
|
425
430
|
test('should ignore sub-containers that does not have enterTo configured', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
|
|
426
|
-
var item = root.querySelectorAll("[".concat(
|
|
427
|
-
(0,
|
|
431
|
+
var item = root.querySelectorAll("[".concat(_container19.containerAttribute, "='second-container'] .spottable")).item(0);
|
|
432
|
+
(0, _container19.setContainerLastFocusedElement)(item, (0, _container19.getContainersForNode)(item));
|
|
428
433
|
var expected = item;
|
|
429
|
-
var actual = (0,
|
|
434
|
+
var actual = (0, _container19.getContainerConfig)(_container19.rootContainerId).lastFocusedElement;
|
|
430
435
|
expect(actual).toBe(expected);
|
|
431
436
|
}));
|
|
432
437
|
test('should update lastFocusedElement to the first sub-container that has enterTo configured', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
|
|
433
|
-
var item = root.querySelectorAll("[".concat(
|
|
434
|
-
(0,
|
|
438
|
+
var item = root.querySelectorAll("[".concat(_container19.containerAttribute, "='second-container'] .spottable")).item(0);
|
|
439
|
+
(0, _container19.configureContainer)('second-container', {
|
|
435
440
|
enterTo: 'last-focused'
|
|
436
441
|
});
|
|
437
|
-
(0,
|
|
442
|
+
(0, _container19.setContainerLastFocusedElement)(item, (0, _container19.getContainersForNode)(item));
|
|
438
443
|
var expected = 'second-container';
|
|
439
|
-
var actual = (0,
|
|
444
|
+
var actual = (0, _container19.getContainerConfig)(_container19.rootContainerId).lastFocusedElement;
|
|
440
445
|
expect(actual).toBe(expected);
|
|
441
446
|
}));
|
|
442
447
|
});
|
|
@@ -446,36 +451,36 @@ describe('container', function () {
|
|
|
446
451
|
test('should return element when last focused is not within a subcontainer with enterTo', (0, _utils.testScenario)(scenarios.onlySpottables, function (root) {
|
|
447
452
|
var index = 3;
|
|
448
453
|
var item = root.querySelectorAll('.spottable').item(index);
|
|
449
|
-
(0,
|
|
450
|
-
(0,
|
|
454
|
+
(0, _container19.setContainerLastFocusedElement)(item, (0, _container19.getContainersForNode)(item));
|
|
455
|
+
(0, _container19.unmountContainer)(_container19.rootContainerId);
|
|
451
456
|
var expected = true;
|
|
452
|
-
var actual = (0,
|
|
457
|
+
var actual = (0, _container19.getContainerConfig)(_container19.rootContainerId).lastFocusedKey.element;
|
|
453
458
|
expect(actual).toBe(expected);
|
|
454
459
|
}));
|
|
455
460
|
test('should return container when last focused is within a subcontainer with enterTo', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
|
|
456
|
-
var item = root.querySelectorAll("[".concat(
|
|
457
|
-
(0,
|
|
461
|
+
var item = root.querySelectorAll("[".concat(_container19.containerAttribute, "=\"first-container\"] .spottable")).item(1);
|
|
462
|
+
(0, _container19.configureContainer)('first-container', {
|
|
458
463
|
enterTo: 'last-focused'
|
|
459
464
|
});
|
|
460
|
-
(0,
|
|
461
|
-
(0,
|
|
465
|
+
(0, _container19.setContainerLastFocusedElement)(item, (0, _container19.getContainersForNode)(item));
|
|
466
|
+
(0, _container19.unmountContainer)(_container19.rootContainerId);
|
|
462
467
|
var expected = true;
|
|
463
|
-
var actual = (0,
|
|
468
|
+
var actual = (0, _container19.getContainerConfig)(_container19.rootContainerId).lastFocusedKey.container;
|
|
464
469
|
expect(actual).toBe(expected);
|
|
465
470
|
}));
|
|
466
471
|
test('should save the index of the node when lastFocusedPersist is undefined', (0, _utils.testScenario)(scenarios.onlySpottables, function (root) {
|
|
467
472
|
var index = 3;
|
|
468
473
|
var item = root.querySelectorAll('.spottable').item(index);
|
|
469
|
-
(0,
|
|
470
|
-
(0,
|
|
474
|
+
(0, _container19.setContainerLastFocusedElement)(item, (0, _container19.getContainersForNode)(item));
|
|
475
|
+
(0, _container19.unmountContainer)(_container19.rootContainerId);
|
|
471
476
|
var expected = index;
|
|
472
|
-
var actual = (0,
|
|
477
|
+
var actual = (0, _container19.getContainerConfig)(_container19.rootContainerId).lastFocusedKey.key;
|
|
473
478
|
expect(actual).toBe(expected);
|
|
474
479
|
}));
|
|
475
480
|
test('should save a custom key for container-configured lastFocusedPersist', (0, _utils.testScenario)(scenarios.onlySpottables, function (root) {
|
|
476
481
|
var index = 3;
|
|
477
482
|
var item = root.querySelectorAll('.spottable').item(3);
|
|
478
|
-
(0,
|
|
483
|
+
(0, _container19.configureContainer)(_container19.rootContainerId, {
|
|
479
484
|
lastFocusedPersist: function lastFocusedPersist(n, all) {
|
|
480
485
|
return {
|
|
481
486
|
element: true,
|
|
@@ -483,36 +488,36 @@ describe('container', function () {
|
|
|
483
488
|
};
|
|
484
489
|
}
|
|
485
490
|
});
|
|
486
|
-
(0,
|
|
487
|
-
(0,
|
|
491
|
+
(0, _container19.setContainerLastFocusedElement)(item, (0, _container19.getContainersForNode)(item));
|
|
492
|
+
(0, _container19.unmountContainer)(_container19.rootContainerId);
|
|
488
493
|
var expected = "item-".concat(index);
|
|
489
|
-
var actual = (0,
|
|
494
|
+
var actual = (0, _container19.getContainerConfig)(_container19.rootContainerId).lastFocusedKey.key;
|
|
490
495
|
expect(actual).toBe(expected);
|
|
491
496
|
}));
|
|
492
497
|
test('should save the container id as the key when a container with enterTo configured had the last focused item', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
|
|
493
|
-
var item = root.querySelectorAll("[".concat(
|
|
494
|
-
(0,
|
|
498
|
+
var item = root.querySelectorAll("[".concat(_container19.containerAttribute, "=\"first-container\"] .spottable")).item(1);
|
|
499
|
+
(0, _container19.configureContainer)('first-container', {
|
|
495
500
|
enterTo: 'last-focused'
|
|
496
501
|
});
|
|
497
|
-
(0,
|
|
498
|
-
(0,
|
|
502
|
+
(0, _container19.setContainerLastFocusedElement)(item, (0, _container19.getContainersForNode)(item));
|
|
503
|
+
(0, _container19.unmountContainer)(_container19.rootContainerId);
|
|
499
504
|
var expected = 'first-container';
|
|
500
|
-
var actual = (0,
|
|
505
|
+
var actual = (0, _container19.getContainerConfig)(_container19.rootContainerId).lastFocusedKey.key;
|
|
501
506
|
expect(actual).toBe(expected);
|
|
502
507
|
}));
|
|
503
508
|
test('should save the index as the key when last focused item is only within containers without enterTo configured', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
|
|
504
|
-
var item = root.querySelectorAll("[".concat(
|
|
505
|
-
(0,
|
|
506
|
-
(0,
|
|
509
|
+
var item = root.querySelectorAll("[".concat(_container19.containerAttribute, "=\"second-container\"] .spottable")).item(1);
|
|
510
|
+
(0, _container19.setContainerLastFocusedElement)(item, (0, _container19.getContainersForNode)(item));
|
|
511
|
+
(0, _container19.unmountContainer)(_container19.rootContainerId);
|
|
507
512
|
var expected = 4;
|
|
508
|
-
var actual = (0,
|
|
513
|
+
var actual = (0, _container19.getContainerConfig)(_container19.rootContainerId).lastFocusedKey.key;
|
|
509
514
|
expect(actual).toBe(expected);
|
|
510
515
|
}));
|
|
511
516
|
test('should mark the container inactive', (0, _utils.testScenario)(scenarios.complexTree, function () {
|
|
512
|
-
(0,
|
|
513
|
-
(0,
|
|
517
|
+
(0, _container19.addContainer)('first-container');
|
|
518
|
+
(0, _container19.unmountContainer)('first-container');
|
|
514
519
|
var expected = false;
|
|
515
|
-
var actual = (0,
|
|
520
|
+
var actual = (0, _container19.getContainerConfig)('first-container').active;
|
|
516
521
|
expect(actual).toBe(expected);
|
|
517
522
|
}));
|
|
518
523
|
});
|
|
@@ -520,42 +525,42 @@ describe('container', function () {
|
|
|
520
525
|
beforeEach(setupContainers);
|
|
521
526
|
afterEach(teardownContainers);
|
|
522
527
|
test('should be nearest restrict="self-only" container to current if target is not within it', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
|
|
523
|
-
(0,
|
|
528
|
+
(0, _container19.configureContainer)('first-container', {
|
|
524
529
|
restrict: 'self-only'
|
|
525
530
|
});
|
|
526
531
|
var current = root.querySelector('[data-spotlight-id="first-container"] .spottable');
|
|
527
532
|
var target = root.querySelector('.spottable');
|
|
528
|
-
(0,
|
|
533
|
+
(0, _container19.setLastContainerFromTarget)(current, target);
|
|
529
534
|
var expected = 'first-container';
|
|
530
|
-
var actual = (0,
|
|
535
|
+
var actual = (0, _container19.getLastContainer)();
|
|
531
536
|
expect(actual).toBe(expected);
|
|
532
537
|
}));
|
|
533
538
|
test('should be use nearest container to target if within current container', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
|
|
534
|
-
(0,
|
|
539
|
+
(0, _container19.configureContainer)('first-container', {
|
|
535
540
|
restrict: 'none'
|
|
536
541
|
});
|
|
537
|
-
(0,
|
|
542
|
+
(0, _container19.configureContainer)('second-container', {
|
|
538
543
|
restrict: 'none'
|
|
539
544
|
});
|
|
540
545
|
var current = root.querySelector('[data-spotlight-id="first-container"] .spottable');
|
|
541
546
|
var target = root.querySelector('[data-spotlight-id="second-container"] .spottable');
|
|
542
|
-
(0,
|
|
547
|
+
(0, _container19.setLastContainerFromTarget)(current, target);
|
|
543
548
|
var expected = 'second-container';
|
|
544
|
-
var actual = (0,
|
|
549
|
+
var actual = (0, _container19.getLastContainer)();
|
|
545
550
|
expect(actual).toBe(expected);
|
|
546
551
|
}));
|
|
547
552
|
test('should target container if it is restrict="self-only" and contains current container', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
|
|
548
|
-
(0,
|
|
553
|
+
(0, _container19.configureContainer)('first-container', {
|
|
549
554
|
restrict: 'self-only'
|
|
550
555
|
});
|
|
551
|
-
(0,
|
|
556
|
+
(0, _container19.configureContainer)('second-container', {
|
|
552
557
|
restrict: 'none'
|
|
553
558
|
});
|
|
554
559
|
var current = root.querySelector('[data-spotlight-id="second-container"] .spottable');
|
|
555
560
|
var target = root.querySelector('[data-spotlight-id="first-container"]');
|
|
556
|
-
(0,
|
|
561
|
+
(0, _container19.setLastContainerFromTarget)(current, target);
|
|
557
562
|
var expected = 'first-container';
|
|
558
|
-
var actual = (0,
|
|
563
|
+
var actual = (0, _container19.getLastContainer)();
|
|
559
564
|
expect(actual).toBe(expected);
|
|
560
565
|
}));
|
|
561
566
|
});
|
|
@@ -563,9 +568,9 @@ describe('container', function () {
|
|
|
563
568
|
beforeEach(setupContainers);
|
|
564
569
|
afterEach(teardownContainers);
|
|
565
570
|
test('should return an empty string when container is inactive', (0, _utils.testScenario)(scenarios.complexTree, function () {
|
|
566
|
-
(0,
|
|
571
|
+
(0, _container19.unmountContainer)(_container19.rootContainerId);
|
|
567
572
|
var expected = '';
|
|
568
|
-
var actual = (0,
|
|
573
|
+
var actual = (0, _container19.getDefaultContainer)();
|
|
569
574
|
expect(actual).toBe(expected);
|
|
570
575
|
}));
|
|
571
576
|
});
|
|
@@ -573,11 +578,11 @@ describe('container', function () {
|
|
|
573
578
|
beforeEach(setupContainers);
|
|
574
579
|
afterEach(teardownContainers);
|
|
575
580
|
test('should return an empty string when container is inactive', (0, _utils.testScenario)(scenarios.complexTree, function () {
|
|
576
|
-
(0,
|
|
577
|
-
(0,
|
|
578
|
-
(0,
|
|
581
|
+
(0, _container19.addContainer)('first-container');
|
|
582
|
+
(0, _container19.setLastContainer)('first-container');
|
|
583
|
+
(0, _container19.unmountContainer)('first-container');
|
|
579
584
|
var expected = '';
|
|
580
|
-
var actual = (0,
|
|
585
|
+
var actual = (0, _container19.getLastContainer)();
|
|
581
586
|
expect(actual).toBe(expected);
|
|
582
587
|
}));
|
|
583
588
|
});
|
|
@@ -586,10 +591,10 @@ describe('container', function () {
|
|
|
586
591
|
afterEach(teardownContainers);
|
|
587
592
|
test('should not include inacive containers', (0, _utils.testScenario)(scenarios.onlyContainers, function (root) {
|
|
588
593
|
var containerId = root.querySelector('[data-spotlight-id]').dataset.containerId;
|
|
589
|
-
(0,
|
|
590
|
-
(0,
|
|
594
|
+
(0, _container19.addContainer)(containerId);
|
|
595
|
+
(0, _container19.unmountContainer)(containerId);
|
|
591
596
|
var expected = -1;
|
|
592
|
-
var actual = (0,
|
|
597
|
+
var actual = (0, _container19.getAllContainerIds)().indexOf(containerId);
|
|
593
598
|
expect(actual).toBe(expected);
|
|
594
599
|
}));
|
|
595
600
|
});
|
|
@@ -598,7 +603,7 @@ describe('container', function () {
|
|
|
598
603
|
afterEach(teardownContainers);
|
|
599
604
|
test('should return null for an invalid container', (0, _utils.testScenario)(scenarios.onlySpottables, function () {
|
|
600
605
|
var expected = null;
|
|
601
|
-
var actual = (0,
|
|
606
|
+
var actual = (0, _container19.getContainerLastFocusedElement)('does-not-exist');
|
|
602
607
|
expect(actual).toBe(expected);
|
|
603
608
|
}));
|
|
604
609
|
});
|
|
@@ -607,7 +612,7 @@ describe('container', function () {
|
|
|
607
612
|
afterEach(teardownContainers);
|
|
608
613
|
test('should return null for an invalid container', (0, _utils.testScenario)(scenarios.onlySpottables, function () {
|
|
609
614
|
var expected = null;
|
|
610
|
-
var actual = (0,
|
|
615
|
+
var actual = (0, _container19.getContainerDefaultElement)('does-not-exist');
|
|
611
616
|
expect(actual).toBe(expected);
|
|
612
617
|
}));
|
|
613
618
|
});
|
|
@@ -615,16 +620,16 @@ describe('container', function () {
|
|
|
615
620
|
beforeEach(setupContainers);
|
|
616
621
|
afterEach(teardownContainers);
|
|
617
622
|
test('should include all containers when none are restrict="self-only"', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
|
|
618
|
-
var expected = [
|
|
619
|
-
var actual = (0,
|
|
623
|
+
var expected = [_container19.rootContainerId, 'first-container', 'second-container'];
|
|
624
|
+
var actual = (0, _container19.getNavigableContainersForNode)(root.querySelector('#secondContainerFirstSpottable'));
|
|
620
625
|
expect(actual).toEqual(expected);
|
|
621
626
|
}));
|
|
622
627
|
test('should include all containers within the first restrict="self-only" container (inclusive)', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
|
|
623
|
-
(0,
|
|
628
|
+
(0, _container19.configureContainer)('first-container', {
|
|
624
629
|
restrict: 'self-only'
|
|
625
630
|
});
|
|
626
631
|
var expected = ['first-container', 'second-container'];
|
|
627
|
-
var actual = (0,
|
|
632
|
+
var actual = (0, _container19.getNavigableContainersForNode)(root.querySelector('#secondContainerFirstSpottable'));
|
|
628
633
|
expect(actual).toEqual(expected);
|
|
629
634
|
}));
|
|
630
635
|
});
|
|
@@ -633,15 +638,30 @@ describe('container', function () {
|
|
|
633
638
|
afterEach(teardownContainers);
|
|
634
639
|
test('should return an empty array for an unconfigured container', (0, _utils.testScenario)(scenarios.complexTree, function () {
|
|
635
640
|
var expected = [];
|
|
636
|
-
var actual = (0,
|
|
641
|
+
var actual = (0, _container19.getContainerNavigableElements)('first-container');
|
|
637
642
|
expect(actual).toEqual(expected);
|
|
638
643
|
}));
|
|
639
644
|
test('should return an empty array for an unmounted, configured container', (0, _utils.testScenario)(scenarios.onlySpottables, function () {
|
|
640
|
-
(0,
|
|
645
|
+
(0, _container19.configureContainer)('first-container', {
|
|
641
646
|
overflow: true
|
|
642
647
|
});
|
|
643
648
|
var expected = [];
|
|
644
|
-
var actual = (0,
|
|
649
|
+
var actual = (0, _container19.getContainerNavigableElements)('first-container');
|
|
650
|
+
expect(actual).toEqual(expected);
|
|
651
|
+
}));
|
|
652
|
+
});
|
|
653
|
+
describe('#getPositionTargetOnFocus', function () {
|
|
654
|
+
beforeEach(setupContainers);
|
|
655
|
+
afterEach(teardownContainers);
|
|
656
|
+
test('should return a container that has positionTargetOnFocus configured', (0, _utils.testScenario)(scenarios.positionTargetOnFocusContainer, function (root) {
|
|
657
|
+
(0, _container19.configureContainer)('positionTargetContainer', {
|
|
658
|
+
positionTargetOnFocus: true
|
|
659
|
+
});
|
|
660
|
+
(0, _container19.configureContainer)('child', {
|
|
661
|
+
enterTo: 'last-focused'
|
|
662
|
+
});
|
|
663
|
+
var expected = root.querySelector('#positionTargetContainer');
|
|
664
|
+
var actual = (0, _container19.getPositionTargetOnFocus)(root.querySelector('#firstChildSpottable'));
|
|
645
665
|
expect(actual).toEqual(expected);
|
|
646
666
|
}));
|
|
647
667
|
});
|
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
var _inputType = require("../inputType");
|
|
4
4
|
describe('inputType', function () {
|
|
5
|
+
test('should have a default input type as \'key\'', function () {
|
|
6
|
+
var expected = 'key';
|
|
7
|
+
var actual = (0, _inputType.getInputType)();
|
|
8
|
+
expect(actual).toBe(expected);
|
|
9
|
+
});
|
|
10
|
+
test('should ignore input type in internal variable when invalid type is set', function () {
|
|
11
|
+
(0, _inputType.setInputType)('none');
|
|
12
|
+
var expected = 'key';
|
|
13
|
+
var actual = (0, _inputType.getInputType)();
|
|
14
|
+
expect(actual).toBe(expected);
|
|
15
|
+
});
|
|
5
16
|
test('should set input type properly in internal variable', function () {
|
|
6
17
|
(0, _inputType.setInputType)('touch');
|
|
7
18
|
var expected = 'touch';
|
package/src/tests/utils-specs.js
CHANGED
|
@@ -37,6 +37,82 @@ var scenarios = {
|
|
|
37
37
|
})
|
|
38
38
|
};
|
|
39
39
|
describe('utils', function () {
|
|
40
|
+
describe('#getIntersectionRect', function () {
|
|
41
|
+
test('should return the intersection rect between two given rects', function () {
|
|
42
|
+
var rect1 = {
|
|
43
|
+
getBoundingClientRect: function getBoundingClientRect() {
|
|
44
|
+
return {
|
|
45
|
+
left: 0,
|
|
46
|
+
top: 0,
|
|
47
|
+
width: 100,
|
|
48
|
+
height: 100
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var rect2 = {
|
|
53
|
+
getBoundingClientRect: function getBoundingClientRect() {
|
|
54
|
+
return {
|
|
55
|
+
left: 50,
|
|
56
|
+
top: 50,
|
|
57
|
+
width: 100,
|
|
58
|
+
height: 100
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var expected = {
|
|
63
|
+
left: 50,
|
|
64
|
+
top: 50,
|
|
65
|
+
width: 50,
|
|
66
|
+
height: 50,
|
|
67
|
+
right: 100,
|
|
68
|
+
bottom: 100,
|
|
69
|
+
center: {
|
|
70
|
+
x: 75,
|
|
71
|
+
y: 75,
|
|
72
|
+
left: 75,
|
|
73
|
+
right: 75,
|
|
74
|
+
top: 75,
|
|
75
|
+
bottom: 75
|
|
76
|
+
},
|
|
77
|
+
element: rect2
|
|
78
|
+
};
|
|
79
|
+
var actual = (0, _utils.getIntersectionRect)(rect1, rect2);
|
|
80
|
+
expect(actual).toEqual(expected);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
describe('#getRect', function () {
|
|
84
|
+
test('should return the rect value calculated based on the given element', function () {
|
|
85
|
+
var element = {
|
|
86
|
+
getBoundingClientRect: function getBoundingClientRect() {
|
|
87
|
+
return {
|
|
88
|
+
left: 10,
|
|
89
|
+
top: 20,
|
|
90
|
+
width: 100,
|
|
91
|
+
height: 200
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
var expected = {
|
|
96
|
+
left: 10,
|
|
97
|
+
top: 20,
|
|
98
|
+
width: 100,
|
|
99
|
+
height: 200,
|
|
100
|
+
right: 110,
|
|
101
|
+
bottom: 220,
|
|
102
|
+
center: {
|
|
103
|
+
x: 60,
|
|
104
|
+
y: 120,
|
|
105
|
+
left: 60,
|
|
106
|
+
right: 60,
|
|
107
|
+
top: 120,
|
|
108
|
+
bottom: 120
|
|
109
|
+
},
|
|
110
|
+
element: element
|
|
111
|
+
};
|
|
112
|
+
var actual = (0, _utils.getRect)(element);
|
|
113
|
+
expect(actual).toEqual(expected);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
40
116
|
describe('#getPointRect', function () {
|
|
41
117
|
test('should return an rect value calculated based on given position', function () {
|
|
42
118
|
var expected = {
|
package/src/utils.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.contains = void 0;
|
|
7
7
|
exports.getContainerRect = getContainerRect;
|
|
8
|
+
exports.getIntersectionRect = getIntersectionRect;
|
|
8
9
|
exports.getPointRect = getPointRect;
|
|
9
10
|
exports.getRect = getRect;
|
|
10
11
|
exports.getRects = getRects;
|
|
@@ -81,6 +82,34 @@ var intersects = exports.intersects = (0, _curry["default"])(function (container
|
|
|
81
82
|
var contains = exports.contains = (0, _curry["default"])(function (containerRect, elementRect) {
|
|
82
83
|
return testIntersection('contains', containerRect, elementRect);
|
|
83
84
|
});
|
|
85
|
+
function getIntersectionRect(container, element) {
|
|
86
|
+
var _container$getBoundin = container.getBoundingClientRect(),
|
|
87
|
+
L = _container$getBoundin.left,
|
|
88
|
+
T = _container$getBoundin.top,
|
|
89
|
+
W = _container$getBoundin.width,
|
|
90
|
+
H = _container$getBoundin.height;
|
|
91
|
+
var _element$getBoundingC = element.getBoundingClientRect(),
|
|
92
|
+
l = _element$getBoundingC.left,
|
|
93
|
+
t = _element$getBoundingC.top,
|
|
94
|
+
w = _element$getBoundingC.width,
|
|
95
|
+
h = _element$getBoundingC.height;
|
|
96
|
+
var intersectionRect = {
|
|
97
|
+
element: element,
|
|
98
|
+
left: Math.max(l, L),
|
|
99
|
+
right: Math.min(l + w, L + W),
|
|
100
|
+
top: Math.max(t, T),
|
|
101
|
+
bottom: Math.min(t + h, T + H)
|
|
102
|
+
};
|
|
103
|
+
intersectionRect.width = intersectionRect.right - intersectionRect.left;
|
|
104
|
+
intersectionRect.height = intersectionRect.bottom - intersectionRect.top;
|
|
105
|
+
intersectionRect.center = {
|
|
106
|
+
x: intersectionRect.left + Math.floor(intersectionRect.width / 2),
|
|
107
|
+
y: intersectionRect.top + Math.floor(intersectionRect.height / 2)
|
|
108
|
+
};
|
|
109
|
+
intersectionRect.center.left = intersectionRect.center.right = intersectionRect.center.x;
|
|
110
|
+
intersectionRect.center.top = intersectionRect.center.bottom = intersectionRect.center.y;
|
|
111
|
+
return intersectionRect;
|
|
112
|
+
}
|
|
84
113
|
function getRect(elem) {
|
|
85
114
|
var cr = elem.getBoundingClientRect();
|
|
86
115
|
var rect = {
|