@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssa-ui-kit/core",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "private": false,
@@ -52,9 +52,6 @@ export const TypeaheadContext = React.createContext<UseTypeaheadResult>({
52
52
  handleRemoveSelectedClick: () => () => {
53
53
  /* no-op */
54
54
  },
55
- handleInputBlur: () => {
56
- /* no-op */
57
- },
58
55
  handleSelectedClick: () => {
59
56
  /* no-op */
60
57
  },
@@ -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
- onBlur={() => {
67
- console.log('>>>onBlur event');
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
- onBlur={() => {
131
- console.log('>>>onBlur event');
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
- onBlur,
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
- onBlur,
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
- onBlur?: React.FocusEventHandler<HTMLInputElement>;
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
- | 'onBlur'
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
- onBlur,
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
  };