@instructure/ui-tray 10.11.0 → 10.11.1-snapshot-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 +8 -0
- package/es/Tray/__new-tests__/Tray.test.js +175 -0
- package/lib/Tray/__new-tests__/Tray.test.js +177 -0
- package/package.json +20 -18
- package/src/Tray/__new-tests__/Tray.test.tsx +204 -0
- package/tsconfig.build.json +0 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Tray/__new-tests__/Tray.test.d.ts +2 -0
- package/types/Tray/__new-tests__/Tray.test.d.ts.map +1 -0
- package/es/Tray/TrayLocator.js +0 -29
- package/es/Tray/locator.js +0 -27
- package/lib/Tray/TrayLocator.js +0 -34
- package/lib/Tray/locator.js +0 -37
- package/src/Tray/TrayLocator.ts +0 -30
- package/src/Tray/locator.ts +0 -28
- package/types/Tray/TrayLocator.d.ts +0 -310
- package/types/Tray/TrayLocator.d.ts.map +0 -1
- package/types/Tray/locator.d.ts +0 -4
- package/types/Tray/locator.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [10.11.1-snapshot-2](https://github.com/instructure/instructure-ui/compare/v10.11.0...v10.11.1-snapshot-2) (2025-02-05)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-tray
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [10.11.0](https://github.com/instructure/instructure-ui/compare/v10.10.0...v10.11.0) (2025-02-03)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @instructure/ui-tray
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
var _Tray, _Tray2, _Tray3, _input, _input2;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import React from 'react';
|
|
27
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
28
|
+
import { vi } from 'vitest';
|
|
29
|
+
import '@testing-library/jest-dom';
|
|
30
|
+
import { Tray } from '../index';
|
|
31
|
+
describe('<Tray />', async () => {
|
|
32
|
+
it('should render nothing and have a node with no parent when closed', async () => {
|
|
33
|
+
render(_Tray || (_Tray = /*#__PURE__*/React.createElement(Tray, {
|
|
34
|
+
label: "Tray Example"
|
|
35
|
+
}, "Hello Tray")));
|
|
36
|
+
const trayContent = screen.queryByText('Hello Tray');
|
|
37
|
+
expect(trayContent).not.toBeInTheDocument();
|
|
38
|
+
});
|
|
39
|
+
it('should render children and have a node with a parent when open', async () => {
|
|
40
|
+
render(_Tray2 || (_Tray2 = /*#__PURE__*/React.createElement(Tray, {
|
|
41
|
+
label: "Tray Example",
|
|
42
|
+
open: true
|
|
43
|
+
}, "Hello Tray")));
|
|
44
|
+
const trayContent = screen.getByText('Hello Tray');
|
|
45
|
+
expect(trayContent).toBeInTheDocument();
|
|
46
|
+
});
|
|
47
|
+
it('should apply the a11y attributes', async () => {
|
|
48
|
+
render(_Tray3 || (_Tray3 = /*#__PURE__*/React.createElement(Tray, {
|
|
49
|
+
label: "Tray Example",
|
|
50
|
+
open: true
|
|
51
|
+
}, "Hello Tray")));
|
|
52
|
+
const tray = screen.getByRole('dialog');
|
|
53
|
+
expect(tray).toHaveAttribute('aria-label', 'Tray Example');
|
|
54
|
+
});
|
|
55
|
+
it('should support onOpen prop', async () => {
|
|
56
|
+
const onOpen = vi.fn();
|
|
57
|
+
render(/*#__PURE__*/React.createElement(Tray, {
|
|
58
|
+
label: "Tray Example",
|
|
59
|
+
open: true,
|
|
60
|
+
onOpen: onOpen
|
|
61
|
+
}, "Hello Tray"));
|
|
62
|
+
await waitFor(() => {
|
|
63
|
+
expect(onOpen).toHaveBeenCalled();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
it('should support onClose prop', async () => {
|
|
67
|
+
const onClose = vi.fn();
|
|
68
|
+
const _render = render(/*#__PURE__*/React.createElement(Tray, {
|
|
69
|
+
label: "Tray Example",
|
|
70
|
+
open: true,
|
|
71
|
+
onClose: onClose
|
|
72
|
+
}, "Hello Tray")),
|
|
73
|
+
rerender = _render.rerender;
|
|
74
|
+
|
|
75
|
+
// Set prop: open
|
|
76
|
+
rerender(/*#__PURE__*/React.createElement(Tray, {
|
|
77
|
+
label: "Tray Example",
|
|
78
|
+
open: false,
|
|
79
|
+
onClose: onClose
|
|
80
|
+
}, "Hello Tray"));
|
|
81
|
+
await waitFor(() => {
|
|
82
|
+
expect(onClose).toHaveBeenCalled();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
it('should take a prop for finding default focus', async () => {
|
|
86
|
+
render(/*#__PURE__*/React.createElement(Tray, {
|
|
87
|
+
label: "Tray Example",
|
|
88
|
+
open: true,
|
|
89
|
+
defaultFocusElement: () => document.getElementById('my-input')
|
|
90
|
+
}, "Hello Tray", _input || (_input = /*#__PURE__*/React.createElement("input", {
|
|
91
|
+
type: "text"
|
|
92
|
+
})), _input2 || (_input2 = /*#__PURE__*/React.createElement("input", {
|
|
93
|
+
type: "text",
|
|
94
|
+
id: "my-input",
|
|
95
|
+
"aria-label": "my-input-label"
|
|
96
|
+
}))));
|
|
97
|
+
const input = screen.getByLabelText('my-input-label');
|
|
98
|
+
await waitFor(() => {
|
|
99
|
+
expect(document.activeElement).toBe(input);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
describe('transition()', () => {
|
|
103
|
+
const placements = {
|
|
104
|
+
ltr: {
|
|
105
|
+
enteringPlacements: {
|
|
106
|
+
start: 'slide-left',
|
|
107
|
+
end: 'slide-right',
|
|
108
|
+
top: 'slide-up',
|
|
109
|
+
bottom: 'slide-down'
|
|
110
|
+
},
|
|
111
|
+
exitingPlacements: {
|
|
112
|
+
start: 'slide-left',
|
|
113
|
+
end: 'slide-right',
|
|
114
|
+
top: 'slide-up',
|
|
115
|
+
bottom: 'slide-down'
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
rtl: {
|
|
119
|
+
enteringPlacements: {
|
|
120
|
+
start: 'slide-right',
|
|
121
|
+
end: 'slide-left'
|
|
122
|
+
},
|
|
123
|
+
exitingPlacements: {
|
|
124
|
+
start: 'slide-right',
|
|
125
|
+
end: 'slide-left'
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
for (const dir in placements) {
|
|
130
|
+
describe(`when text direction is '${dir}'`, () => {
|
|
131
|
+
for (const placement in placements[dir].enteringPlacements) {
|
|
132
|
+
const val = placements[dir].enteringPlacements[placement];
|
|
133
|
+
it(`returns ${val} for ${placement} when entering`, async () => {
|
|
134
|
+
const onEntered = vi.fn();
|
|
135
|
+
document.documentElement.setAttribute('dir', dir);
|
|
136
|
+
render(/*#__PURE__*/React.createElement(Tray, {
|
|
137
|
+
open: true,
|
|
138
|
+
label: "Tray Example",
|
|
139
|
+
placement: placement,
|
|
140
|
+
onEntered: onEntered
|
|
141
|
+
}, "Hello"));
|
|
142
|
+
await waitFor(() => {
|
|
143
|
+
expect(onEntered).toHaveBeenCalled();
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
for (const placement in placements[dir].exitingPlacements) {
|
|
148
|
+
const val = placements[dir].exitingPlacements[placement];
|
|
149
|
+
it(`returns ${val} for ${placement} when exiting`, async () => {
|
|
150
|
+
const onExited = vi.fn();
|
|
151
|
+
document.documentElement.setAttribute('dir', dir);
|
|
152
|
+
const _render2 = render(/*#__PURE__*/React.createElement(Tray, {
|
|
153
|
+
open: true,
|
|
154
|
+
label: "Tray Example",
|
|
155
|
+
placement: placement,
|
|
156
|
+
onExited: onExited
|
|
157
|
+
}, "Hello")),
|
|
158
|
+
rerender = _render2.rerender;
|
|
159
|
+
|
|
160
|
+
// Set prop: open
|
|
161
|
+
rerender(/*#__PURE__*/React.createElement(Tray, {
|
|
162
|
+
open: false,
|
|
163
|
+
label: "Tray Example",
|
|
164
|
+
placement: placement,
|
|
165
|
+
onExited: onExited
|
|
166
|
+
}, "Hello"));
|
|
167
|
+
await waitFor(() => {
|
|
168
|
+
expect(onExited).toHaveBeenCalled();
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _react = _interopRequireDefault(require("react"));
|
|
5
|
+
var _react2 = require("@testing-library/react");
|
|
6
|
+
var _vitest = require("vitest");
|
|
7
|
+
require("@testing-library/jest-dom");
|
|
8
|
+
var _index = require("../index");
|
|
9
|
+
var _Tray, _Tray2, _Tray3, _input, _input2;
|
|
10
|
+
/*
|
|
11
|
+
* The MIT License (MIT)
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
14
|
+
*
|
|
15
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
17
|
+
* in the Software without restriction, including without limitation the rights
|
|
18
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
* furnished to do so, subject to the following conditions:
|
|
21
|
+
*
|
|
22
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
23
|
+
* copies or substantial portions of the Software.
|
|
24
|
+
*
|
|
25
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
+
* SOFTWARE.
|
|
32
|
+
*/
|
|
33
|
+
describe('<Tray />', async () => {
|
|
34
|
+
it('should render nothing and have a node with no parent when closed', async () => {
|
|
35
|
+
(0, _react2.render)(_Tray || (_Tray = /*#__PURE__*/_react.default.createElement(_index.Tray, {
|
|
36
|
+
label: "Tray Example"
|
|
37
|
+
}, "Hello Tray")));
|
|
38
|
+
const trayContent = _react2.screen.queryByText('Hello Tray');
|
|
39
|
+
expect(trayContent).not.toBeInTheDocument();
|
|
40
|
+
});
|
|
41
|
+
it('should render children and have a node with a parent when open', async () => {
|
|
42
|
+
(0, _react2.render)(_Tray2 || (_Tray2 = /*#__PURE__*/_react.default.createElement(_index.Tray, {
|
|
43
|
+
label: "Tray Example",
|
|
44
|
+
open: true
|
|
45
|
+
}, "Hello Tray")));
|
|
46
|
+
const trayContent = _react2.screen.getByText('Hello Tray');
|
|
47
|
+
expect(trayContent).toBeInTheDocument();
|
|
48
|
+
});
|
|
49
|
+
it('should apply the a11y attributes', async () => {
|
|
50
|
+
(0, _react2.render)(_Tray3 || (_Tray3 = /*#__PURE__*/_react.default.createElement(_index.Tray, {
|
|
51
|
+
label: "Tray Example",
|
|
52
|
+
open: true
|
|
53
|
+
}, "Hello Tray")));
|
|
54
|
+
const tray = _react2.screen.getByRole('dialog');
|
|
55
|
+
expect(tray).toHaveAttribute('aria-label', 'Tray Example');
|
|
56
|
+
});
|
|
57
|
+
it('should support onOpen prop', async () => {
|
|
58
|
+
const onOpen = _vitest.vi.fn();
|
|
59
|
+
(0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.Tray, {
|
|
60
|
+
label: "Tray Example",
|
|
61
|
+
open: true,
|
|
62
|
+
onOpen: onOpen
|
|
63
|
+
}, "Hello Tray"));
|
|
64
|
+
await (0, _react2.waitFor)(() => {
|
|
65
|
+
expect(onOpen).toHaveBeenCalled();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
it('should support onClose prop', async () => {
|
|
69
|
+
const onClose = _vitest.vi.fn();
|
|
70
|
+
const _render = (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.Tray, {
|
|
71
|
+
label: "Tray Example",
|
|
72
|
+
open: true,
|
|
73
|
+
onClose: onClose
|
|
74
|
+
}, "Hello Tray")),
|
|
75
|
+
rerender = _render.rerender;
|
|
76
|
+
|
|
77
|
+
// Set prop: open
|
|
78
|
+
rerender(/*#__PURE__*/_react.default.createElement(_index.Tray, {
|
|
79
|
+
label: "Tray Example",
|
|
80
|
+
open: false,
|
|
81
|
+
onClose: onClose
|
|
82
|
+
}, "Hello Tray"));
|
|
83
|
+
await (0, _react2.waitFor)(() => {
|
|
84
|
+
expect(onClose).toHaveBeenCalled();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
it('should take a prop for finding default focus', async () => {
|
|
88
|
+
(0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.Tray, {
|
|
89
|
+
label: "Tray Example",
|
|
90
|
+
open: true,
|
|
91
|
+
defaultFocusElement: () => document.getElementById('my-input')
|
|
92
|
+
}, "Hello Tray", _input || (_input = /*#__PURE__*/_react.default.createElement("input", {
|
|
93
|
+
type: "text"
|
|
94
|
+
})), _input2 || (_input2 = /*#__PURE__*/_react.default.createElement("input", {
|
|
95
|
+
type: "text",
|
|
96
|
+
id: "my-input",
|
|
97
|
+
"aria-label": "my-input-label"
|
|
98
|
+
}))));
|
|
99
|
+
const input = _react2.screen.getByLabelText('my-input-label');
|
|
100
|
+
await (0, _react2.waitFor)(() => {
|
|
101
|
+
expect(document.activeElement).toBe(input);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
describe('transition()', () => {
|
|
105
|
+
const placements = {
|
|
106
|
+
ltr: {
|
|
107
|
+
enteringPlacements: {
|
|
108
|
+
start: 'slide-left',
|
|
109
|
+
end: 'slide-right',
|
|
110
|
+
top: 'slide-up',
|
|
111
|
+
bottom: 'slide-down'
|
|
112
|
+
},
|
|
113
|
+
exitingPlacements: {
|
|
114
|
+
start: 'slide-left',
|
|
115
|
+
end: 'slide-right',
|
|
116
|
+
top: 'slide-up',
|
|
117
|
+
bottom: 'slide-down'
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
rtl: {
|
|
121
|
+
enteringPlacements: {
|
|
122
|
+
start: 'slide-right',
|
|
123
|
+
end: 'slide-left'
|
|
124
|
+
},
|
|
125
|
+
exitingPlacements: {
|
|
126
|
+
start: 'slide-right',
|
|
127
|
+
end: 'slide-left'
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
for (const dir in placements) {
|
|
132
|
+
describe(`when text direction is '${dir}'`, () => {
|
|
133
|
+
for (const placement in placements[dir].enteringPlacements) {
|
|
134
|
+
const val = placements[dir].enteringPlacements[placement];
|
|
135
|
+
it(`returns ${val} for ${placement} when entering`, async () => {
|
|
136
|
+
const onEntered = _vitest.vi.fn();
|
|
137
|
+
document.documentElement.setAttribute('dir', dir);
|
|
138
|
+
(0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.Tray, {
|
|
139
|
+
open: true,
|
|
140
|
+
label: "Tray Example",
|
|
141
|
+
placement: placement,
|
|
142
|
+
onEntered: onEntered
|
|
143
|
+
}, "Hello"));
|
|
144
|
+
await (0, _react2.waitFor)(() => {
|
|
145
|
+
expect(onEntered).toHaveBeenCalled();
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
for (const placement in placements[dir].exitingPlacements) {
|
|
150
|
+
const val = placements[dir].exitingPlacements[placement];
|
|
151
|
+
it(`returns ${val} for ${placement} when exiting`, async () => {
|
|
152
|
+
const onExited = _vitest.vi.fn();
|
|
153
|
+
document.documentElement.setAttribute('dir', dir);
|
|
154
|
+
const _render2 = (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.Tray, {
|
|
155
|
+
open: true,
|
|
156
|
+
label: "Tray Example",
|
|
157
|
+
placement: placement,
|
|
158
|
+
onExited: onExited
|
|
159
|
+
}, "Hello")),
|
|
160
|
+
rerender = _render2.rerender;
|
|
161
|
+
|
|
162
|
+
// Set prop: open
|
|
163
|
+
rerender(/*#__PURE__*/_react.default.createElement(_index.Tray, {
|
|
164
|
+
open: false,
|
|
165
|
+
label: "Tray Example",
|
|
166
|
+
placement: placement,
|
|
167
|
+
onExited: onExited
|
|
168
|
+
}, "Hello"));
|
|
169
|
+
await (0, _react2.waitFor)(() => {
|
|
170
|
+
expect(onExited).toHaveBeenCalled();
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-tray",
|
|
3
|
-
"version": "10.11.
|
|
3
|
+
"version": "10.11.1-snapshot-2",
|
|
4
4
|
"description": "Tray component for secondary/menu content",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -24,26 +24,28 @@
|
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@babel/runtime": "^7.26.0",
|
|
27
|
-
"@instructure/console": "10.11.
|
|
28
|
-
"@instructure/emotion": "10.11.
|
|
29
|
-
"@instructure/shared-types": "10.11.
|
|
30
|
-
"@instructure/ui-dialog": "10.11.
|
|
31
|
-
"@instructure/ui-i18n": "10.11.
|
|
32
|
-
"@instructure/ui-motion": "10.11.
|
|
33
|
-
"@instructure/ui-overlays": "10.11.
|
|
34
|
-
"@instructure/ui-portal": "10.11.
|
|
35
|
-
"@instructure/ui-position": "10.11.
|
|
36
|
-
"@instructure/ui-prop-types": "10.11.
|
|
37
|
-
"@instructure/ui-react-utils": "10.11.
|
|
38
|
-
"@instructure/ui-testable": "10.11.
|
|
39
|
-
"@instructure/ui-utils": "10.11.
|
|
27
|
+
"@instructure/console": "10.11.1-snapshot-2",
|
|
28
|
+
"@instructure/emotion": "10.11.1-snapshot-2",
|
|
29
|
+
"@instructure/shared-types": "10.11.1-snapshot-2",
|
|
30
|
+
"@instructure/ui-dialog": "10.11.1-snapshot-2",
|
|
31
|
+
"@instructure/ui-i18n": "10.11.1-snapshot-2",
|
|
32
|
+
"@instructure/ui-motion": "10.11.1-snapshot-2",
|
|
33
|
+
"@instructure/ui-overlays": "10.11.1-snapshot-2",
|
|
34
|
+
"@instructure/ui-portal": "10.11.1-snapshot-2",
|
|
35
|
+
"@instructure/ui-position": "10.11.1-snapshot-2",
|
|
36
|
+
"@instructure/ui-prop-types": "10.11.1-snapshot-2",
|
|
37
|
+
"@instructure/ui-react-utils": "10.11.1-snapshot-2",
|
|
38
|
+
"@instructure/ui-testable": "10.11.1-snapshot-2",
|
|
39
|
+
"@instructure/ui-utils": "10.11.1-snapshot-2",
|
|
40
40
|
"prop-types": "^15.8.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@instructure/ui-babel-preset": "10.11.
|
|
44
|
-
"@instructure/ui-
|
|
45
|
-
"@
|
|
46
|
-
"@
|
|
43
|
+
"@instructure/ui-babel-preset": "10.11.1-snapshot-2",
|
|
44
|
+
"@instructure/ui-themes": "10.11.1-snapshot-2",
|
|
45
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
46
|
+
"@testing-library/react": "^16.0.1",
|
|
47
|
+
"@testing-library/user-event": "^14.5.2",
|
|
48
|
+
"vitest": "^2.1.8"
|
|
47
49
|
},
|
|
48
50
|
"peerDependencies": {
|
|
49
51
|
"react": ">=16.14 <=18"
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import React from 'react'
|
|
26
|
+
import { render, screen, waitFor } from '@testing-library/react'
|
|
27
|
+
import { vi } from 'vitest'
|
|
28
|
+
import '@testing-library/jest-dom'
|
|
29
|
+
|
|
30
|
+
import { Tray } from '../index'
|
|
31
|
+
import type { TrayProps } from '../props'
|
|
32
|
+
|
|
33
|
+
describe('<Tray />', async () => {
|
|
34
|
+
it('should render nothing and have a node with no parent when closed', async () => {
|
|
35
|
+
render(<Tray label="Tray Example">Hello Tray</Tray>)
|
|
36
|
+
|
|
37
|
+
const trayContent = screen.queryByText('Hello Tray')
|
|
38
|
+
expect(trayContent).not.toBeInTheDocument()
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('should render children and have a node with a parent when open', async () => {
|
|
42
|
+
render(
|
|
43
|
+
<Tray label="Tray Example" open>
|
|
44
|
+
Hello Tray
|
|
45
|
+
</Tray>
|
|
46
|
+
)
|
|
47
|
+
const trayContent = screen.getByText('Hello Tray')
|
|
48
|
+
|
|
49
|
+
expect(trayContent).toBeInTheDocument()
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('should apply the a11y attributes', async () => {
|
|
53
|
+
render(
|
|
54
|
+
<Tray label="Tray Example" open>
|
|
55
|
+
Hello Tray
|
|
56
|
+
</Tray>
|
|
57
|
+
)
|
|
58
|
+
const tray = screen.getByRole('dialog')
|
|
59
|
+
|
|
60
|
+
expect(tray).toHaveAttribute('aria-label', 'Tray Example')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('should support onOpen prop', async () => {
|
|
64
|
+
const onOpen = vi.fn()
|
|
65
|
+
render(
|
|
66
|
+
<Tray label="Tray Example" open onOpen={onOpen}>
|
|
67
|
+
Hello Tray
|
|
68
|
+
</Tray>
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
await waitFor(() => {
|
|
72
|
+
expect(onOpen).toHaveBeenCalled()
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('should support onClose prop', async () => {
|
|
77
|
+
const onClose = vi.fn()
|
|
78
|
+
|
|
79
|
+
const { rerender } = render(
|
|
80
|
+
<Tray label="Tray Example" open onClose={onClose}>
|
|
81
|
+
Hello Tray
|
|
82
|
+
</Tray>
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
// Set prop: open
|
|
86
|
+
rerender(
|
|
87
|
+
<Tray label="Tray Example" open={false} onClose={onClose}>
|
|
88
|
+
Hello Tray
|
|
89
|
+
</Tray>
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
await waitFor(() => {
|
|
93
|
+
expect(onClose).toHaveBeenCalled()
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('should take a prop for finding default focus', async () => {
|
|
98
|
+
render(
|
|
99
|
+
<Tray
|
|
100
|
+
label="Tray Example"
|
|
101
|
+
open
|
|
102
|
+
defaultFocusElement={() => document.getElementById('my-input')}
|
|
103
|
+
>
|
|
104
|
+
Hello Tray
|
|
105
|
+
<input type="text" />
|
|
106
|
+
<input type="text" id="my-input" aria-label="my-input-label" />
|
|
107
|
+
</Tray>
|
|
108
|
+
)
|
|
109
|
+
const input = screen.getByLabelText('my-input-label')
|
|
110
|
+
|
|
111
|
+
await waitFor(() => {
|
|
112
|
+
expect(document.activeElement).toBe(input)
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
describe('transition()', () => {
|
|
117
|
+
const placements: Record<string, any> = {
|
|
118
|
+
ltr: {
|
|
119
|
+
enteringPlacements: {
|
|
120
|
+
start: 'slide-left',
|
|
121
|
+
end: 'slide-right',
|
|
122
|
+
top: 'slide-up',
|
|
123
|
+
bottom: 'slide-down'
|
|
124
|
+
},
|
|
125
|
+
exitingPlacements: {
|
|
126
|
+
start: 'slide-left',
|
|
127
|
+
end: 'slide-right',
|
|
128
|
+
top: 'slide-up',
|
|
129
|
+
bottom: 'slide-down'
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
rtl: {
|
|
133
|
+
enteringPlacements: {
|
|
134
|
+
start: 'slide-right',
|
|
135
|
+
end: 'slide-left'
|
|
136
|
+
},
|
|
137
|
+
exitingPlacements: {
|
|
138
|
+
start: 'slide-right',
|
|
139
|
+
end: 'slide-left'
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
for (const dir in placements) {
|
|
145
|
+
describe(`when text direction is '${dir}'`, () => {
|
|
146
|
+
for (const placement in placements[dir].enteringPlacements) {
|
|
147
|
+
const val = placements[dir].enteringPlacements[placement]
|
|
148
|
+
it(`returns ${val} for ${placement} when entering`, async () => {
|
|
149
|
+
const onEntered = vi.fn()
|
|
150
|
+
document.documentElement.setAttribute('dir', dir)
|
|
151
|
+
|
|
152
|
+
render(
|
|
153
|
+
<Tray
|
|
154
|
+
open
|
|
155
|
+
label="Tray Example"
|
|
156
|
+
placement={placement as TrayProps['placement']}
|
|
157
|
+
onEntered={onEntered}
|
|
158
|
+
>
|
|
159
|
+
Hello
|
|
160
|
+
</Tray>
|
|
161
|
+
)
|
|
162
|
+
await waitFor(() => {
|
|
163
|
+
expect(onEntered).toHaveBeenCalled()
|
|
164
|
+
})
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
for (const placement in placements[dir].exitingPlacements) {
|
|
169
|
+
const val = placements[dir].exitingPlacements[placement]
|
|
170
|
+
it(`returns ${val} for ${placement} when exiting`, async () => {
|
|
171
|
+
const onExited = vi.fn()
|
|
172
|
+
document.documentElement.setAttribute('dir', dir)
|
|
173
|
+
|
|
174
|
+
const { rerender } = render(
|
|
175
|
+
<Tray
|
|
176
|
+
open
|
|
177
|
+
label="Tray Example"
|
|
178
|
+
placement={placement as TrayProps['placement']}
|
|
179
|
+
onExited={onExited}
|
|
180
|
+
>
|
|
181
|
+
Hello
|
|
182
|
+
</Tray>
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
// Set prop: open
|
|
186
|
+
rerender(
|
|
187
|
+
<Tray
|
|
188
|
+
open={false}
|
|
189
|
+
label="Tray Example"
|
|
190
|
+
placement={placement as TrayProps['placement']}
|
|
191
|
+
onExited={onExited}
|
|
192
|
+
>
|
|
193
|
+
Hello
|
|
194
|
+
</Tray>
|
|
195
|
+
)
|
|
196
|
+
await waitFor(() => {
|
|
197
|
+
expect(onExited).toHaveBeenCalled()
|
|
198
|
+
})
|
|
199
|
+
})
|
|
200
|
+
}
|
|
201
|
+
})
|
|
202
|
+
}
|
|
203
|
+
})
|
|
204
|
+
})
|
package/tsconfig.build.json
CHANGED
|
@@ -21,8 +21,6 @@
|
|
|
21
21
|
{ "path": "../ui-overlays/tsconfig.build.json" },
|
|
22
22
|
{ "path": "../ui-utils/tsconfig.build.json" },
|
|
23
23
|
{ "path": "../ui-babel-preset/tsconfig.build.json" },
|
|
24
|
-
{ "path": "../ui-test-locator/tsconfig.build.json" },
|
|
25
|
-
{ "path": "../ui-test-utils/tsconfig.build.json" },
|
|
26
24
|
{ "path": "../ui-themes/tsconfig.build.json" }
|
|
27
25
|
]
|
|
28
26
|
}
|