@pushwoosh/dumb-components 1.1.143 → 1.1.144

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.
@@ -65,6 +65,7 @@ function FreeCombobox({
65
65
  setActiveIndex,
66
66
  onSelectIndex: index => pick(filteredItems[index]),
67
67
  onEscape: close,
68
+ onSubmit: close,
68
69
  onReachEnd: loadMore
69
70
  });
70
71
  const onShellMouseDown = useShellMouseDown(inputRef, isOpen, open);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/dumb-components",
3
- "version": "1.1.143",
3
+ "version": "1.1.144",
4
4
  "description": "React components to build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -7,11 +7,12 @@ type Args = {
7
7
  setActiveIndex: Dispatch<SetStateAction<number>>;
8
8
  onSelectIndex: (index: number) => void;
9
9
  onEscape: () => void;
10
+ onSubmit?: () => void;
10
11
  onReachEnd?: () => void;
11
12
  hasExtraRow?: boolean;
12
13
  onSelectExtra?: () => void;
13
14
  isQueryEmpty?: boolean;
14
15
  onBackspaceEmpty?: () => void;
15
16
  };
16
- export declare function useListNavigation({ isOpen, open, itemCount, activeIndex, setActiveIndex, onSelectIndex, onEscape, onReachEnd, hasExtraRow, onSelectExtra, isQueryEmpty, onBackspaceEmpty, }: Args): (event: KeyboardEvent<HTMLInputElement>) => void;
17
+ export declare function useListNavigation({ isOpen, open, itemCount, activeIndex, setActiveIndex, onSelectIndex, onEscape, onSubmit, onReachEnd, hasExtraRow, onSelectExtra, isQueryEmpty, onBackspaceEmpty, }: Args): (event: KeyboardEvent<HTMLInputElement>) => void;
17
18
  export {};
@@ -7,6 +7,7 @@ export function useListNavigation({
7
7
  setActiveIndex,
8
8
  onSelectIndex,
9
9
  onEscape,
10
+ onSubmit,
10
11
  onReachEnd,
11
12
  hasExtraRow,
12
13
  onSelectExtra,
@@ -34,7 +35,14 @@ export function useListNavigation({
34
35
  return;
35
36
  }
36
37
  if (event.key === 'Enter') {
37
- if (!isOpen || activeIndex < 0 || activeIndex >= total) return;
38
+ if (!isOpen) return;
39
+ if (activeIndex < 0 || activeIndex >= total) {
40
+ if (onSubmit) {
41
+ event.preventDefault();
42
+ onSubmit();
43
+ }
44
+ return;
45
+ }
38
46
  event.preventDefault();
39
47
  if (hasExtraRow && activeIndex === 0) onSelectExtra === null || onSelectExtra === void 0 || onSelectExtra();else onSelectIndex(hasExtraRow ? activeIndex - 1 : activeIndex);
40
48
  return;
@@ -50,5 +58,5 @@ export function useListNavigation({
50
58
  if (event.key === 'Backspace' && isQueryEmpty && onBackspaceEmpty) {
51
59
  onBackspaceEmpty();
52
60
  }
53
- }, [isOpen, open, total, activeIndex, setActiveIndex, onSelectIndex, onSelectExtra, onEscape, onReachEnd, hasExtraRow, isQueryEmpty, onBackspaceEmpty]);
61
+ }, [isOpen, open, total, activeIndex, setActiveIndex, onSelectIndex, onSelectExtra, onEscape, onSubmit, onReachEnd, hasExtraRow, isQueryEmpty, onBackspaceEmpty]);
54
62
  }