@ssa-ui-kit/core 1.0.9 → 1.0.10
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/Typeahead/Typeahead.context.d.ts +0 -1
- package/dist/components/Typeahead/Typeahead.d.ts +1 -1
- package/dist/components/Typeahead/types.d.ts +2 -2
- package/dist/components/Typeahead/useTypeahead.d.ts +1 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Typeahead/Typeahead.context.ts +0 -3
- package/src/components/Typeahead/Typeahead.stories.tsx +4 -4
- package/src/components/Typeahead/Typeahead.tsx +2 -2
- package/src/components/Typeahead/components/MultipleTrigger.tsx +0 -1
- package/src/components/Typeahead/components/SingleTrigger.tsx +0 -1
- package/src/components/Typeahead/types.ts +2 -2
- package/src/components/Typeahead/useTypeahead.tsx +10 -2
- package/tsbuildcache +1 -1
package/package.json
CHANGED
|
@@ -63,8 +63,8 @@ export const Basic: StoryObj = (args: TypeaheadProps) => {
|
|
|
63
63
|
<Typeahead
|
|
64
64
|
initialSelectedItems={[items[2].id]}
|
|
65
65
|
isDisabled={args.isDisabled}
|
|
66
|
-
|
|
67
|
-
console.log('>>>
|
|
66
|
+
onEmptyChange={(isEmpty) => {
|
|
67
|
+
console.log('>>>onEmptyChange event', isEmpty);
|
|
68
68
|
}}
|
|
69
69
|
name={'typeahead-dropdown'}
|
|
70
70
|
label="Label"
|
|
@@ -127,8 +127,8 @@ export const Multiple: StoryObj = (args: TypeaheadProps) => {
|
|
|
127
127
|
initialSelectedItems={[items[2].id, items[1].id]}
|
|
128
128
|
isMultiple
|
|
129
129
|
isDisabled={args.isDisabled}
|
|
130
|
-
|
|
131
|
-
console.log('>>>
|
|
130
|
+
onEmptyChange={(isEmpty) => {
|
|
131
|
+
console.log('>>>onEmptyChange event', isEmpty);
|
|
132
132
|
}}
|
|
133
133
|
label="Label"
|
|
134
134
|
helperText="Helper Text"
|
|
@@ -45,7 +45,7 @@ export const Typeahead = ({
|
|
|
45
45
|
setValue,
|
|
46
46
|
register,
|
|
47
47
|
onChange,
|
|
48
|
-
|
|
48
|
+
onEmptyChange,
|
|
49
49
|
renderOption,
|
|
50
50
|
}: TypeaheadProps) => {
|
|
51
51
|
const theme = useTheme();
|
|
@@ -68,7 +68,7 @@ export const Typeahead = ({
|
|
|
68
68
|
setValue,
|
|
69
69
|
register,
|
|
70
70
|
onChange,
|
|
71
|
-
|
|
71
|
+
onEmptyChange,
|
|
72
72
|
renderOption,
|
|
73
73
|
});
|
|
74
74
|
|
|
@@ -67,7 +67,6 @@ export const MultipleTrigger = () => {
|
|
|
67
67
|
onClick: context.handleInputClick,
|
|
68
68
|
onKeyDown: context.handleInputKeyDown,
|
|
69
69
|
onChange: context.handleInputChange,
|
|
70
|
-
onBlur: context.handleInputBlur,
|
|
71
70
|
value: context.inputValue,
|
|
72
71
|
autoComplete: 'off',
|
|
73
72
|
className: ['typeahead-input', S.TypeaheadInput(theme)].join(' '),
|
|
@@ -26,7 +26,6 @@ export const SingleTrigger = () => {
|
|
|
26
26
|
onClick: context.handleInputClick,
|
|
27
27
|
onKeyDown: context.handleInputKeyDown,
|
|
28
28
|
onChange: context.handleInputChange,
|
|
29
|
-
onBlur: context.handleInputBlur,
|
|
30
29
|
value: context.inputValue,
|
|
31
30
|
autoComplete: 'off',
|
|
32
31
|
className: ['typeahead-input', S.TypeaheadInput(theme)].join(' '),
|
|
@@ -34,7 +34,7 @@ export interface TypeaheadProps {
|
|
|
34
34
|
setValue?: UseFormSetValue<FieldValues>;
|
|
35
35
|
register?: UseFormReturn['register'];
|
|
36
36
|
onChange?: (selectedItem: TypeaheadValue, isSelected: boolean) => void;
|
|
37
|
-
|
|
37
|
+
onEmptyChange?: (isEmpty?: boolean) => void;
|
|
38
38
|
renderOption?: (data: {
|
|
39
39
|
value: string | number;
|
|
40
40
|
input: string;
|
|
@@ -49,7 +49,7 @@ export type UseTypeaheadProps = Pick<
|
|
|
49
49
|
| 'children'
|
|
50
50
|
| 'isMultiple'
|
|
51
51
|
| 'onChange'
|
|
52
|
-
| '
|
|
52
|
+
| 'onEmptyChange'
|
|
53
53
|
| 'renderOption'
|
|
54
54
|
| 'isOpen'
|
|
55
55
|
| 'className'
|
|
@@ -29,7 +29,7 @@ export const useTypeahead = ({
|
|
|
29
29
|
register,
|
|
30
30
|
setValue,
|
|
31
31
|
onChange,
|
|
32
|
-
|
|
32
|
+
onEmptyChange,
|
|
33
33
|
renderOption,
|
|
34
34
|
}: UseTypeaheadProps) => {
|
|
35
35
|
const inputName = `${name}-text`;
|
|
@@ -40,6 +40,7 @@ export const useTypeahead = ({
|
|
|
40
40
|
const [optionsWithKey, setOptionsWithKey] = useState<
|
|
41
41
|
Record<number | string, Record<string, string | number>>
|
|
42
42
|
>({});
|
|
43
|
+
const [isEmpty, setIsEmpty] = useState<boolean>();
|
|
43
44
|
const [isFirstRender, setFirstRender] = useState<boolean>(true);
|
|
44
45
|
const [items, setItems] = useState<Array<React.ReactElement> | undefined>();
|
|
45
46
|
const [inputValue, setInputValue] = useState<string>('');
|
|
@@ -70,8 +71,16 @@ export const useTypeahead = ({
|
|
|
70
71
|
shouldDirty: !isFirstRender,
|
|
71
72
|
});
|
|
72
73
|
}
|
|
74
|
+
|
|
75
|
+
if (!isFirstRender) {
|
|
76
|
+
setIsEmpty(!selected.length);
|
|
77
|
+
}
|
|
73
78
|
}, [selected]);
|
|
74
79
|
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
onEmptyChange?.(isEmpty);
|
|
82
|
+
}, [isEmpty]);
|
|
83
|
+
|
|
75
84
|
useEffect(() => {
|
|
76
85
|
if (isDisabled && isOpen) {
|
|
77
86
|
setIsOpen(false);
|
|
@@ -341,7 +350,6 @@ export const useTypeahead = ({
|
|
|
341
350
|
handleInputChange,
|
|
342
351
|
handleInputClick,
|
|
343
352
|
handleInputKeyDown,
|
|
344
|
-
handleInputBlur: onBlur,
|
|
345
353
|
handleSelectedClick,
|
|
346
354
|
handleRemoveSelectedClick,
|
|
347
355
|
};
|