@ssa-ui-kit/core 1.0.8 → 1.0.9

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.8",
3
+ "version": "1.0.9",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "private": false,
@@ -52,6 +52,9 @@ export const TypeaheadContext = React.createContext<UseTypeaheadResult>({
52
52
  handleRemoveSelectedClick: () => () => {
53
53
  /* no-op */
54
54
  },
55
+ handleInputBlur: () => {
56
+ /* no-op */
57
+ },
55
58
  handleSelectedClick: () => {
56
59
  /* no-op */
57
60
  },
@@ -63,6 +63,9 @@ 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');
68
+ }}
66
69
  name={'typeahead-dropdown'}
67
70
  label="Label"
68
71
  helperText="Helper Text"
@@ -124,6 +127,9 @@ export const Multiple: StoryObj = (args: TypeaheadProps) => {
124
127
  initialSelectedItems={[items[2].id, items[1].id]}
125
128
  isMultiple
126
129
  isDisabled={args.isDisabled}
130
+ onBlur={() => {
131
+ console.log('>>>onBlur event');
132
+ }}
127
133
  label="Label"
128
134
  helperText="Helper Text"
129
135
  register={register}
@@ -45,6 +45,7 @@ export const Typeahead = ({
45
45
  setValue,
46
46
  register,
47
47
  onChange,
48
+ onBlur,
48
49
  renderOption,
49
50
  }: TypeaheadProps) => {
50
51
  const theme = useTheme();
@@ -67,6 +68,7 @@ export const Typeahead = ({
67
68
  setValue,
68
69
  register,
69
70
  onChange,
71
+ onBlur,
70
72
  renderOption,
71
73
  });
72
74
 
@@ -67,6 +67,7 @@ export const MultipleTrigger = () => {
67
67
  onClick: context.handleInputClick,
68
68
  onKeyDown: context.handleInputKeyDown,
69
69
  onChange: context.handleInputChange,
70
+ onBlur: context.handleInputBlur,
70
71
  value: context.inputValue,
71
72
  autoComplete: 'off',
72
73
  className: ['typeahead-input', S.TypeaheadInput(theme)].join(' '),
@@ -26,6 +26,7 @@ export const SingleTrigger = () => {
26
26
  onClick: context.handleInputClick,
27
27
  onKeyDown: context.handleInputKeyDown,
28
28
  onChange: context.handleInputChange,
29
+ onBlur: context.handleInputBlur,
29
30
  value: context.inputValue,
30
31
  autoComplete: 'off',
31
32
  className: ['typeahead-input', S.TypeaheadInput(theme)].join(' '),
@@ -34,6 +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
38
  renderOption?: (data: {
38
39
  value: string | number;
39
40
  input: string;
@@ -48,6 +49,7 @@ export type UseTypeaheadProps = Pick<
48
49
  | 'children'
49
50
  | 'isMultiple'
50
51
  | 'onChange'
52
+ | 'onBlur'
51
53
  | 'renderOption'
52
54
  | 'isOpen'
53
55
  | 'className'
@@ -29,6 +29,7 @@ export const useTypeahead = ({
29
29
  register,
30
30
  setValue,
31
31
  onChange,
32
+ onBlur,
32
33
  renderOption,
33
34
  }: UseTypeaheadProps) => {
34
35
  const inputName = `${name}-text`;
@@ -261,7 +262,11 @@ export const useTypeahead = ({
261
262
  inputRef.current?.focus();
262
263
  event.stopPropagation();
263
264
  event.preventDefault();
264
- } else if (['Tab', 'Enter'].includes(event.code) && firstSuggestion) {
265
+ } else if (
266
+ ['Tab', 'Enter'].includes(event.code) &&
267
+ firstSuggestion &&
268
+ firstSuggestion !== inputValue
269
+ ) {
265
270
  const foundItem = Object.values(optionsWithKey).find(
266
271
  (item) =>
267
272
  `${item.label}`.toLowerCase() === firstSuggestion.toLowerCase(),
@@ -281,7 +286,7 @@ export const useTypeahead = ({
281
286
  handleChange(selected[selected.length - 1]);
282
287
  event.preventDefault();
283
288
  return false;
284
- } else if (!isOpen) {
289
+ } else if (!isOpen && firstSuggestion !== inputValue) {
285
290
  setIsOpen(true);
286
291
  }
287
292
  };
@@ -336,6 +341,7 @@ export const useTypeahead = ({
336
341
  handleInputChange,
337
342
  handleInputClick,
338
343
  handleInputKeyDown,
344
+ handleInputBlur: onBlur,
339
345
  handleSelectedClick,
340
346
  handleRemoveSelectedClick,
341
347
  };