@vev/silke 1.0.16 → 1.0.17
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/dist/chunk-SOFGXMET.js +22 -0
- package/dist/{chunk-LAB2YEXC.js.map → chunk-SOFGXMET.js.map} +3 -3
- package/dist/index.js +43 -8
- package/dist/index.js.LEGAL.txt +6 -10
- package/dist/index.js.map +4 -4
- package/dist/{silke-code-editor-WEBZ7JXL.js → silke-code-editor-3Y2KM5KB.js} +3 -3
- package/dist/styles.css +411 -482
- package/package.json +4 -4
- package/src/components/silke-autocomplete-field/autocomplete-item.tsx +33 -7
- package/src/components/silke-autocomplete-field/autocomplete-tags.tsx +6 -2
- package/src/components/silke-autocomplete-field/autocomplete-types.ts +4 -0
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.mdx +67 -24
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.scss +32 -13
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.spec.tsx +24 -109
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.tsx +304 -220
- package/src/components/silke-box/silke-box.scss +9 -10
- package/src/components/silke-box/silke-box.tsx +9 -0
- package/src/components/silke-button/silke-button.scss +3 -3
- package/src/components/silke-color-picker/silke-color-info.tsx +2 -18
- package/src/components/silke-context-menu/silke-context-menu.tsx +0 -1
- package/src/components/silke-css-number-field/silke-css-number-field.mdx +43 -4
- package/src/components/silke-css-number-field/silke-css-number-field.scss +47 -14
- package/src/components/silke-css-number-field/silke-css-number-field.tsx +114 -186
- package/src/components/silke-css-number-field/utils.ts +25 -0
- package/src/components/silke-drawer/silke-drawer.tsx +0 -14
- package/src/components/silke-form/silke-form.tsx +1 -1
- package/src/components/silke-form-schema/fields/array-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/utils/generate-title.ts +5 -4
- package/src/components/silke-image/silke-image.scss +2 -2
- package/src/components/silke-modal/silke-modal.tsx +11 -2
- package/src/components/silke-navigation-link/silke-navigation-link.scss +12 -2
- package/src/components/silke-navigation-link/silke-navigation-link.tsx +21 -17
- package/src/components/silke-notification/silke-notification.scss +1 -1
- package/src/components/silke-overflow-menu/silke-overflow-menu.tsx +1 -2
- package/src/components/silke-popover/silke-popover.tsx +1 -20
- package/src/components/silke-select-field/silke-select-field.mdx +137 -7
- package/src/components/silke-select-field/silke-select-field.spec.tsx +44 -126
- package/src/components/silke-sortable-list/silke-nested-sortable-item.tsx +17 -2
- package/src/components/silke-sortable-list/silke-nested-sortable-list.tsx +6 -2
- package/src/components/silke-sortable-list/silke-nested-sortable-utils.ts +6 -0
- package/src/components/silke-table/silke-table.tsx +1 -1
- package/src/components/silke-tag/silke-tag.tsx +1 -1
- package/src/components/silke-text-field/silke-text-field-item.tsx +12 -7
- package/src/components/silke-text-field/silke-text-field-outline.tsx +39 -42
- package/src/components/silke-text-field/silke-text-field.mdx +73 -6
- package/src/components/silke-text-field/silke-text-field.scss +153 -247
- package/src/components/silke-text-field/silke-text-field.tsx +4 -3
- package/src/components/silke-tooltip/silke-icon-tooltip.tsx +2 -1
- package/src/docs/app.tsx +9 -16
- package/src/hooks/form/use-form-field.ts +1 -1
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-uniq-id.ts +6 -0
- package/src/icons.tsx +8 -2
- package/dist/chunk-LAB2YEXC.js +0 -22
- /package/dist/{chunk-LAB2YEXC.js.LEGAL.txt → chunk-SOFGXMET.js.LEGAL.txt} +0 -0
- /package/dist/{silke-code-editor-WEBZ7JXL.js.LEGAL.txt → silke-code-editor-3Y2KM5KB.js.LEGAL.txt} +0 -0
- /package/dist/{silke-code-editor-WEBZ7JXL.js.map → silke-code-editor-3Y2KM5KB.js.map} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vev/silke",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"watch": "run-p watch:tsc watch:code",
|
|
15
15
|
"watch:code": "node esbuild.config.mjs --watch",
|
|
16
16
|
"watch:tsc": "tsc --project ./tsconfig.json --noEmit --watch",
|
|
17
|
-
"clean": "del dist",
|
|
17
|
+
"clean": "del-cli dist",
|
|
18
18
|
"tsc": "tsc --project ./tsconfig.json --noEmit"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"@mdx-js/mdx": "^2.0.0-next.9",
|
|
31
31
|
"@mdx-js/react": "^2.1.2",
|
|
32
32
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
|
|
33
|
-
"@vev/react": "0.1.
|
|
34
|
-
"@vev/utils": "1.1.
|
|
33
|
+
"@vev/react": "0.1.1",
|
|
34
|
+
"@vev/utils": "1.1.1",
|
|
35
35
|
"@uiw/react-codemirror": "^4.12.3",
|
|
36
36
|
"@uiw/codemirror-theme-dracula": "^4.12.3",
|
|
37
37
|
"classnames": ">=2.2.0",
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import React, { useRef } from 'react';
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
2
|
import { BoxSize, SilkeBox } from '../silke-box';
|
|
3
3
|
import { SilkeCheckbox } from '../silke-checkbox';
|
|
4
4
|
import { SilkeText } from '../silke-text';
|
|
5
5
|
import { Data, Entry } from './autocomplete-types';
|
|
6
6
|
import styles from './silke-autocomplete-field.scss';
|
|
7
|
+
import { SilkeIcon } from '../silke-icon';
|
|
8
|
+
import { EmojiType } from '@vev/utils';
|
|
7
9
|
|
|
8
10
|
export interface AutocompleteRenderItemProps<U> {
|
|
9
11
|
item: U;
|
|
@@ -35,20 +37,32 @@ export default function AutocompleteItem<T, U extends Entry<T>>({
|
|
|
35
37
|
const isDisabled = (item as Data<T>).disabled;
|
|
36
38
|
const ref = useRef<HTMLDivElement>(null);
|
|
37
39
|
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
const cl = styles.autocompleteItem;
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const el = ref.current;
|
|
44
|
+
if (highlight) (el as any)?.scrollIntoViewIfNeeded?.();
|
|
45
|
+
}, [highlight]);
|
|
46
|
+
|
|
47
|
+
let iconSize: BoxSize = size || 'm';
|
|
48
|
+
if (size === 'm') iconSize = 'base';
|
|
49
|
+
if (size === 'base') iconSize = 's';
|
|
50
|
+
// if (size === 's') iconSize = 's';
|
|
51
|
+
// else if (size === 'xs') iconSize = 's';
|
|
52
|
+
// console.log('###### SIZE', size);
|
|
41
53
|
|
|
42
54
|
return (
|
|
43
55
|
<SilkeBox
|
|
44
56
|
ref={ref}
|
|
57
|
+
role="option"
|
|
45
58
|
height={size || 'm'}
|
|
46
|
-
hPad={ItemRender ? undefined : 's'}
|
|
59
|
+
hPad={ItemRender || item.icon || item.image ? undefined : 's'}
|
|
60
|
+
bg={highlight ? 'neutral-30' : undefined}
|
|
47
61
|
bgHover={isDisabled ? undefined : 'neutral-30'}
|
|
48
62
|
vAlign="center"
|
|
49
|
-
gap=
|
|
63
|
+
gap={item.icon || item.image ? 'xxs' : 'xs'}
|
|
50
64
|
rounded={size === 's' ? 'tiny' : 'small'}
|
|
51
|
-
className={
|
|
65
|
+
className={cl}
|
|
52
66
|
onMouseDown={
|
|
53
67
|
isDisabled ? (e: React.MouseEvent<HTMLButtonElement>) => e.preventDefault() : onMouseDown
|
|
54
68
|
}
|
|
@@ -62,6 +76,18 @@ export default function AutocompleteItem<T, U extends Entry<T>>({
|
|
|
62
76
|
<SilkeCheckbox value={selected} style={{ pointerEvents: 'none' }} />
|
|
63
77
|
</SilkeBox>
|
|
64
78
|
)}
|
|
79
|
+
|
|
80
|
+
{item.image && (
|
|
81
|
+
<SilkeBox size={iconSize} align="center" pad="xs">
|
|
82
|
+
<SilkeIcon icon={{ type: EmojiType.upload, value: { url: item.image } }} />
|
|
83
|
+
</SilkeBox>
|
|
84
|
+
)}
|
|
85
|
+
|
|
86
|
+
{item.icon && (
|
|
87
|
+
<SilkeBox size={iconSize} align="center">
|
|
88
|
+
<SilkeIcon icon={item.icon} />
|
|
89
|
+
</SilkeBox>
|
|
90
|
+
)}
|
|
65
91
|
<SilkeText
|
|
66
92
|
tag={size === 's' ? 'small' : undefined}
|
|
67
93
|
overflow
|
|
@@ -11,7 +11,7 @@ export interface AutocompleteTagsProps<T> {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export default function AutocompleteTags<T>({
|
|
14
|
-
showMaxTags =
|
|
14
|
+
showMaxTags = 10,
|
|
15
15
|
items,
|
|
16
16
|
onRemove,
|
|
17
17
|
onRemoveAll,
|
|
@@ -26,7 +26,11 @@ export default function AutocompleteTags<T>({
|
|
|
26
26
|
kind="blue"
|
|
27
27
|
key={i}
|
|
28
28
|
label={item.label}
|
|
29
|
-
onRemove={() =>
|
|
29
|
+
onRemove={(e) => {
|
|
30
|
+
e.stopPropagation();
|
|
31
|
+
e.preventDefault();
|
|
32
|
+
onRemove(item.value);
|
|
33
|
+
}}
|
|
30
34
|
id={`tag_${i}`}
|
|
31
35
|
/>
|
|
32
36
|
))}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { IEmojiIcon } from '@vev/utils';
|
|
1
2
|
import { FormFieldProps } from '../silke-form';
|
|
3
|
+
import { SilkeIcons } from '../silke-icon';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Defines data for the Autocomplete
|
|
@@ -17,6 +19,7 @@ export interface Data<T> {
|
|
|
17
19
|
* Image URL
|
|
18
20
|
*/
|
|
19
21
|
image?: string;
|
|
22
|
+
icon?: IEmojiIcon | SilkeIcons;
|
|
20
23
|
label: string;
|
|
21
24
|
/**
|
|
22
25
|
* Description
|
|
@@ -27,6 +30,7 @@ export interface Data<T> {
|
|
|
27
30
|
|
|
28
31
|
export interface Divider {
|
|
29
32
|
image?: string;
|
|
33
|
+
icon?: IEmojiIcon | SilkeIcons;
|
|
30
34
|
label?: string;
|
|
31
35
|
subLabel?: string;
|
|
32
36
|
divider: true;
|
|
@@ -3,22 +3,31 @@ const items = ipsum.list((i) => ({ value: i, label: ipsum.name() }));
|
|
|
3
3
|
const [value, setValue] = React.useState("");
|
|
4
4
|
<>
|
|
5
5
|
<h5>Value: {value || "No value"}</h5>
|
|
6
|
-
<
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
<SilkeTextField name="test" label="Text before" />
|
|
7
|
+
{["default", "zombie", "ghost"].map((kind) => (
|
|
8
|
+
<SilkeBox key={kind} gap="s">
|
|
9
|
+
<SilkeAutocompleteField
|
|
10
|
+
label={kind}
|
|
11
|
+
kind={kind}
|
|
12
|
+
name="Foobar"
|
|
13
|
+
placeholder="Placeholder"
|
|
14
|
+
onChange={setValue}
|
|
15
|
+
value={value}
|
|
16
|
+
items={items}
|
|
17
|
+
/>
|
|
18
|
+
<SilkeAutocompleteField
|
|
19
|
+
label={kind}
|
|
20
|
+
kind={kind}
|
|
21
|
+
size="xs"
|
|
22
|
+
name="Foobar"
|
|
23
|
+
placeholder="Placeholder"
|
|
24
|
+
onChange={setValue}
|
|
25
|
+
value={value}
|
|
26
|
+
items={items}
|
|
27
|
+
/>
|
|
28
|
+
</SilkeBox>
|
|
29
|
+
))}
|
|
30
|
+
<SilkeTextField name="test" label="Text after" />
|
|
22
31
|
</>;
|
|
23
32
|
```
|
|
24
33
|
|
|
@@ -29,14 +38,19 @@ const items = ipsum.list((i) => ({ value: i, label: ipsum.name() }));
|
|
|
29
38
|
const [value, setValue] = React.useState([]);
|
|
30
39
|
<>
|
|
31
40
|
<h5>Value: {value.join(", ") || "No value"}</h5>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
{["default", "zombie", "ghost"].map((kind) => (
|
|
42
|
+
<SilkeAutocompleteField
|
|
43
|
+
key={kind}
|
|
44
|
+
label={kind}
|
|
45
|
+
kind={kind}
|
|
46
|
+
placeholder="Select multiple"
|
|
47
|
+
name="Foobar"
|
|
48
|
+
multiple
|
|
49
|
+
onChange={setValue}
|
|
50
|
+
value={value}
|
|
51
|
+
items={items}
|
|
52
|
+
/>
|
|
53
|
+
))}
|
|
40
54
|
</>;
|
|
41
55
|
```
|
|
42
56
|
|
|
@@ -81,3 +95,32 @@ const items = values.map((i) => ({ value: i.toLowerCase(), label: i }));
|
|
|
81
95
|
showMaxTags={Infinity}
|
|
82
96
|
/>;
|
|
83
97
|
```
|
|
98
|
+
|
|
99
|
+
## Autocomplete with icon
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
const items = ipsum.list((i) => ({
|
|
103
|
+
value: i,
|
|
104
|
+
label: ipsum.name(),
|
|
105
|
+
icon: "html5",
|
|
106
|
+
}));
|
|
107
|
+
const [value, setValue] = React.useState("");
|
|
108
|
+
<>
|
|
109
|
+
<h5>Value: {value || "No value"}</h5>
|
|
110
|
+
<SilkeTextField name="test" label="Text before" />
|
|
111
|
+
{["default", "zombie", "ghost"].map((kind) => (
|
|
112
|
+
<SilkeBox key={kind} gap="s">
|
|
113
|
+
<SilkeAutocompleteField
|
|
114
|
+
label={kind}
|
|
115
|
+
kind={kind}
|
|
116
|
+
name="Foobar"
|
|
117
|
+
placeholder="Placeholder"
|
|
118
|
+
onChange={setValue}
|
|
119
|
+
value={value}
|
|
120
|
+
items={items}
|
|
121
|
+
/>
|
|
122
|
+
</SilkeBox>
|
|
123
|
+
))}
|
|
124
|
+
<SilkeTextField name="test" label="Text after" />
|
|
125
|
+
</>;
|
|
126
|
+
```
|
|
@@ -1,27 +1,46 @@
|
|
|
1
1
|
@use '../../variables' as *;
|
|
2
|
-
.
|
|
3
|
-
.clickable input {
|
|
2
|
+
.root {
|
|
4
3
|
cursor: pointer;
|
|
5
4
|
user-select: none;
|
|
5
|
+
&:hover,
|
|
6
|
+
&.ghost,
|
|
7
|
+
&.open {
|
|
8
|
+
.downIcon {
|
|
9
|
+
opacity: 1;
|
|
10
|
+
transform: translateY(2px);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
&.open:not(.ghost){
|
|
15
|
+
--text-field-bg: var(--color-neutral-20);
|
|
16
|
+
--text-field-hover-bg: var(--color-neutral-20);
|
|
17
|
+
--text-field-focus-border-color: transparent;
|
|
18
|
+
}
|
|
19
|
+
|
|
6
20
|
}
|
|
7
21
|
|
|
8
22
|
.autocompleteItem {
|
|
9
|
-
background: transparent;
|
|
10
23
|
cursor: pointer;
|
|
11
24
|
}
|
|
12
25
|
|
|
13
|
-
.
|
|
14
|
-
background:
|
|
26
|
+
.downIcon {
|
|
27
|
+
background: transparent;
|
|
28
|
+
outline: none;
|
|
29
|
+
border: none;
|
|
30
|
+
font-size: 0.845em;
|
|
31
|
+
// opacity: 0;
|
|
32
|
+
transform: translateY(0);
|
|
33
|
+
// color: var(--text-field-placeholder-color);
|
|
34
|
+
transition: opacity 0.5s ease-in-out, transform 0.3s ease-out;
|
|
15
35
|
}
|
|
16
36
|
|
|
17
|
-
.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
filter: drop-shadow(0px 4px 16px rgba(0, 0, 0, 0.2));
|
|
21
|
-
margin-top: 2px;
|
|
37
|
+
.placeholder {
|
|
38
|
+
color: var(--text-field-disabled-placeholder-color);
|
|
39
|
+
font-size: var(--text-field-font-size);
|
|
22
40
|
}
|
|
23
41
|
|
|
24
|
-
.
|
|
25
|
-
|
|
26
|
-
|
|
42
|
+
.hiddenSearch{
|
|
43
|
+
width:0;height:0;
|
|
44
|
+
overflow: hidden;
|
|
45
|
+
opacity: 0;
|
|
27
46
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import { act, render, screen } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
1
3
|
import React from 'react';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import { SilkeAutocompleteField, useMatchingItemsOnTop } from './silke-autocomplete-field';
|
|
4
4
|
import { ARROW_DOWN, ENTER, ESCAPE } from '../../../jest/keys';
|
|
5
|
-
import
|
|
6
|
-
import { renderHook } from '@testing-library/react-hooks';
|
|
5
|
+
import { SilkeAutocompleteField } from './silke-autocomplete-field';
|
|
7
6
|
|
|
8
7
|
type Item = {
|
|
9
8
|
label: string;
|
|
@@ -31,7 +30,7 @@ describe('silke-autocomplete-field', () => {
|
|
|
31
30
|
render(<SilkeAutocompleteField items={items} label="Animal" />);
|
|
32
31
|
const input = screen.getByLabelText('Animal');
|
|
33
32
|
|
|
34
|
-
await user.click(input);
|
|
33
|
+
await act(async () => await user.click(input));
|
|
35
34
|
|
|
36
35
|
const list = screen.getByRole('listbox');
|
|
37
36
|
|
|
@@ -45,16 +44,14 @@ describe('silke-autocomplete-field', () => {
|
|
|
45
44
|
|
|
46
45
|
render(<SilkeAutocompleteField items={items} label="Animal" />);
|
|
47
46
|
const input = screen.getByLabelText('Animal');
|
|
48
|
-
|
|
49
|
-
await user.click(input);
|
|
47
|
+
await act(async () => await user.click(input));
|
|
50
48
|
|
|
51
49
|
const list = screen.getByRole('listbox');
|
|
52
50
|
|
|
53
51
|
items.forEach((item) => {
|
|
54
52
|
expect(list.textContent).toContain(item.label);
|
|
55
53
|
});
|
|
56
|
-
|
|
57
|
-
await user.keyboard(ESCAPE);
|
|
54
|
+
await act(async () => await user.keyboard(ESCAPE));
|
|
58
55
|
|
|
59
56
|
const list2 = await screen.queryAllByRole('listbox');
|
|
60
57
|
expect(list2).toHaveLength(0);
|
|
@@ -66,11 +63,11 @@ describe('silke-autocomplete-field', () => {
|
|
|
66
63
|
render(<SilkeAutocompleteField items={items} label="Animal" />);
|
|
67
64
|
|
|
68
65
|
const input = screen.getByLabelText('Animal');
|
|
69
|
-
|
|
66
|
+
act(() => input.focus());
|
|
70
67
|
|
|
71
|
-
await user.keyboard(ARROW_DOWN);
|
|
68
|
+
await act(async () => await user.keyboard(ARROW_DOWN));
|
|
72
69
|
|
|
73
|
-
await user.keyboard('C');
|
|
70
|
+
await act(async () => await user.keyboard('C'));
|
|
74
71
|
|
|
75
72
|
const listbox = screen.getByRole('listbox');
|
|
76
73
|
|
|
@@ -82,7 +79,7 @@ describe('silke-autocomplete-field', () => {
|
|
|
82
79
|
expect(listbox.textContent).not.toContain(label);
|
|
83
80
|
});
|
|
84
81
|
|
|
85
|
-
await user.keyboard('A');
|
|
82
|
+
await act(async () => await user.keyboard('A'));
|
|
86
83
|
|
|
87
84
|
['cat'].forEach((label) => {
|
|
88
85
|
expect(listbox.textContent).toContain(label);
|
|
@@ -110,12 +107,12 @@ describe('silke-autocomplete-field', () => {
|
|
|
110
107
|
);
|
|
111
108
|
|
|
112
109
|
const input = screen.getByLabelText('Animal');
|
|
113
|
-
|
|
110
|
+
act(() => input.focus());
|
|
114
111
|
|
|
115
|
-
await user.keyboard('banana');
|
|
112
|
+
await act(async () => await user.keyboard('banana'));
|
|
116
113
|
|
|
117
114
|
const addButton = screen.getByText('+ Add item "banana"');
|
|
118
|
-
await user.click(addButton);
|
|
115
|
+
await act(async () => await user.click(addButton));
|
|
119
116
|
|
|
120
117
|
expect(onAdd).toHaveBeenCalledWith('banana');
|
|
121
118
|
});
|
|
@@ -137,11 +134,11 @@ describe('silke-autocomplete-field', () => {
|
|
|
137
134
|
);
|
|
138
135
|
|
|
139
136
|
const input = screen.getByLabelText('Animal');
|
|
140
|
-
|
|
137
|
+
act(() => input.focus());
|
|
141
138
|
|
|
142
|
-
await user.keyboard('banana');
|
|
139
|
+
await act(async () => await user.keyboard('banana'));
|
|
143
140
|
|
|
144
|
-
await user.keyboard(ENTER);
|
|
141
|
+
await act(async () => await user.keyboard(ENTER));
|
|
145
142
|
|
|
146
143
|
expect(onAdd).toHaveBeenCalledWith('banana');
|
|
147
144
|
});
|
|
@@ -154,10 +151,10 @@ describe('silke-autocomplete-field', () => {
|
|
|
154
151
|
|
|
155
152
|
const input = screen.getByLabelText('Animal');
|
|
156
153
|
|
|
157
|
-
await user.click(input);
|
|
154
|
+
await act(async () => await user.click(input));
|
|
158
155
|
|
|
159
156
|
const bearItem = screen.getByText('bear');
|
|
160
|
-
await user.click(bearItem);
|
|
157
|
+
await act(async () => await user.click(bearItem));
|
|
161
158
|
|
|
162
159
|
expect(onChange).toHaveBeenCalledWith('bear');
|
|
163
160
|
});
|
|
@@ -169,95 +166,13 @@ describe('silke-autocomplete-field', () => {
|
|
|
169
166
|
render(<SilkeAutocompleteField label="Animal" onChange={onChange} items={items} />);
|
|
170
167
|
|
|
171
168
|
const input = screen.getByLabelText('Animal');
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
await user.keyboard(ARROW_DOWN);
|
|
175
|
-
await user.keyboard(ARROW_DOWN);
|
|
176
|
-
await user.keyboard(ARROW_DOWN);
|
|
177
|
-
|
|
178
|
-
await user.keyboard(ENTER);
|
|
169
|
+
act(() => input.focus());
|
|
179
170
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const abbaItem = { label: 'abba', value: 'zzz' };
|
|
185
|
-
|
|
186
|
-
const items: Item[] = [
|
|
187
|
-
makeItem('cure'),
|
|
188
|
-
makeItem('cat'),
|
|
189
|
-
makeItem('lion'),
|
|
190
|
-
makeItem('lio'),
|
|
191
|
-
makeItem('bear'),
|
|
192
|
-
makeItem('deer'),
|
|
193
|
-
makeItem('Fish'),
|
|
194
|
-
];
|
|
195
|
-
|
|
196
|
-
let sortedItems: Item[];
|
|
197
|
-
|
|
198
|
-
beforeEach(() => {
|
|
199
|
-
sortedItems = [...items, abbaItem].sort((a, b) => {
|
|
200
|
-
return a.label.toLowerCase() > b.label.toLowerCase() ? 1 : -1;
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it('Returns all items if no search string', () => {
|
|
205
|
-
const { result } = renderHook(() => useMatchingItemsOnTop(sortedItems, undefined));
|
|
206
|
-
expect(result.current).toEqual(sortedItems);
|
|
207
|
-
});
|
|
171
|
+
await act(async () => await user.keyboard(ARROW_DOWN));
|
|
172
|
+
await act(async () => await user.keyboard(ARROW_DOWN));
|
|
173
|
+
await act(async () => await user.keyboard(ARROW_DOWN));
|
|
174
|
+
await act(async () => await user.keyboard(ENTER));
|
|
208
175
|
|
|
209
|
-
|
|
210
|
-
const { result } = renderHook(() => useMatchingItemsOnTop(sortedItems, 'LIO'));
|
|
211
|
-
expect(result.current).toEqual([
|
|
212
|
-
makeItem('lio'),
|
|
213
|
-
makeItem('lion'),
|
|
214
|
-
abbaItem,
|
|
215
|
-
makeItem('bear'),
|
|
216
|
-
makeItem('cat'),
|
|
217
|
-
makeItem('cure'),
|
|
218
|
-
makeItem('deer'),
|
|
219
|
-
makeItem('Fish'),
|
|
220
|
-
]);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it('Places items with full string match at the start', () => {
|
|
224
|
-
const { result } = renderHook(() => useMatchingItemsOnTop(sortedItems, 'lion'));
|
|
225
|
-
expect(result.current).toEqual([
|
|
226
|
-
makeItem('lion'),
|
|
227
|
-
abbaItem,
|
|
228
|
-
makeItem('bear'),
|
|
229
|
-
makeItem('cat'),
|
|
230
|
-
makeItem('cure'),
|
|
231
|
-
makeItem('deer'),
|
|
232
|
-
makeItem('Fish'),
|
|
233
|
-
makeItem('lio'),
|
|
234
|
-
]);
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
it('Places items with full string match on the VALUE at the start', () => {
|
|
238
|
-
const { result } = renderHook(() => useMatchingItemsOnTop(sortedItems, 'zzz'));
|
|
239
|
-
expect(result.current).toEqual([
|
|
240
|
-
abbaItem,
|
|
241
|
-
makeItem('bear'),
|
|
242
|
-
makeItem('cat'),
|
|
243
|
-
makeItem('cure'),
|
|
244
|
-
makeItem('deer'),
|
|
245
|
-
makeItem('Fish'),
|
|
246
|
-
makeItem('lio'),
|
|
247
|
-
makeItem('lion'),
|
|
248
|
-
]);
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
it('Matches with start of string only', () => {
|
|
252
|
-
const items = [...sortedItems, makeItem('KAN (Professional, 2 users)')];
|
|
253
|
-
const { result } = renderHook(() => useMatchingItemsOnTop(items, 'KAN'));
|
|
254
|
-
expect(result.current).toEqual([makeItem('KAN (Professional, 2 users)'), ...sortedItems]);
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
it('Returns items as-they-are if selectedItem === searchString', () => {
|
|
258
|
-
const items = [makeItem('a'), makeItem('b'), makeItem('c'), makeItem('d')];
|
|
259
|
-
const { result } = renderHook(() => useMatchingItemsOnTop(items, 'd', 'd'));
|
|
260
|
-
expect(result.current).toEqual(items);
|
|
261
|
-
});
|
|
176
|
+
expect(onChange).toHaveBeenCalledWith('bear');
|
|
262
177
|
});
|
|
263
178
|
});
|