uikit-react-public 0.50.5 → 0.50.6
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/dist/components/ToggleGroup/ToggleGroup.d.ts +5 -3
- package/dist/components/ToggleGroup/ToggleGroup.stories.d.ts +2 -2
- package/dist/components/ToggleGroup/ToggleGroupContext.d.ts +2 -0
- package/dist/components/ToggleGroup/index.d.ts +1 -2
- package/dist/components/ToggleGroup/subcomponents/ToggleGroupItem.d.ts +13 -0
- package/dist/components/ToggleGroup/subcomponents/{Item.stories.d.ts → ToggleGroupItem.stories.d.ts} +2 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/index.js +5126 -5045
- package/lib/components/ToggleGroup/ToggleGroup.tsx +51 -10
- package/lib/components/ToggleGroup/ToggleGroupContext.tsx +2 -0
- package/lib/components/ToggleGroup/__tests__/ToggleGroup.test.tsx +105 -6
- package/lib/components/ToggleGroup/index.ts +1 -2
- package/lib/components/ToggleGroup/subcomponents/{Item.stories.tsx → ToggleGroupItem.stories.tsx} +2 -3
- package/lib/components/ToggleGroup/subcomponents/{Item.tsx → ToggleGroupItem.tsx} +126 -52
- package/lib/components/ToggleGroup/subcomponents/__tests__/{Item.test.tsx → ToggleGroupItem.test.tsx} +50 -6
- package/lib/components/index.ts +1 -1
- package/package.json +1 -1
- package/dist/components/ToggleGroup/subcomponents/Item.d.ts +0 -11
- /package/dist/components/ToggleGroup/subcomponents/__tests__/{Item.test.d.ts → ToggleGroupItem.test.d.ts} +0 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { describe, expect, test, vi } from 'vitest';
|
|
2
2
|
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
3
|
import ToggleGroup from '../../ToggleGroup';
|
|
4
|
-
import ToggleGroupItem from '../Item';
|
|
5
4
|
import { ThemeContextProvider } from '../../../../theme/useTheme';
|
|
6
5
|
|
|
6
|
+
const ToggleGroupItem = ToggleGroup.Item;
|
|
7
|
+
|
|
7
8
|
const wrap = (ui: React.ReactElement) =>
|
|
8
9
|
render(<ThemeContextProvider>{ui}</ThemeContextProvider>);
|
|
9
10
|
|
|
@@ -20,8 +21,10 @@ describe('ToggleGroupItem', () => {
|
|
|
20
21
|
|
|
21
22
|
const item = screen.getByRole('radio', { name: 'Option 1' });
|
|
22
23
|
|
|
24
|
+
expect(item).toHaveAttribute('data-testid', 'ucl-uikit-toggle-group__item');
|
|
25
|
+
expect(item).toHaveClass('ucl-uikit-toggle-group__item');
|
|
23
26
|
expect(item).toHaveAttribute('aria-checked', 'false');
|
|
24
|
-
expect(item).toHaveAttribute('tabindex', '
|
|
27
|
+
expect(item).toHaveAttribute('tabindex', '0');
|
|
25
28
|
});
|
|
26
29
|
|
|
27
30
|
test('reflects selection state from the surrounding ToggleGroup', () => {
|
|
@@ -54,6 +57,7 @@ describe('ToggleGroupItem', () => {
|
|
|
54
57
|
|
|
55
58
|
test('calls setValue via the ToggleGroup on click', () => {
|
|
56
59
|
const onValueChange = vi.fn();
|
|
60
|
+
const onChange = vi.fn();
|
|
57
61
|
|
|
58
62
|
wrap(
|
|
59
63
|
<ToggleGroup
|
|
@@ -67,13 +71,23 @@ describe('ToggleGroupItem', () => {
|
|
|
67
71
|
<ToggleGroupItem
|
|
68
72
|
value='option-2'
|
|
69
73
|
label='Option 2'
|
|
74
|
+
className='custom-toggle-group-item'
|
|
75
|
+
onChange={onChange}
|
|
76
|
+
testId='option-2'
|
|
70
77
|
/>
|
|
71
78
|
</ToggleGroup>
|
|
72
79
|
);
|
|
73
80
|
|
|
74
|
-
|
|
81
|
+
const option2 = screen.getByRole('radio', { name: 'Option 2' });
|
|
82
|
+
fireEvent.click(option2);
|
|
75
83
|
|
|
84
|
+
expect(option2).toHaveAttribute('data-testid', 'option-2');
|
|
85
|
+
expect(option2).toHaveClass(
|
|
86
|
+
'ucl-uikit-toggle-group__item',
|
|
87
|
+
'custom-toggle-group-item'
|
|
88
|
+
);
|
|
76
89
|
expect(onValueChange).toHaveBeenCalledWith('option-2');
|
|
90
|
+
expect(onChange).toHaveBeenCalledOnce();
|
|
77
91
|
});
|
|
78
92
|
|
|
79
93
|
test('does not select or fire onValueChange when disabled', () => {
|
|
@@ -168,7 +182,7 @@ describe('ToggleGroupItem', () => {
|
|
|
168
182
|
).toBeInTheDocument();
|
|
169
183
|
});
|
|
170
184
|
|
|
171
|
-
test('
|
|
185
|
+
test('reserves checkmark space without showing it on unselected items', () => {
|
|
172
186
|
wrap(
|
|
173
187
|
<ToggleGroup defaultValue='option-1'>
|
|
174
188
|
<ToggleGroupItem
|
|
@@ -189,7 +203,37 @@ describe('ToggleGroupItem', () => {
|
|
|
189
203
|
.getByRole('radio', { name: 'Option 2' })
|
|
190
204
|
.closest('label');
|
|
191
205
|
|
|
192
|
-
|
|
193
|
-
|
|
206
|
+
const selectedCheckmark = selected!.lastElementChild!.querySelector('svg')!;
|
|
207
|
+
const unselectedCheckmark =
|
|
208
|
+
unselected!.lastElementChild!.querySelector('svg')!;
|
|
209
|
+
|
|
210
|
+
expect(selected!.querySelectorAll('svg')).toHaveLength(2);
|
|
211
|
+
expect(unselected!.querySelectorAll('svg')).toHaveLength(2);
|
|
212
|
+
expect(selectedCheckmark).toHaveStyle({ visibility: 'visible' });
|
|
213
|
+
expect(unselectedCheckmark).toHaveStyle({ visibility: 'hidden' });
|
|
214
|
+
expect(selected!.lastElementChild).toHaveStyle({
|
|
215
|
+
justifyContent: 'center',
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test('aligns sublabel content between the item edges', () => {
|
|
220
|
+
wrap(
|
|
221
|
+
<ToggleGroup defaultValue='option-1'>
|
|
222
|
+
<ToggleGroupItem
|
|
223
|
+
value='option-1'
|
|
224
|
+
label='Option 1'
|
|
225
|
+
sublabel='Sublabel 1'
|
|
226
|
+
icon='BookOpen'
|
|
227
|
+
/>
|
|
228
|
+
</ToggleGroup>
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
const item = screen
|
|
232
|
+
.getByRole('radio', { name: 'Option 1 Sublabel 1' })
|
|
233
|
+
.closest('label');
|
|
234
|
+
|
|
235
|
+
expect(item!.lastElementChild).toHaveStyle({
|
|
236
|
+
justifyContent: 'space-between',
|
|
237
|
+
});
|
|
194
238
|
});
|
|
195
239
|
});
|
package/lib/components/index.ts
CHANGED
|
@@ -142,7 +142,7 @@ export { default as Toggle } from './Toggle';
|
|
|
142
142
|
export type { ToggleProps } from './Toggle';
|
|
143
143
|
|
|
144
144
|
export { default as ToggleGroup } from './ToggleGroup';
|
|
145
|
-
export type {
|
|
145
|
+
export type { ToggleGroupItemProps, ToggleGroupProps } from './ToggleGroup';
|
|
146
146
|
|
|
147
147
|
export { default as Chip } from './Chip';
|
|
148
148
|
export type { ChipProps } from './Chip';
|
package/package.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { InputHTMLAttributes } from 'react';
|
|
2
|
-
import { SpecificIconsType } from '../../Icon/Icon';
|
|
3
|
-
export interface ItemProps extends InputHTMLAttributes<HTMLInputElement> {
|
|
4
|
-
value: string;
|
|
5
|
-
label: string;
|
|
6
|
-
icon?: keyof SpecificIconsType;
|
|
7
|
-
disabled?: boolean;
|
|
8
|
-
sublabel?: string;
|
|
9
|
-
}
|
|
10
|
-
declare const Item: ({ value, label, sublabel, icon, disabled, }: ItemProps) => import("react").JSX.Element;
|
|
11
|
-
export default Item;
|
|
File without changes
|