@instructure/ui-tabs 10.19.2-snapshot-2 → 10.19.2-snapshot-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/package.json +20 -20
- package/tsconfig.build.tsbuildinfo +1 -1
- package/es/Tabs/Panel/__new-tests__/Panel.test.js +0 -50
- package/es/Tabs/Tab/__new-tests__/Tab.test.js +0 -187
- package/es/Tabs/__new-tests__/Tabs.test.js +0 -441
- package/lib/Tabs/Panel/__new-tests__/Panel.test.js +0 -51
- package/lib/Tabs/Tab/__new-tests__/Tab.test.js +0 -189
- package/lib/Tabs/__new-tests__/Tabs.test.js +0 -443
- package/src/Tabs/Panel/__new-tests__/Panel.test.tsx +0 -52
- package/src/Tabs/Tab/__new-tests__/Tab.test.tsx +0 -209
- package/src/Tabs/__new-tests__/Tabs.test.tsx +0 -430
- package/types/Tabs/Panel/__new-tests__/Panel.test.d.ts +0 -2
- package/types/Tabs/Panel/__new-tests__/Panel.test.d.ts.map +0 -1
- package/types/Tabs/Tab/__new-tests__/Tab.test.d.ts +0 -2
- package/types/Tabs/Tab/__new-tests__/Tab.test.d.ts.map +0 -1
- package/types/Tabs/__new-tests__/Tabs.test.d.ts +0 -2
- package/types/Tabs/__new-tests__/Tabs.test.d.ts.map +0 -1
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
var _Panel, _Panel2;
|
|
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 { render, screen } from '@testing-library/react';
|
|
27
|
-
import '@testing-library/jest-dom';
|
|
28
|
-
import { Panel } from '../index';
|
|
29
|
-
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
30
|
-
describe('<Tabs.Panel />', () => {
|
|
31
|
-
it('should render children', async () => {
|
|
32
|
-
render(_Panel || (_Panel = _jsx(Panel, {
|
|
33
|
-
isSelected: true,
|
|
34
|
-
renderTitle: "Panel Title",
|
|
35
|
-
children: "Panel contents"
|
|
36
|
-
})));
|
|
37
|
-
const children = screen.getByText('Panel contents');
|
|
38
|
-
expect(children).toBeInTheDocument();
|
|
39
|
-
});
|
|
40
|
-
it('should have appropriate role attribute', async () => {
|
|
41
|
-
const _render = render(_Panel2 || (_Panel2 = _jsx(Panel, {
|
|
42
|
-
isSelected: true,
|
|
43
|
-
renderTitle: "Panel Title",
|
|
44
|
-
children: "Panel contents"
|
|
45
|
-
}))),
|
|
46
|
-
container = _render.container;
|
|
47
|
-
const tabPanel = container.querySelector('[class$="-panel"]');
|
|
48
|
-
expect(tabPanel).toHaveAttribute('role', 'tabpanel');
|
|
49
|
-
});
|
|
50
|
-
});
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
var _Tab, _Tab2, _Tab3, _Tab4, _Tab5, _Tab6, _Tab7, _Tab8;
|
|
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 { render, screen, waitFor } from '@testing-library/react';
|
|
27
|
-
import { vi } from 'vitest';
|
|
28
|
-
import userEvent from '@testing-library/user-event';
|
|
29
|
-
import '@testing-library/jest-dom';
|
|
30
|
-
import { Tab } from '../index';
|
|
31
|
-
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
32
|
-
describe('<Tabs.Tab />', () => {
|
|
33
|
-
it('should render children', async () => {
|
|
34
|
-
render(_Tab || (_Tab = _jsx(Tab, {
|
|
35
|
-
id: "foo",
|
|
36
|
-
index: 0,
|
|
37
|
-
controls: "foo-panel",
|
|
38
|
-
children: "Tab Label"
|
|
39
|
-
})));
|
|
40
|
-
const children = screen.getByText('Tab Label');
|
|
41
|
-
expect(children).toBeInTheDocument();
|
|
42
|
-
});
|
|
43
|
-
it('should have appropriate role attribute', async () => {
|
|
44
|
-
render(_Tab2 || (_Tab2 = _jsx(Tab, {
|
|
45
|
-
id: "foo",
|
|
46
|
-
index: 0,
|
|
47
|
-
controls: "foo-panel",
|
|
48
|
-
children: "Tab Label"
|
|
49
|
-
})));
|
|
50
|
-
const tab = screen.getByRole('tab');
|
|
51
|
-
expect(tab).toBeInTheDocument();
|
|
52
|
-
});
|
|
53
|
-
it('should have appropriate aria attributes', async () => {
|
|
54
|
-
render(_Tab3 || (_Tab3 = _jsx(Tab, {
|
|
55
|
-
id: "foo",
|
|
56
|
-
index: 0,
|
|
57
|
-
controls: "foo-panel",
|
|
58
|
-
children: "Tab Label"
|
|
59
|
-
})));
|
|
60
|
-
const tab = screen.getByRole('tab');
|
|
61
|
-
expect(tab).not.toHaveAttribute('aria-selected');
|
|
62
|
-
expect(tab).not.toHaveAttribute('aria-disabled');
|
|
63
|
-
});
|
|
64
|
-
it('should set the aria-selected attribute', async () => {
|
|
65
|
-
render(_Tab4 || (_Tab4 = _jsx(Tab, {
|
|
66
|
-
id: "foo",
|
|
67
|
-
index: 0,
|
|
68
|
-
controls: "foo-panel",
|
|
69
|
-
isSelected: true,
|
|
70
|
-
children: "Tab Label"
|
|
71
|
-
})));
|
|
72
|
-
const tab = screen.getByRole('tab');
|
|
73
|
-
expect(tab).toHaveAttribute('aria-selected', 'true');
|
|
74
|
-
});
|
|
75
|
-
it('should set the aria-disabled attribute', async () => {
|
|
76
|
-
render(_Tab5 || (_Tab5 = _jsx(Tab, {
|
|
77
|
-
id: "foo",
|
|
78
|
-
index: 0,
|
|
79
|
-
controls: "foo-panel",
|
|
80
|
-
isDisabled: true,
|
|
81
|
-
children: "Tab Label"
|
|
82
|
-
})));
|
|
83
|
-
const tab = screen.getByRole('tab');
|
|
84
|
-
expect(tab).toHaveAttribute('aria-disabled', 'true');
|
|
85
|
-
});
|
|
86
|
-
it('should set the tabindex to 0 when selected', async () => {
|
|
87
|
-
render(_Tab6 || (_Tab6 = _jsx(Tab, {
|
|
88
|
-
id: "foo",
|
|
89
|
-
index: 0,
|
|
90
|
-
controls: "foo-panel",
|
|
91
|
-
isSelected: true,
|
|
92
|
-
children: "Tab Label"
|
|
93
|
-
})));
|
|
94
|
-
const tab = screen.getByRole('tab');
|
|
95
|
-
expect(tab).toHaveAttribute('tabindex', '0');
|
|
96
|
-
});
|
|
97
|
-
it('should not set the tabindex when not selected', async () => {
|
|
98
|
-
render(_Tab7 || (_Tab7 = _jsx(Tab, {
|
|
99
|
-
id: "foo",
|
|
100
|
-
index: 0,
|
|
101
|
-
controls: "foo-panel",
|
|
102
|
-
children: "Tab Label"
|
|
103
|
-
})));
|
|
104
|
-
const tab = screen.getByRole('tab');
|
|
105
|
-
expect(tab).not.toHaveAttribute('tabindex');
|
|
106
|
-
});
|
|
107
|
-
it('should remove the tabindex attribute when disabled', async () => {
|
|
108
|
-
render(_Tab8 || (_Tab8 = _jsx(Tab, {
|
|
109
|
-
id: "foo",
|
|
110
|
-
index: 0,
|
|
111
|
-
controls: "foo-panel",
|
|
112
|
-
isDisabled: true,
|
|
113
|
-
children: "Tab Label"
|
|
114
|
-
})));
|
|
115
|
-
const tab = screen.getByRole('tab');
|
|
116
|
-
expect(tab).not.toHaveAttribute('tabindex');
|
|
117
|
-
});
|
|
118
|
-
it('should call onClick when clicked', async () => {
|
|
119
|
-
const onClick = vi.fn();
|
|
120
|
-
const index = 2;
|
|
121
|
-
render(_jsx(Tab, {
|
|
122
|
-
id: "foo",
|
|
123
|
-
index: index,
|
|
124
|
-
controls: "foo-panel",
|
|
125
|
-
onClick: onClick,
|
|
126
|
-
children: "Tab Label"
|
|
127
|
-
}));
|
|
128
|
-
const tab = screen.getByRole('tab');
|
|
129
|
-
await userEvent.click(tab);
|
|
130
|
-
await waitFor(() => {
|
|
131
|
-
expect(onClick).toHaveBeenCalled();
|
|
132
|
-
const args = onClick.mock.calls[0][1];
|
|
133
|
-
expect(args).toHaveProperty('index', index);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
it('should NOT call onClick when clicked and tab is disabled', async () => {
|
|
137
|
-
const onClick = vi.fn();
|
|
138
|
-
render(_jsx(Tab, {
|
|
139
|
-
id: "foo",
|
|
140
|
-
index: 0,
|
|
141
|
-
controls: "foo-panel",
|
|
142
|
-
onClick: onClick,
|
|
143
|
-
isDisabled: true,
|
|
144
|
-
children: "Tab Label"
|
|
145
|
-
}));
|
|
146
|
-
const tab = screen.getByRole('tab');
|
|
147
|
-
await userEvent.click(tab);
|
|
148
|
-
await waitFor(() => {
|
|
149
|
-
expect(onClick).not.toHaveBeenCalled();
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
it('should call onKeyDown when keys are pressed and tab is selected', async () => {
|
|
153
|
-
const onKeyDown = vi.fn();
|
|
154
|
-
const index = 2;
|
|
155
|
-
render(_jsx(Tab, {
|
|
156
|
-
id: "foo",
|
|
157
|
-
isSelected: true,
|
|
158
|
-
index: index,
|
|
159
|
-
controls: "foo-panel",
|
|
160
|
-
onKeyDown: onKeyDown,
|
|
161
|
-
children: "Tab Label"
|
|
162
|
-
}));
|
|
163
|
-
const tab = screen.getByRole('tab');
|
|
164
|
-
await userEvent.type(tab, '{enter}');
|
|
165
|
-
await waitFor(() => {
|
|
166
|
-
expect(onKeyDown).toHaveBeenCalled();
|
|
167
|
-
const args = onKeyDown.mock.calls[0][1];
|
|
168
|
-
expect(args).toHaveProperty('index', index);
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
it('should NOT call onKeyDown when keys are pressed and tab is disabled', async () => {
|
|
172
|
-
const onKeyDown = vi.fn();
|
|
173
|
-
render(_jsx(Tab, {
|
|
174
|
-
id: "foo",
|
|
175
|
-
index: 0,
|
|
176
|
-
controls: "foo-panel",
|
|
177
|
-
onKeyDown: onKeyDown,
|
|
178
|
-
isDisabled: true,
|
|
179
|
-
children: "Tab Label"
|
|
180
|
-
}));
|
|
181
|
-
const tab = screen.getByRole('tab');
|
|
182
|
-
await userEvent.type(tab, '{enter}');
|
|
183
|
-
await waitFor(() => {
|
|
184
|
-
expect(onKeyDown).not.toHaveBeenCalled();
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
});
|
|
@@ -1,441 +0,0 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
var _p, _Tabs, _Tabs2, _Tabs3, _Tabs4, _Tabs5, _Tabs6, _Tabs9, _Tabs$Panel, _Tabs$Panel2, _Tabs$Panel3, _Tabs10, _Tabs$Panel4, _Tabs$Panel5, _Tabs$Panel6, _Tabs11, _Tabs12, _Tabs13, _Tabs14, _Tabs15;
|
|
3
|
-
/*
|
|
4
|
-
* The MIT License (MIT)
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
7
|
-
*
|
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
* furnished to do so, subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
-
* copies or substantial portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
-
* SOFTWARE.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
import { useState } from 'react';
|
|
28
|
-
import { render, screen, waitFor } from '@testing-library/react';
|
|
29
|
-
import { vi } from 'vitest';
|
|
30
|
-
import userEvent from '@testing-library/user-event';
|
|
31
|
-
import '@testing-library/jest-dom';
|
|
32
|
-
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
33
|
-
import { Tabs } from '../index';
|
|
34
|
-
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
35
|
-
const TabExample = props => {
|
|
36
|
-
const _useState = useState(0),
|
|
37
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
38
|
-
selectedIndex = _useState2[0],
|
|
39
|
-
setSelectedIndex = _useState2[1];
|
|
40
|
-
return _jsxs(Tabs, {
|
|
41
|
-
onRequestTabChange: (_event, {
|
|
42
|
-
index
|
|
43
|
-
}) => {
|
|
44
|
-
setSelectedIndex(index);
|
|
45
|
-
props.onIndexChange(index);
|
|
46
|
-
},
|
|
47
|
-
variant: "default",
|
|
48
|
-
margin: "medium",
|
|
49
|
-
children: [_jsx(Tabs.Panel, {
|
|
50
|
-
renderTitle: "First Tab",
|
|
51
|
-
id: "first",
|
|
52
|
-
isSelected: selectedIndex === 0,
|
|
53
|
-
active: true,
|
|
54
|
-
children: _p || (_p = _jsx("p", {
|
|
55
|
-
children: "CONTENT"
|
|
56
|
-
}))
|
|
57
|
-
}), _jsx(Tabs.Panel, {
|
|
58
|
-
renderTitle: "Second Tab",
|
|
59
|
-
id: "second",
|
|
60
|
-
isSelected: selectedIndex === 1
|
|
61
|
-
}), _jsx(Tabs.Panel, {
|
|
62
|
-
renderTitle: "Third Tab",
|
|
63
|
-
id: "third",
|
|
64
|
-
isSelected: selectedIndex === 2
|
|
65
|
-
})]
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
describe('<Tabs />', () => {
|
|
69
|
-
var _Tabs7, _Tabs8;
|
|
70
|
-
const tab1Content = 'Tab 1 content';
|
|
71
|
-
const tab2Content = 'Tab 2 content';
|
|
72
|
-
const tab3Content = 'Tab 3 content';
|
|
73
|
-
let consoleErrorMock;
|
|
74
|
-
let consoleWarningMock;
|
|
75
|
-
beforeEach(() => {
|
|
76
|
-
// Mocking console to prevent test output pollution and expect for messages
|
|
77
|
-
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
78
|
-
consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
79
|
-
});
|
|
80
|
-
afterEach(() => {
|
|
81
|
-
consoleErrorMock.mockRestore();
|
|
82
|
-
consoleWarningMock.mockRestore();
|
|
83
|
-
});
|
|
84
|
-
it('should render the correct number of panels', () => {
|
|
85
|
-
const _render = render(_Tabs || (_Tabs = _jsxs(Tabs, {
|
|
86
|
-
children: [_jsx(Tabs.Panel, {
|
|
87
|
-
renderTitle: "First Tab",
|
|
88
|
-
children: "Tab 1 content"
|
|
89
|
-
}), _jsx(Tabs.Panel, {
|
|
90
|
-
renderTitle: "Second Tab",
|
|
91
|
-
children: "Tab 2 content"
|
|
92
|
-
}), _jsx(Tabs.Panel, {
|
|
93
|
-
renderTitle: "Third Tab",
|
|
94
|
-
isDisabled: true,
|
|
95
|
-
children: "Tab 3 content"
|
|
96
|
-
})]
|
|
97
|
-
}))),
|
|
98
|
-
container = _render.container;
|
|
99
|
-
const panels = container.querySelectorAll('[role="tabpanel"]');
|
|
100
|
-
expect(panels.length).toBe(3);
|
|
101
|
-
});
|
|
102
|
-
it('should render with null children', async () => {
|
|
103
|
-
const _render2 = render(_Tabs2 || (_Tabs2 = _jsxs(Tabs, {
|
|
104
|
-
children: [_jsx(Tabs.Panel, {
|
|
105
|
-
renderTitle: "First Tab",
|
|
106
|
-
children: "Tab 1 content"
|
|
107
|
-
}), _jsx(Tabs.Panel, {
|
|
108
|
-
renderTitle: "Second Tab",
|
|
109
|
-
children: "Tab 2 content"
|
|
110
|
-
}), _jsx(Tabs.Panel, {
|
|
111
|
-
renderTitle: "Third Tab",
|
|
112
|
-
isDisabled: true,
|
|
113
|
-
children: "Tab 3 content"
|
|
114
|
-
}), null]
|
|
115
|
-
}))),
|
|
116
|
-
container = _render2.container;
|
|
117
|
-
const panels = container.querySelectorAll('[role="tabpanel"]');
|
|
118
|
-
expect(panels.length).toBe(3);
|
|
119
|
-
});
|
|
120
|
-
it('should be okay with rendering without any children', async () => {
|
|
121
|
-
render(_Tabs3 || (_Tabs3 = _jsx(Tabs, {})));
|
|
122
|
-
expect(consoleErrorMock).not.toHaveBeenCalled();
|
|
123
|
-
});
|
|
124
|
-
it('should render correct number of tabs', async () => {
|
|
125
|
-
render(_Tabs4 || (_Tabs4 = _jsxs(Tabs, {
|
|
126
|
-
children: [_jsx(Tabs.Panel, {
|
|
127
|
-
renderTitle: "First Tab",
|
|
128
|
-
children: "Tab 1 content"
|
|
129
|
-
}), _jsx(Tabs.Panel, {
|
|
130
|
-
renderTitle: "Second Tab",
|
|
131
|
-
children: "Tab 2 content"
|
|
132
|
-
}), _jsx(Tabs.Panel, {
|
|
133
|
-
renderTitle: "Third Tab",
|
|
134
|
-
isDisabled: true,
|
|
135
|
-
children: "Tab 3 content"
|
|
136
|
-
})]
|
|
137
|
-
})));
|
|
138
|
-
const tabs = screen.getAllByRole('tab');
|
|
139
|
-
expect(tabs.length).toBe(3);
|
|
140
|
-
});
|
|
141
|
-
it('should render same content for other tabs as for the active one', () => {
|
|
142
|
-
const _render3 = render(_Tabs5 || (_Tabs5 = _jsxs(Tabs, {
|
|
143
|
-
children: [_jsx(Tabs.Panel, {
|
|
144
|
-
renderTitle: "First Tab",
|
|
145
|
-
active: true,
|
|
146
|
-
children: "CONTENT"
|
|
147
|
-
}), _jsx(Tabs.Panel, {
|
|
148
|
-
id: "secondTab",
|
|
149
|
-
renderTitle: "Second Tab",
|
|
150
|
-
isSelected: true,
|
|
151
|
-
children: "Child"
|
|
152
|
-
}), _jsx(Tabs.Panel, {
|
|
153
|
-
renderTitle: "Third Tab",
|
|
154
|
-
children: "Child"
|
|
155
|
-
})]
|
|
156
|
-
}))),
|
|
157
|
-
container = _render3.container;
|
|
158
|
-
const tabContent = screen.getByText('CONTENT');
|
|
159
|
-
expect(container).toBeInTheDocument();
|
|
160
|
-
expect(tabContent).toBeInTheDocument();
|
|
161
|
-
const childContent = screen.queryByText('Child');
|
|
162
|
-
expect(childContent).toBeNull();
|
|
163
|
-
});
|
|
164
|
-
it('should render the same content in second tab when selected', async () => {
|
|
165
|
-
const onIndexChange = vi.fn();
|
|
166
|
-
const _render4 = render(_jsx(TabExample, {
|
|
167
|
-
onIndexChange: onIndexChange
|
|
168
|
-
})),
|
|
169
|
-
container = _render4.container;
|
|
170
|
-
expect(container).toBeInTheDocument();
|
|
171
|
-
const secondTab = screen.getAllByRole('tab')[1];
|
|
172
|
-
await userEvent.click(secondTab);
|
|
173
|
-
await waitFor(() => {
|
|
174
|
-
expect(onIndexChange).toHaveBeenCalledWith(1);
|
|
175
|
-
});
|
|
176
|
-
const panelContent = screen.queryByText('CONTENT');
|
|
177
|
-
expect(panelContent).toBeInTheDocument();
|
|
178
|
-
});
|
|
179
|
-
it('should warn if multiple active tabs exist', () => {
|
|
180
|
-
const _render5 = render(_Tabs6 || (_Tabs6 = _jsxs(Tabs, {
|
|
181
|
-
children: [_jsx(Tabs.Panel, {
|
|
182
|
-
renderTitle: "First Tab",
|
|
183
|
-
active: true,
|
|
184
|
-
children: "Tab 1 content"
|
|
185
|
-
}), _jsx(Tabs.Panel, {
|
|
186
|
-
renderTitle: "Second Tab",
|
|
187
|
-
active: true,
|
|
188
|
-
children: "Tab 2 content"
|
|
189
|
-
}), _jsx(Tabs.Panel, {
|
|
190
|
-
renderTitle: "Third Tab",
|
|
191
|
-
isDisabled: true,
|
|
192
|
-
children: "Tab 3 content"
|
|
193
|
-
})]
|
|
194
|
-
}))),
|
|
195
|
-
container = _render5.container;
|
|
196
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
197
|
-
expect(consoleErrorMock.mock.calls[0][0]).toEqual('Warning: [Tabs] Only one Panel can be marked as active.');
|
|
198
|
-
});
|
|
199
|
-
it('should default to selecting the first tab', async () => {
|
|
200
|
-
const _render6 = render(_Tabs7 || (_Tabs7 = _jsxs(Tabs, {
|
|
201
|
-
children: [_jsx(Tabs.Panel, {
|
|
202
|
-
renderTitle: "First Tab",
|
|
203
|
-
children: tab1Content
|
|
204
|
-
}), _jsx(Tabs.Panel, {
|
|
205
|
-
renderTitle: "Second Tab",
|
|
206
|
-
children: tab2Content
|
|
207
|
-
}), _jsx(Tabs.Panel, {
|
|
208
|
-
renderTitle: "Third Tab",
|
|
209
|
-
isDisabled: true,
|
|
210
|
-
children: tab3Content
|
|
211
|
-
})]
|
|
212
|
-
}))),
|
|
213
|
-
container = _render6.container;
|
|
214
|
-
const panelsContainer = container.querySelector('[class$="panelsContainer"]');
|
|
215
|
-
expect(panelsContainer).toHaveTextContent(tab1Content);
|
|
216
|
-
expect(screen.getByText(tab1Content)).toBeVisible();
|
|
217
|
-
expect(panelsContainer).not.toHaveTextContent(tab2Content);
|
|
218
|
-
expect(panelsContainer).not.toHaveTextContent(tab3Content);
|
|
219
|
-
});
|
|
220
|
-
it('should honor the isSelected prop', async () => {
|
|
221
|
-
const _render7 = render(_Tabs8 || (_Tabs8 = _jsxs(Tabs, {
|
|
222
|
-
children: [_jsx(Tabs.Panel, {
|
|
223
|
-
renderTitle: "First Tab",
|
|
224
|
-
children: tab1Content
|
|
225
|
-
}), _jsx(Tabs.Panel, {
|
|
226
|
-
renderTitle: "Second Tab",
|
|
227
|
-
isSelected: true,
|
|
228
|
-
children: tab2Content
|
|
229
|
-
}), _jsx(Tabs.Panel, {
|
|
230
|
-
renderTitle: "Third Tab",
|
|
231
|
-
isDisabled: true,
|
|
232
|
-
children: tab3Content
|
|
233
|
-
})]
|
|
234
|
-
}))),
|
|
235
|
-
container = _render7.container;
|
|
236
|
-
const panelsContainer = container.querySelector('[class$="panelsContainer"]');
|
|
237
|
-
expect(panelsContainer).toHaveTextContent(tab2Content);
|
|
238
|
-
expect(screen.getByText(tab2Content)).toBeVisible();
|
|
239
|
-
expect(panelsContainer).not.toHaveTextContent(tab1Content);
|
|
240
|
-
expect(panelsContainer).not.toHaveTextContent(tab3Content);
|
|
241
|
-
});
|
|
242
|
-
it('should not allow selecting a disabled tab', async () => {
|
|
243
|
-
const _render8 = render(_Tabs9 || (_Tabs9 = _jsxs(Tabs, {
|
|
244
|
-
children: [_jsx(Tabs.Panel, {
|
|
245
|
-
renderTitle: "First Tab",
|
|
246
|
-
children: "Tab 1 content"
|
|
247
|
-
}), _jsx(Tabs.Panel, {
|
|
248
|
-
renderTitle: "Second Tab",
|
|
249
|
-
children: "Tab 2 content"
|
|
250
|
-
}), _jsx(Tabs.Panel, {
|
|
251
|
-
renderTitle: "Third Tab",
|
|
252
|
-
isDisabled: true,
|
|
253
|
-
isSelected: true,
|
|
254
|
-
children: "Tab 3 content"
|
|
255
|
-
})]
|
|
256
|
-
}))),
|
|
257
|
-
container = _render8.container;
|
|
258
|
-
const panelsContainer = container.querySelector('[class$="panelsContainer"]');
|
|
259
|
-
const panels = container.querySelectorAll('[role="tabpanel"]');
|
|
260
|
-
expect(panelsContainer).toHaveTextContent(tab1Content);
|
|
261
|
-
expect(screen.getByText(tab1Content)).toBeVisible();
|
|
262
|
-
expect(panelsContainer).not.toHaveTextContent(tab2Content);
|
|
263
|
-
expect(panelsContainer).not.toHaveTextContent(tab3Content);
|
|
264
|
-
expect(panels.length).toBe(3);
|
|
265
|
-
expect(panels[0]).not.toHaveAttribute('aria-hidden', 'true');
|
|
266
|
-
expect(panels[1]).toHaveAttribute('aria-hidden', 'true');
|
|
267
|
-
expect(panels[2]).toHaveAttribute('aria-hidden', 'true');
|
|
268
|
-
});
|
|
269
|
-
it('should call onRequestTabChange when selection changes via click', async () => {
|
|
270
|
-
const onChange = vi.fn();
|
|
271
|
-
render(_jsxs(Tabs, {
|
|
272
|
-
onRequestTabChange: onChange,
|
|
273
|
-
children: [_Tabs$Panel || (_Tabs$Panel = _jsx(Tabs.Panel, {
|
|
274
|
-
renderTitle: "First Tab",
|
|
275
|
-
isSelected: true,
|
|
276
|
-
id: "one",
|
|
277
|
-
children: "Tab 1 content"
|
|
278
|
-
})), _Tabs$Panel2 || (_Tabs$Panel2 = _jsx(Tabs.Panel, {
|
|
279
|
-
renderTitle: "Second Tab",
|
|
280
|
-
id: "two",
|
|
281
|
-
children: "Tab 2 content"
|
|
282
|
-
})), _Tabs$Panel3 || (_Tabs$Panel3 = _jsx(Tabs.Panel, {
|
|
283
|
-
renderTitle: "Third Tab",
|
|
284
|
-
isDisabled: true,
|
|
285
|
-
id: "three",
|
|
286
|
-
children: "Tab 3 content"
|
|
287
|
-
}))]
|
|
288
|
-
}));
|
|
289
|
-
const secondTab = screen.getByText('Second Tab');
|
|
290
|
-
await userEvent.click(secondTab);
|
|
291
|
-
await waitFor(() => {
|
|
292
|
-
expect(onChange).toHaveBeenCalled();
|
|
293
|
-
const args = onChange.mock.calls[0][1];
|
|
294
|
-
expect(args).toHaveProperty('index', 1);
|
|
295
|
-
expect(args).toHaveProperty('id', 'two');
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
it('should focus the selected tab when shouldFocusOnRender is set', async () => {
|
|
299
|
-
render(_Tabs10 || (_Tabs10 = _jsxs(Tabs, {
|
|
300
|
-
shouldFocusOnRender: true,
|
|
301
|
-
children: [_jsx(Tabs.Panel, {
|
|
302
|
-
renderTitle: "First Tab",
|
|
303
|
-
children: "Tab 1 content"
|
|
304
|
-
}), _jsx(Tabs.Panel, {
|
|
305
|
-
renderTitle: "Second Tab",
|
|
306
|
-
isSelected: true,
|
|
307
|
-
children: "Tab 2 content"
|
|
308
|
-
}), _jsx(Tabs.Panel, {
|
|
309
|
-
renderTitle: "Third Tab",
|
|
310
|
-
isDisabled: true,
|
|
311
|
-
children: "Tab 3 content"
|
|
312
|
-
})]
|
|
313
|
-
})));
|
|
314
|
-
const secondTab = screen.getByText('Second Tab');
|
|
315
|
-
await waitFor(() => {
|
|
316
|
-
expect(document.activeElement).toBe(secondTab);
|
|
317
|
-
});
|
|
318
|
-
});
|
|
319
|
-
it('should not call onRequestTabChange when clicking a disabled tab', async () => {
|
|
320
|
-
const onChange = vi.fn();
|
|
321
|
-
render(_jsxs(Tabs, {
|
|
322
|
-
onRequestTabChange: onChange,
|
|
323
|
-
children: [_Tabs$Panel4 || (_Tabs$Panel4 = _jsx(Tabs.Panel, {
|
|
324
|
-
renderTitle: "First Tab",
|
|
325
|
-
children: "Tab 1 content"
|
|
326
|
-
})), _Tabs$Panel5 || (_Tabs$Panel5 = _jsx(Tabs.Panel, {
|
|
327
|
-
renderTitle: "Second Tab",
|
|
328
|
-
children: "Tab 2 content"
|
|
329
|
-
})), _Tabs$Panel6 || (_Tabs$Panel6 = _jsx(Tabs.Panel, {
|
|
330
|
-
renderTitle: "Third Tab",
|
|
331
|
-
isDisabled: true,
|
|
332
|
-
children: "Tab 3 content"
|
|
333
|
-
}))]
|
|
334
|
-
}));
|
|
335
|
-
const thirdTab = screen.getByText('Third Tab');
|
|
336
|
-
await userEvent.click(thirdTab);
|
|
337
|
-
await waitFor(() => {
|
|
338
|
-
expect(onChange).not.toHaveBeenCalled();
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
it('should meet a11y standards when set to the secondary variant', async () => {
|
|
342
|
-
const _render9 = render(_Tabs11 || (_Tabs11 = _jsxs(Tabs, {
|
|
343
|
-
variant: "secondary",
|
|
344
|
-
children: [_jsx(Tabs.Panel, {
|
|
345
|
-
renderTitle: "First Tab",
|
|
346
|
-
children: "Tab 1 content"
|
|
347
|
-
}), _jsx(Tabs.Panel, {
|
|
348
|
-
renderTitle: "Second Tab",
|
|
349
|
-
children: "Tab 2 content"
|
|
350
|
-
}), _jsx(Tabs.Panel, {
|
|
351
|
-
renderTitle: "Third Tab",
|
|
352
|
-
isDisabled: true,
|
|
353
|
-
children: "Tab 3 content"
|
|
354
|
-
})]
|
|
355
|
-
}))),
|
|
356
|
-
container = _render9.container;
|
|
357
|
-
const axeCheck = await runAxeCheck(container);
|
|
358
|
-
expect(axeCheck).toBe(true);
|
|
359
|
-
});
|
|
360
|
-
it('should meet a11y standards when set to the default variant', async () => {
|
|
361
|
-
const _render10 = render(_Tabs12 || (_Tabs12 = _jsxs(Tabs, {
|
|
362
|
-
variant: "default",
|
|
363
|
-
children: [_jsx(Tabs.Panel, {
|
|
364
|
-
renderTitle: "First Tab",
|
|
365
|
-
children: "Tab 1 content"
|
|
366
|
-
}), _jsx(Tabs.Panel, {
|
|
367
|
-
renderTitle: "Second Tab",
|
|
368
|
-
children: "Tab 2 content"
|
|
369
|
-
}), _jsx(Tabs.Panel, {
|
|
370
|
-
renderTitle: "Third Tab",
|
|
371
|
-
isDisabled: true,
|
|
372
|
-
children: "Tab 3 content"
|
|
373
|
-
})]
|
|
374
|
-
}))),
|
|
375
|
-
container = _render10.container;
|
|
376
|
-
const axeCheck = await runAxeCheck(container);
|
|
377
|
-
expect(axeCheck).toBe(true);
|
|
378
|
-
});
|
|
379
|
-
it('should link tabs with the corresponding panels via ids', async () => {
|
|
380
|
-
const _render11 = render(_Tabs13 || (_Tabs13 = _jsxs(Tabs, {
|
|
381
|
-
children: [_jsx(Tabs.Panel, {
|
|
382
|
-
renderTitle: "First Tab",
|
|
383
|
-
children: "Tab 1 content"
|
|
384
|
-
}), _jsx(Tabs.Panel, {
|
|
385
|
-
renderTitle: "Second Tab",
|
|
386
|
-
children: "Tab 2 content"
|
|
387
|
-
}), _jsx(Tabs.Panel, {
|
|
388
|
-
renderTitle: "Third Tab",
|
|
389
|
-
isDisabled: true,
|
|
390
|
-
children: "Tab 3 content"
|
|
391
|
-
})]
|
|
392
|
-
}))),
|
|
393
|
-
container = _render11.container;
|
|
394
|
-
const firstTab = screen.getByText('First Tab');
|
|
395
|
-
const firstPanel = container.querySelectorAll('[role="tabpanel"]')[0];
|
|
396
|
-
expect(firstTab).toHaveAttribute('aria-controls', firstPanel.id);
|
|
397
|
-
expect(firstPanel).toHaveAttribute('aria-labelledby', firstTab.id);
|
|
398
|
-
});
|
|
399
|
-
describe('with duplicate-named tabs', () => {
|
|
400
|
-
it('should still render the correct number of panels', async () => {
|
|
401
|
-
const _render12 = render(_Tabs14 || (_Tabs14 = _jsxs(Tabs, {
|
|
402
|
-
children: [_jsx(Tabs.Panel, {
|
|
403
|
-
renderTitle: "A Tab",
|
|
404
|
-
children: "Contents of first tab."
|
|
405
|
-
}), _jsx(Tabs.Panel, {
|
|
406
|
-
renderTitle: "A Tab",
|
|
407
|
-
children: "Contents of second tab."
|
|
408
|
-
}), _jsx(Tabs.Panel, {
|
|
409
|
-
renderTitle: "A Tab",
|
|
410
|
-
isDisabled: true,
|
|
411
|
-
children: "Contents of third tab."
|
|
412
|
-
})]
|
|
413
|
-
}))),
|
|
414
|
-
container = _render12.container;
|
|
415
|
-
const tabPanels = container.querySelectorAll('[role="tabpanel"]');
|
|
416
|
-
expect(tabPanels.length).toBe(3);
|
|
417
|
-
});
|
|
418
|
-
});
|
|
419
|
-
describe('with nodes as tab titles', () => {
|
|
420
|
-
it('should still render the correct number of panels', async () => {
|
|
421
|
-
const _render13 = render(_Tabs15 || (_Tabs15 = _jsxs(Tabs, {
|
|
422
|
-
children: [_jsx(Tabs.Panel, {
|
|
423
|
-
renderTitle: _jsx("div", {}),
|
|
424
|
-
children: "Contents of first tab."
|
|
425
|
-
}), _jsx(Tabs.Panel, {
|
|
426
|
-
renderTitle: _jsx("span", {}),
|
|
427
|
-
children: "Contents of second tab."
|
|
428
|
-
}), _jsx(Tabs.Panel, {
|
|
429
|
-
renderTitle: _jsx("img", {
|
|
430
|
-
alt: "example"
|
|
431
|
-
}),
|
|
432
|
-
isDisabled: true,
|
|
433
|
-
children: "Contents of third tab."
|
|
434
|
-
})]
|
|
435
|
-
}))),
|
|
436
|
-
container = _render13.container;
|
|
437
|
-
const tabPanels = container.querySelectorAll('[role="tabpanel"]');
|
|
438
|
-
expect(tabPanels.length).toBe(3);
|
|
439
|
-
});
|
|
440
|
-
});
|
|
441
|
-
});
|