@sprinklrjs/spaceweb 14.16.0 → 14.16.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/avatar/avatar.js +3 -3
- package/baseui/datepicker/day.js +21 -8
- package/date-input/DateInput.js +3 -0
- package/esm/avatar/avatar.js +3 -3
- package/esm/baseui/datepicker/day.js +21 -8
- package/esm/date-input/DateInput.js +3 -0
- package/esm/select/styled-component.js +1 -3
- package/esm/test-utils/keyboard/focusLock.d.ts +19 -0
- package/esm/test-utils/keyboard/focusLock.js +31 -0
- package/esm/test-utils/keyboard/index.d.ts +15 -0
- package/esm/test-utils/keyboard/index.js +15 -0
- package/esm/test-utils/keyboard/patterns.d.ts +63 -0
- package/esm/test-utils/keyboard/patterns.js +178 -0
- package/esm/test-utils/keyboard/press.d.ts +12 -0
- package/esm/test-utils/keyboard/press.js +22 -0
- package/esm/time-range-picker/RangeSelector.js +2 -2
- package/esm/time-range-picker/RangeSelectorContainer.js +1 -1
- package/package.json +12 -2
- package/select/styled-component.js +1 -3
- package/test-utils/keyboard/focusLock.d.ts +19 -0
- package/test-utils/keyboard/focusLock.js +35 -0
- package/test-utils/keyboard/index.d.ts +15 -0
- package/test-utils/keyboard/index.js +27 -0
- package/test-utils/keyboard/patterns.d.ts +63 -0
- package/test-utils/keyboard/patterns.js +185 -0
- package/test-utils/keyboard/press.d.ts +12 -0
- package/test-utils/keyboard/press.js +30 -0
- package/time-range-picker/RangeSelector.js +2 -2
- package/time-range-picker/RangeSelectorContainer.js +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sprinklrjs/spaceweb",
|
|
3
|
-
"version": "14.16.
|
|
3
|
+
"version": "14.16.2",
|
|
4
4
|
"description": "Components for SpaceWeb",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -100,8 +100,18 @@
|
|
|
100
100
|
"typescript": "~5.0.0"
|
|
101
101
|
},
|
|
102
102
|
"peerDependencies": {
|
|
103
|
-
"@sprinklrjs/spaceweb-themes": "14.16.
|
|
103
|
+
"@sprinklrjs/spaceweb-themes": "14.16.2",
|
|
104
|
+
"@testing-library/react": "^14.0.0",
|
|
105
|
+
"@testing-library/user-event": "^13.2.1",
|
|
104
106
|
"react": ">=17.0.2 <19.0.0",
|
|
105
107
|
"react-dom": ">=17.0.2 <19.0.0"
|
|
108
|
+
},
|
|
109
|
+
"peerDependenciesMeta": {
|
|
110
|
+
"@testing-library/react": {
|
|
111
|
+
"optional": true
|
|
112
|
+
},
|
|
113
|
+
"@testing-library/user-event": {
|
|
114
|
+
"optional": true
|
|
115
|
+
}
|
|
106
116
|
}
|
|
107
117
|
}
|
|
@@ -79,9 +79,7 @@ var InputContainer = function (_a) {
|
|
|
79
79
|
var ariaDescribedBy = commaSeparatedValues ? "".concat(selectedValuesId, " ").concat(baseAriaDescribedBy) : baseAriaDescribedBy;
|
|
80
80
|
var containerRef = (0, react_1.useRef)(null);
|
|
81
81
|
if (!props.$searchable) {
|
|
82
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [commaSeparatedValues ? ((0, jsx_runtime_1.jsx)(hidden_element_1.HiddenElement, tslib_1.__assign({ id: selectedValuesId }, { children: "".concat(commaSeparatedValues, " ").concat(props.$multi ? locale.select.multiValueNavigationDescription : '') }))) : null, (0, jsx_runtime_1.jsx)(exports.StyledInputContainer, tslib_1.__assign({}, props, { "$selectSize": size, "aria-controls": props.$isOpen ? listboxId : undefined, "aria-owns": props.$isOpen ? listboxId : null, "aria-describedby": ariaDescribedBy, "aria-expanded": props.$isOpen, "aria-autocomplete": "list", role: "combobox", ref: containerRef },
|
|
83
|
-
? {}
|
|
84
|
-
: { 'aria-placeholder': placeholder !== null && placeholder !== void 0 ? placeholder : locale.select.selectPlaceholder }), { "aria-haspopup": "listbox" }, { children: props.children
|
|
82
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [commaSeparatedValues ? ((0, jsx_runtime_1.jsx)(hidden_element_1.HiddenElement, tslib_1.__assign({ id: selectedValuesId }, { children: "".concat(commaSeparatedValues, " ").concat(props.$multi ? locale.select.multiValueNavigationDescription : '') }))) : null, (0, jsx_runtime_1.jsx)(exports.StyledInputContainer, tslib_1.__assign({}, props, { "$selectSize": size, "aria-controls": props.$isOpen ? listboxId : undefined, "aria-owns": props.$isOpen ? listboxId : null, "aria-describedby": ariaDescribedBy, "aria-expanded": props.$isOpen, "aria-autocomplete": "list", role: "combobox", ref: containerRef, "aria-haspopup": "listbox" }, { children: props.children
|
|
85
83
|
? (0, react_1.cloneElement)(react_1.Children.only(props.children), tslib_1.__assign({ onFocus: function () { var _a; return (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.focus(); } }, ($value && $value.length > 0 ? {} : { placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : locale.select.selectPlaceholder })))
|
|
86
84
|
: null }))] }));
|
|
87
85
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects a focus trap between two controls.
|
|
3
|
+
*
|
|
4
|
+
* Moves focus. Tab from `last` must land on `first`, and Shift+Tab from `first`
|
|
5
|
+
* must land on `last`. Render the dialog or popover first, then pass the
|
|
6
|
+
* focusable ends inside it.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { isFocusLocked } from '@sprinklrjs/spaceweb/test-utils/keyboard';
|
|
10
|
+
*
|
|
11
|
+
* expect(isFocusLocked({ first, last })).toBe(true);
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Test-only. Requires `@testing-library/user-event` v13 and `@testing-library/react`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isFocusLocked(ends: {
|
|
17
|
+
first: HTMLElement;
|
|
18
|
+
last: HTMLElement;
|
|
19
|
+
}): boolean;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isFocusLocked = void 0;
|
|
4
|
+
var react_1 = require("@testing-library/react");
|
|
5
|
+
var press_1 = require("./press");
|
|
6
|
+
/**
|
|
7
|
+
* Detects a focus trap between two controls.
|
|
8
|
+
*
|
|
9
|
+
* Moves focus. Tab from `last` must land on `first`, and Shift+Tab from `first`
|
|
10
|
+
* must land on `last`. Render the dialog or popover first, then pass the
|
|
11
|
+
* focusable ends inside it.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { isFocusLocked } from '@sprinklrjs/spaceweb/test-utils/keyboard';
|
|
15
|
+
*
|
|
16
|
+
* expect(isFocusLocked({ first, last })).toBe(true);
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Test-only. Requires `@testing-library/user-event` v13 and `@testing-library/react`.
|
|
20
|
+
*/
|
|
21
|
+
function isFocusLocked(ends) {
|
|
22
|
+
var first = ends.first, last = ends.last;
|
|
23
|
+
(0, react_1.act)(function () {
|
|
24
|
+
last.focus();
|
|
25
|
+
});
|
|
26
|
+
(0, press_1.tab)();
|
|
27
|
+
var wrapsForward = document.activeElement === first;
|
|
28
|
+
(0, react_1.act)(function () {
|
|
29
|
+
first.focus();
|
|
30
|
+
});
|
|
31
|
+
(0, press_1.shiftTab)();
|
|
32
|
+
var wrapsBackward = document.activeElement === last;
|
|
33
|
+
return wrapsForward && wrapsBackward;
|
|
34
|
+
}
|
|
35
|
+
exports.isFocusLocked = isFocusLocked;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test-only keyboard helpers for Jest.
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* import { isFocusLocked, press, tab } from '@sprinklrjs/spaceweb/test-utils/keyboard';
|
|
6
|
+
* ```
|
|
7
|
+
*
|
|
8
|
+
* Requires `@testing-library/user-event` v13 and `@testing-library/react`.
|
|
9
|
+
* The `describe*` suites also need `@testing-library/jest-dom` (`toHaveFocus`, `toBeChecked`).
|
|
10
|
+
* Dialog and radio suites assume the fixture names in their JSDoc (a button named
|
|
11
|
+
* `Second`, a button named `After`). Do not import this from application code.
|
|
12
|
+
*/
|
|
13
|
+
export { isFocusLocked } from './focusLock';
|
|
14
|
+
export { press, shiftTab, tab, type, type KeyboardKey } from './press';
|
|
15
|
+
export { describeDialogKeyboard, describeRadioGroupKeyboard, describeRovingKeyboard, describeToggleKeyboard, } from './patterns';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.describeToggleKeyboard = exports.describeRovingKeyboard = exports.describeRadioGroupKeyboard = exports.describeDialogKeyboard = exports.type = exports.tab = exports.shiftTab = exports.press = exports.isFocusLocked = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Test-only keyboard helpers for Jest.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { isFocusLocked, press, tab } from '@sprinklrjs/spaceweb/test-utils/keyboard';
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Requires `@testing-library/user-event` v13 and `@testing-library/react`.
|
|
12
|
+
* The `describe*` suites also need `@testing-library/jest-dom` (`toHaveFocus`, `toBeChecked`).
|
|
13
|
+
* Dialog and radio suites assume the fixture names in their JSDoc (a button named
|
|
14
|
+
* `Second`, a button named `After`). Do not import this from application code.
|
|
15
|
+
*/
|
|
16
|
+
var focusLock_1 = require("./focusLock");
|
|
17
|
+
Object.defineProperty(exports, "isFocusLocked", { enumerable: true, get: function () { return focusLock_1.isFocusLocked; } });
|
|
18
|
+
var press_1 = require("./press");
|
|
19
|
+
Object.defineProperty(exports, "press", { enumerable: true, get: function () { return press_1.press; } });
|
|
20
|
+
Object.defineProperty(exports, "shiftTab", { enumerable: true, get: function () { return press_1.shiftTab; } });
|
|
21
|
+
Object.defineProperty(exports, "tab", { enumerable: true, get: function () { return press_1.tab; } });
|
|
22
|
+
Object.defineProperty(exports, "type", { enumerable: true, get: function () { return press_1.type; } });
|
|
23
|
+
var patterns_1 = require("./patterns");
|
|
24
|
+
Object.defineProperty(exports, "describeDialogKeyboard", { enumerable: true, get: function () { return patterns_1.describeDialogKeyboard; } });
|
|
25
|
+
Object.defineProperty(exports, "describeRadioGroupKeyboard", { enumerable: true, get: function () { return patterns_1.describeRadioGroupKeyboard; } });
|
|
26
|
+
Object.defineProperty(exports, "describeRovingKeyboard", { enumerable: true, get: function () { return patterns_1.describeRovingKeyboard; } });
|
|
27
|
+
Object.defineProperty(exports, "describeToggleKeyboard", { enumerable: true, get: function () { return patterns_1.describeToggleKeyboard; } });
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type KeyboardKey } from './press';
|
|
2
|
+
/**
|
|
3
|
+
* Shared keyboard contracts for Spaceweb.
|
|
4
|
+
*
|
|
5
|
+
* Add a `describe*` function when a new interactive component shares a contract
|
|
6
|
+
* other components will reuse (menu, listbox, combobox, slider). Call it from
|
|
7
|
+
* that component's spec, inside `describe('keyboard interaction')`. Keep one-off branches in the component file.
|
|
8
|
+
* These tests press keys only — no click or hover.
|
|
9
|
+
*
|
|
10
|
+
* | Pattern | Keys | Components |
|
|
11
|
+
* | toggle | Tab, Space, Enter does not toggle | Checkbox, Switch |
|
|
12
|
+
* | radio | Tab lands on the active radio, Space selects, arrows move within the group | RadioGroup |
|
|
13
|
+
* | roving | next/previous, wrap, Home, End | Tabs. ButtonGroup uses the same hook |
|
|
14
|
+
* | dialog | Escape, Tab trap, focus return | Modal |
|
|
15
|
+
*/
|
|
16
|
+
type RenderFn = () => void;
|
|
17
|
+
export declare function describeToggleKeyboard(options: {
|
|
18
|
+
role: 'checkbox' | 'switch';
|
|
19
|
+
/** Renders one unchecked, enabled control. Space must check it. */
|
|
20
|
+
renderEnabled: RenderFn;
|
|
21
|
+
/** Renders one unchecked, disabled control. Space must not check it. */
|
|
22
|
+
renderDisabled: RenderFn;
|
|
23
|
+
}): void;
|
|
24
|
+
export declare function describeRadioGroupKeyboard(options: {
|
|
25
|
+
/** Renders Apple and Pear. `value` selects one. Include a button named After after the group. */
|
|
26
|
+
renderGroup: (props?: {
|
|
27
|
+
value?: string;
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
}) => void;
|
|
30
|
+
}): void;
|
|
31
|
+
/**
|
|
32
|
+
* Roving focus across `setup()` stops. The first stop is the tab entry.
|
|
33
|
+
* `setup` must return at least three stops in keyboard order.
|
|
34
|
+
*/
|
|
35
|
+
export declare function describeRovingKeyboard(options: {
|
|
36
|
+
name: string;
|
|
37
|
+
setup: () => HTMLElement[];
|
|
38
|
+
nextKey: KeyboardKey;
|
|
39
|
+
previousKey: KeyboardKey;
|
|
40
|
+
ignoredKeys?: KeyboardKey[];
|
|
41
|
+
}): void;
|
|
42
|
+
export declare function describeDialogKeyboard(options: {
|
|
43
|
+
/**
|
|
44
|
+
* Renders one dialog. `onClose` must unmount it. `first` and `last` are the
|
|
45
|
+
* focusable ends inside the dialog. Include a button named Second between them
|
|
46
|
+
* when the dialog is closeable.
|
|
47
|
+
*/
|
|
48
|
+
mount: (props?: {
|
|
49
|
+
closeable?: boolean;
|
|
50
|
+
focusLock?: boolean;
|
|
51
|
+
autoFocus?: boolean;
|
|
52
|
+
}) => {
|
|
53
|
+
dialog: HTMLElement;
|
|
54
|
+
first: HTMLElement;
|
|
55
|
+
last: HTMLElement;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Renders a closed dialog and a trigger. Enter on the trigger opens the dialog.
|
|
59
|
+
* Escape must close it and return focus to the trigger.
|
|
60
|
+
*/
|
|
61
|
+
openFromTrigger: () => HTMLElement;
|
|
62
|
+
}): void;
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.describeDialogKeyboard = exports.describeRovingKeyboard = exports.describeRadioGroupKeyboard = exports.describeToggleKeyboard = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var react_1 = require("@testing-library/react");
|
|
6
|
+
var focusLock_1 = require("./focusLock");
|
|
7
|
+
var press_1 = require("./press");
|
|
8
|
+
function describeToggleKeyboard(options) {
|
|
9
|
+
var role = options.role, renderEnabled = options.renderEnabled, renderDisabled = options.renderDisabled;
|
|
10
|
+
test('Tab moves focus onto the control', function () {
|
|
11
|
+
renderEnabled();
|
|
12
|
+
var control = react_1.screen.getByRole(role);
|
|
13
|
+
(0, press_1.tab)();
|
|
14
|
+
expect(control).toHaveFocus();
|
|
15
|
+
});
|
|
16
|
+
test('Space checks the control', function () {
|
|
17
|
+
renderEnabled();
|
|
18
|
+
var control = react_1.screen.getByRole(role);
|
|
19
|
+
(0, press_1.tab)();
|
|
20
|
+
(0, press_1.press)('Space');
|
|
21
|
+
expect(control).toBeChecked();
|
|
22
|
+
});
|
|
23
|
+
test('Enter does not check the control', function () {
|
|
24
|
+
renderEnabled();
|
|
25
|
+
var control = react_1.screen.getByRole(role);
|
|
26
|
+
(0, press_1.tab)();
|
|
27
|
+
(0, press_1.press)('Enter');
|
|
28
|
+
expect(control).not.toBeChecked();
|
|
29
|
+
});
|
|
30
|
+
test('Space does not check a disabled control', function () {
|
|
31
|
+
renderDisabled();
|
|
32
|
+
var control = react_1.screen.getByRole(role);
|
|
33
|
+
(0, react_1.act)(function () {
|
|
34
|
+
control.focus();
|
|
35
|
+
});
|
|
36
|
+
(0, press_1.press)('Space');
|
|
37
|
+
expect(control).not.toBeChecked();
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
exports.describeToggleKeyboard = describeToggleKeyboard;
|
|
41
|
+
function describeRadioGroupKeyboard(options) {
|
|
42
|
+
test('Tab focuses the first radio when none is selected', function () {
|
|
43
|
+
options.renderGroup();
|
|
44
|
+
var _a = tslib_1.__read(react_1.screen.getAllByRole('radio'), 2), first = _a[0], second = _a[1];
|
|
45
|
+
(0, press_1.tab)();
|
|
46
|
+
expect(first).toHaveFocus();
|
|
47
|
+
expect(second).toHaveAttribute('tabindex', '-1');
|
|
48
|
+
});
|
|
49
|
+
test('Tab focuses the selected radio', function () {
|
|
50
|
+
options.renderGroup({ value: 'pear' });
|
|
51
|
+
var _a = tslib_1.__read(react_1.screen.getAllByRole('radio'), 2), first = _a[0], second = _a[1];
|
|
52
|
+
(0, press_1.tab)();
|
|
53
|
+
expect(second).toHaveFocus();
|
|
54
|
+
expect(first).toHaveAttribute('tabindex', '-1');
|
|
55
|
+
});
|
|
56
|
+
test('Tab leaves the group from the active radio', function () {
|
|
57
|
+
options.renderGroup({ value: 'pear' });
|
|
58
|
+
var second = react_1.screen.getAllByRole('radio')[1];
|
|
59
|
+
(0, press_1.tab)();
|
|
60
|
+
expect(second).toHaveFocus();
|
|
61
|
+
(0, press_1.tab)();
|
|
62
|
+
expect(react_1.screen.getByRole('button', { name: 'After' })).toHaveFocus();
|
|
63
|
+
});
|
|
64
|
+
test('Space selects the active radio', function () {
|
|
65
|
+
options.renderGroup();
|
|
66
|
+
var first = react_1.screen.getAllByRole('radio')[0];
|
|
67
|
+
(0, press_1.tab)();
|
|
68
|
+
(0, press_1.press)('Space');
|
|
69
|
+
expect(first).toBeChecked();
|
|
70
|
+
});
|
|
71
|
+
test('Space does not select a radio in a disabled group', function () {
|
|
72
|
+
options.renderGroup({ disabled: true });
|
|
73
|
+
var first = react_1.screen.getAllByRole('radio')[0];
|
|
74
|
+
(0, react_1.act)(function () {
|
|
75
|
+
first.focus();
|
|
76
|
+
});
|
|
77
|
+
(0, press_1.press)('Space');
|
|
78
|
+
expect(first).not.toBeChecked();
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
exports.describeRadioGroupKeyboard = describeRadioGroupKeyboard;
|
|
82
|
+
/**
|
|
83
|
+
* Roving focus across `setup()` stops. The first stop is the tab entry.
|
|
84
|
+
* `setup` must return at least three stops in keyboard order.
|
|
85
|
+
*/
|
|
86
|
+
function describeRovingKeyboard(options) {
|
|
87
|
+
var name = options.name, setup = options.setup, nextKey = options.nextKey, previousKey = options.previousKey, _a = options.ignoredKeys, ignoredKeys = _a === void 0 ? [] : _a;
|
|
88
|
+
describe(name, function () {
|
|
89
|
+
test("".concat(nextKey, " moves to the next stop and wraps to the first"), function () {
|
|
90
|
+
var stops = setup();
|
|
91
|
+
(0, press_1.tab)();
|
|
92
|
+
expect(stops[0]).toHaveFocus();
|
|
93
|
+
(0, press_1.press)(nextKey);
|
|
94
|
+
expect(stops[1]).toHaveFocus();
|
|
95
|
+
(0, press_1.press)(nextKey);
|
|
96
|
+
expect(stops[2]).toHaveFocus();
|
|
97
|
+
(0, press_1.press)(nextKey);
|
|
98
|
+
expect(stops[0]).toHaveFocus();
|
|
99
|
+
});
|
|
100
|
+
test("".concat(previousKey, " wraps from the first stop to the last"), function () {
|
|
101
|
+
var stops = setup();
|
|
102
|
+
(0, press_1.tab)();
|
|
103
|
+
(0, press_1.press)(previousKey);
|
|
104
|
+
expect(stops[stops.length - 1]).toHaveFocus();
|
|
105
|
+
});
|
|
106
|
+
test('Home moves to the first stop and End moves to the last', function () {
|
|
107
|
+
var stops = setup();
|
|
108
|
+
(0, press_1.tab)();
|
|
109
|
+
(0, press_1.press)('End');
|
|
110
|
+
expect(stops[stops.length - 1]).toHaveFocus();
|
|
111
|
+
(0, press_1.press)('Home');
|
|
112
|
+
expect(stops[0]).toHaveFocus();
|
|
113
|
+
});
|
|
114
|
+
if (ignoredKeys.length > 0) {
|
|
115
|
+
test("".concat(ignoredKeys.join(', '), " do not move focus"), function () {
|
|
116
|
+
var stops = setup();
|
|
117
|
+
(0, press_1.tab)();
|
|
118
|
+
ignoredKeys.forEach(function (key) {
|
|
119
|
+
(0, press_1.press)(key);
|
|
120
|
+
expect(stops[0]).toHaveFocus();
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
exports.describeRovingKeyboard = describeRovingKeyboard;
|
|
127
|
+
function describeDialogKeyboard(options) {
|
|
128
|
+
var _this = this;
|
|
129
|
+
test('Escape closes a closeable dialog', function () {
|
|
130
|
+
options.mount();
|
|
131
|
+
(0, press_1.press)('Escape');
|
|
132
|
+
expect(react_1.screen.queryByRole('dialog')).toBeNull();
|
|
133
|
+
});
|
|
134
|
+
test('Escape does not close a dialog that is not closeable', function () {
|
|
135
|
+
options.mount({ closeable: false });
|
|
136
|
+
(0, press_1.press)('Escape');
|
|
137
|
+
react_1.screen.getByRole('dialog');
|
|
138
|
+
});
|
|
139
|
+
test('autoFocus moves focus to the first control inside the dialog', function () {
|
|
140
|
+
var first = options.mount().first;
|
|
141
|
+
expect(first).toHaveFocus();
|
|
142
|
+
});
|
|
143
|
+
test('autoFocus false leaves the first control unfocused', function () {
|
|
144
|
+
var first = options.mount({ autoFocus: false }).first;
|
|
145
|
+
expect(first).not.toHaveFocus();
|
|
146
|
+
});
|
|
147
|
+
test('Tab moves through the dialog controls', function () {
|
|
148
|
+
var _a = options.mount(), first = _a.first, last = _a.last;
|
|
149
|
+
expect(first).toHaveFocus();
|
|
150
|
+
(0, press_1.tab)();
|
|
151
|
+
expect(react_1.screen.getByRole('button', { name: 'Second' })).toHaveFocus();
|
|
152
|
+
(0, press_1.tab)();
|
|
153
|
+
expect(last).toHaveFocus();
|
|
154
|
+
});
|
|
155
|
+
test('focus stays locked inside the dialog', function () {
|
|
156
|
+
var _a = options.mount(), first = _a.first, last = _a.last;
|
|
157
|
+
expect((0, focusLock_1.isFocusLocked)({ first: first, last: last })).toBe(true);
|
|
158
|
+
});
|
|
159
|
+
test('Tab does not wrap inside the dialog when focus is not locked', function () {
|
|
160
|
+
var _a = options.mount({ focusLock: false }), first = _a.first, last = _a.last;
|
|
161
|
+
expect((0, focusLock_1.isFocusLocked)({ first: first, last: last })).toBe(false);
|
|
162
|
+
});
|
|
163
|
+
test('Escape returns focus to the trigger', function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
164
|
+
var trigger;
|
|
165
|
+
return tslib_1.__generator(this, function (_a) {
|
|
166
|
+
switch (_a.label) {
|
|
167
|
+
case 0:
|
|
168
|
+
trigger = options.openFromTrigger();
|
|
169
|
+
(0, press_1.tab)();
|
|
170
|
+
expect(trigger).toHaveFocus();
|
|
171
|
+
(0, press_1.press)('Enter');
|
|
172
|
+
expect(react_1.screen.getByRole('dialog')).toBeTruthy();
|
|
173
|
+
(0, press_1.press)('Escape');
|
|
174
|
+
return [4 /*yield*/, (0, react_1.waitFor)(function () {
|
|
175
|
+
expect(react_1.screen.queryByRole('dialog')).toBeNull();
|
|
176
|
+
expect(trigger).toHaveFocus();
|
|
177
|
+
})];
|
|
178
|
+
case 1:
|
|
179
|
+
_a.sent();
|
|
180
|
+
return [2 /*return*/];
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}); });
|
|
184
|
+
}
|
|
185
|
+
exports.describeDialogKeyboard = describeDialogKeyboard;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keys the keyboard harness can press. Add a key here when a new pattern needs it.
|
|
3
|
+
* Tab uses `userEvent.tab()` — `{Tab}` is not a substitute.
|
|
4
|
+
*/
|
|
5
|
+
export type KeyboardKey = 'Enter' | 'Space' | 'Escape' | 'ArrowUp' | 'ArrowDown' | 'ArrowLeft' | 'ArrowRight' | 'Home' | 'End';
|
|
6
|
+
export declare function press(key: KeyboardKey, modifiers?: {
|
|
7
|
+
shift?: boolean;
|
|
8
|
+
}): void;
|
|
9
|
+
/** Types into the focused element. Does not click or move focus. */
|
|
10
|
+
export declare function type(text: string): void;
|
|
11
|
+
export declare function tab(): void;
|
|
12
|
+
export declare function shiftTab(): void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shiftTab = exports.tab = exports.type = exports.press = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var user_event_1 = tslib_1.__importDefault(require("@testing-library/user-event"));
|
|
6
|
+
function keyToken(key) {
|
|
7
|
+
return key === 'Space' ? '{space}' : "{".concat(key, "}");
|
|
8
|
+
}
|
|
9
|
+
function press(key, modifiers) {
|
|
10
|
+
var token = keyToken(key);
|
|
11
|
+
if (modifiers === null || modifiers === void 0 ? void 0 : modifiers.shift) {
|
|
12
|
+
user_event_1.default.keyboard("{Shift>}".concat(token, "{/Shift}"));
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
user_event_1.default.keyboard(token);
|
|
16
|
+
}
|
|
17
|
+
exports.press = press;
|
|
18
|
+
/** Types into the focused element. Does not click or move focus. */
|
|
19
|
+
function type(text) {
|
|
20
|
+
user_event_1.default.keyboard(text);
|
|
21
|
+
}
|
|
22
|
+
exports.type = type;
|
|
23
|
+
function tab() {
|
|
24
|
+
user_event_1.default.tab();
|
|
25
|
+
}
|
|
26
|
+
exports.tab = tab;
|
|
27
|
+
function shiftTab() {
|
|
28
|
+
user_event_1.default.tab({ shift: true });
|
|
29
|
+
}
|
|
30
|
+
exports.shiftTab = shiftTab;
|
|
@@ -16,8 +16,8 @@ var RangeSelector = function (_a) {
|
|
|
16
16
|
var TIME_RANGE_LIST_OVERRIDES = (0, react_1.useMemo)(function () {
|
|
17
17
|
return (0, overrides_1.mergeOverrides)({ Menu: { props: { overrides: { List: { props: { overrides: { Root: { className: 'h-0' } } } } } } } }, overrides);
|
|
18
18
|
}, [overrides]);
|
|
19
|
-
return ((0, jsx_runtime_1.jsxs)(box_1.Box, tslib_1.__assign({ className: "flex border-0 border-t-1 border-solid spr-border-01" }, { children: [props.timeRangePresets.length !== 1 ? ((0, jsx_runtime_1.jsx)(TimeRangeList, tslib_1.__assign({ onChange: onChange, timeRange: timeRange, preset: preset, timeRangePresets: props.timeRangePresets, overrides: TIME_RANGE_LIST_OVERRIDES, hidePresetSearch: hidePresetSearch }, restTimeRangeListProps))) : null, (0, jsx_runtime_1.jsxs)(box_1.Box, tslib_1.__assign({ className: "overflow-y-auto" }, { children: [(0, jsx_runtime_1.jsx)(Calendar, tslib_1.__assign({ timeSelectEnd: props.timeSelect, timeSelectStart: props.timeSelect, value: timeRange, onChange: onChange, peekNextMonth: props.peekNextMonth, excludeDates: props.excludeDates, filterDate: props.filterDate, minDate: props.minDate, maxDate: props.maxDate, range: true, monthsShown: props.monthsShown, locale: props.locale, formatString: formatString,
|
|
20
|
-
// @ts-
|
|
19
|
+
return ((0, jsx_runtime_1.jsxs)(box_1.Box, tslib_1.__assign({ className: "flex flex-1 min-h-0 overflow-y-auto border-0 border-t-1 border-solid spr-border-01", "data-testid": "time-range-selector-scroll" }, { children: [props.timeRangePresets.length !== 1 ? ((0, jsx_runtime_1.jsx)(TimeRangeList, tslib_1.__assign({ onChange: onChange, timeRange: timeRange, preset: preset, timeRangePresets: props.timeRangePresets, overrides: TIME_RANGE_LIST_OVERRIDES, hidePresetSearch: hidePresetSearch }, restTimeRangeListProps))) : null, (0, jsx_runtime_1.jsxs)(box_1.Box, tslib_1.__assign({ className: "overflow-y-auto" }, { children: [(0, jsx_runtime_1.jsx)(Calendar, tslib_1.__assign({ timeSelectEnd: props.timeSelect, timeSelectStart: props.timeSelect, value: timeRange, onChange: onChange, peekNextMonth: props.peekNextMonth, excludeDates: props.excludeDates, filterDate: props.filterDate, minDate: props.minDate, maxDate: props.maxDate, range: true, monthsShown: props.monthsShown, locale: props.locale, formatString: formatString,
|
|
20
|
+
// @ts-expect-error Calendar overrides type does not include date-picker overrides shape
|
|
21
21
|
overrides: props.overrides, fixedHeight: props.fixedHeight }, calendarProps)), footerContent] }))] })));
|
|
22
22
|
};
|
|
23
23
|
RangeSelector.displayName = 'RangeSelector';
|
|
@@ -116,7 +116,7 @@ var RangeSelectorContainer = function (_a) {
|
|
|
116
116
|
fill: theme.spr.clrRed,
|
|
117
117
|
});
|
|
118
118
|
} }), (0, jsx_runtime_1.jsx)(typography_1.Typography, tslib_1.__assign({ className: "my-0", variant: "bs3" }, { children: errMsg }))] }))) : null;
|
|
119
|
-
return ((0, jsx_runtime_1.jsxs)(box_1.Box, tslib_1.__assign({ className: "spr-ui-01 rounded-8" }, { children: [(0, jsx_runtime_1.jsxs)(Header, tslib_1.__assign({ "$setTimezone": setTimezone, "$onClose": props.onClose }, headerProps, { children: [(0, jsx_runtime_1.jsx)(HeaderBeforeEnhancer, tslib_1.__assign({ variant: "heading-7", "$as": "span", className: "flex items-center" }, headerBeforeEnhancerProps, { children: locale.timeRangePicker.headerLabel })), disableTimezone ? null : ((0, jsx_runtime_1.jsx)(TimezonePicker, tslib_1.__assign({ setTimezone: setTimezone, timezone: timezone, timezoneOptions: timezoneOptions }, timezonePickerProps, { "aria-label": locale.timeRangePicker.timezoneLabel, className: ['w-0 grow max-w-md', timezonePickerProps === null || timezonePickerProps === void 0 ? void 0 : timezonePickerProps.className] })))] })), (0, jsx_runtime_1.jsx)(RangeSelector, tslib_1.__assign({ overrides: props.overrides, timeSelect: props.timeSelect, timeRangePresets: timeRangePresets, timezone: timezone, timeRange: timeRange, preset: preset, onChange: onDateChange, adapter: adapter, peekNextMonth: props.peekNextMonth, excludeDates: props.excludeDates, filterDate: props.filterDate, minDate: minDate, maxDate: maxDate, formatString: props.formatString, locale: props.locale, fixedHeight: props.fixedHeight, monthsShown: monthsShown, hidePresetSearch: hidePresetSearch, footerContent: (0, jsx_runtime_1.jsx)(Footer, tslib_1.__assign({ "$hasError": hasError, "$onSubmit": handleSubmit, "$onClose": props.onClose }, footerProps, { className: ['px-6 py-3 mt-2', footerProps.className] }, { children: (0, jsx_runtime_1.jsxs)(box_1.Box, tslib_1.__assign({ className: "justify-between w-0 grow flex" }, { children: [(0, jsx_runtime_1.jsx)(FooterBeforeEnhancer, tslib_1.__assign({}, footerBeforeEnhancerProps)), (0, jsx_runtime_1.jsxs)(stack_1.Stack, tslib_1.__assign({ direction: monthsShown === 1 ? 'vertical' : 'horizontal', gap: 3, className: monthsShown !== 1 ? 'items-center' : undefined, style: { maxWidth: 'fit-content' } }, { children: [monthsShown === 1 ? null : errorEl, (0, jsx_runtime_1.jsxs)(stack_1.StackItem, tslib_1.__assign({ className: "flex self-end" }, { children: [(footerProps === null || footerProps === void 0 ? void 0 : footerProps.showClearButton) ? ((0, jsx_runtime_1.jsx)(button_1.Button, tslib_1.__assign({ size: "xs", onClick: footerProps.handleClearBtnClick, variant: "secondary", "data-testid": "clear", disabled: timeRange.length === 0 }, { children: locale.timeRangePicker.clearBtnLabel }))) : ((0, jsx_runtime_1.jsx)(button_1.Button, tslib_1.__assign({ size: "xs", onClick: props.onClose, variant: "secondary", "data-testid": "cancel" }, { children: locale.timeRangePicker.cancelBtnLabel }))), (0, jsx_runtime_1.jsx)(button_1.Button, tslib_1.__assign({ size: "xs", className: "ml-3", onClick: handleSubmit, disabled: hasError, "data-testid": "save" }, { children: locale.timeRangePicker.saveBtnLabel }))] })), monthsShown === 1 ? errorEl : null] }))] })) })) }, rangeSelectorProps))] })));
|
|
119
|
+
return ((0, jsx_runtime_1.jsxs)(box_1.Box, tslib_1.__assign({ className: "spr-ui-01 rounded-8 flex flex-col", style: { maxHeight: '100vh' }, "data-testid": "time-range-selector-panel" }, { children: [(0, jsx_runtime_1.jsxs)(Header, tslib_1.__assign({ "$setTimezone": setTimezone, "$onClose": props.onClose }, headerProps, { children: [(0, jsx_runtime_1.jsx)(HeaderBeforeEnhancer, tslib_1.__assign({ variant: "heading-7", "$as": "span", className: "flex items-center" }, headerBeforeEnhancerProps, { children: locale.timeRangePicker.headerLabel })), disableTimezone ? null : ((0, jsx_runtime_1.jsx)(TimezonePicker, tslib_1.__assign({ setTimezone: setTimezone, timezone: timezone, timezoneOptions: timezoneOptions }, timezonePickerProps, { "aria-label": locale.timeRangePicker.timezoneLabel, className: ['w-0 grow max-w-md', timezonePickerProps === null || timezonePickerProps === void 0 ? void 0 : timezonePickerProps.className] })))] })), (0, jsx_runtime_1.jsx)(RangeSelector, tslib_1.__assign({ overrides: props.overrides, timeSelect: props.timeSelect, timeRangePresets: timeRangePresets, timezone: timezone, timeRange: timeRange, preset: preset, onChange: onDateChange, adapter: adapter, peekNextMonth: props.peekNextMonth, excludeDates: props.excludeDates, filterDate: props.filterDate, minDate: minDate, maxDate: maxDate, formatString: props.formatString, locale: props.locale, fixedHeight: props.fixedHeight, monthsShown: monthsShown, hidePresetSearch: hidePresetSearch, footerContent: (0, jsx_runtime_1.jsx)(Footer, tslib_1.__assign({ "$hasError": hasError, "$onSubmit": handleSubmit, "$onClose": props.onClose }, footerProps, { className: ['px-6 py-3 mt-2', footerProps.className] }, { children: (0, jsx_runtime_1.jsxs)(box_1.Box, tslib_1.__assign({ className: "justify-between w-0 grow flex" }, { children: [(0, jsx_runtime_1.jsx)(FooterBeforeEnhancer, tslib_1.__assign({}, footerBeforeEnhancerProps)), (0, jsx_runtime_1.jsxs)(stack_1.Stack, tslib_1.__assign({ direction: monthsShown === 1 ? 'vertical' : 'horizontal', gap: 3, className: monthsShown !== 1 ? 'items-center' : undefined, style: { maxWidth: 'fit-content' } }, { children: [monthsShown === 1 ? null : errorEl, (0, jsx_runtime_1.jsxs)(stack_1.StackItem, tslib_1.__assign({ className: "flex self-end" }, { children: [(footerProps === null || footerProps === void 0 ? void 0 : footerProps.showClearButton) ? ((0, jsx_runtime_1.jsx)(button_1.Button, tslib_1.__assign({ size: "xs", onClick: footerProps.handleClearBtnClick, variant: "secondary", "data-testid": "clear", disabled: timeRange.length === 0 }, { children: locale.timeRangePicker.clearBtnLabel }))) : ((0, jsx_runtime_1.jsx)(button_1.Button, tslib_1.__assign({ size: "xs", onClick: props.onClose, variant: "secondary", "data-testid": "cancel" }, { children: locale.timeRangePicker.cancelBtnLabel }))), (0, jsx_runtime_1.jsx)(button_1.Button, tslib_1.__assign({ size: "xs", className: "ml-3", onClick: handleSubmit, disabled: hasError, "data-testid": "save" }, { children: locale.timeRangePicker.saveBtnLabel }))] })), monthsShown === 1 ? errorEl : null] }))] })) })) }, rangeSelectorProps))] })));
|
|
120
120
|
};
|
|
121
121
|
RangeSelectorContainer.displayName = 'RangeSelectorContainer';
|
|
122
122
|
exports.default = RangeSelectorContainer;
|