@adamjanicki/ui-extended 1.0.1 → 1.0.3

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.
@@ -84,6 +84,10 @@ interface Props<T> {
84
84
  * Footer node to render at the bottom of the popover
85
85
  */
86
86
  footer?: React.ReactNode;
87
+ /**
88
+ * A callback to be called when the user hits the enter key while no option is selected
89
+ */
90
+ onUnselectedEnter?: () => void;
87
91
  }
88
92
  declare const Autocomplete: <T>(props: Props<T>) => JSX.Element;
89
93
  export default Autocomplete;
@@ -29,7 +29,7 @@ import { classNames } from "@adamjanicki/ui/utils/util";
29
29
  var defaultRenderOption = function (option) { return (_jsx("div", { className: "ajui-autocomplete-default-rendering", children: "".concat(option) })); };
30
30
  var Autocomplete = function (props) {
31
31
  var _a, _b;
32
- var options = props.options, _c = props.renderOption, renderOption = _c === void 0 ? defaultRenderOption : _c, _d = props.filterOption, filterOption = _d === void 0 ? function () { return true; } : _d, groupBy = props.groupBy, renderGroup = props.renderGroup, noOptionsNode = props.noOptionsNode, _e = props.InputProps, InputProps = _e === void 0 ? {} : _e, _f = props.freeSolo, freeSolo = _f === void 0 ? false : _f, _g = props.focusOnSelect, focusOnSelect = _g === void 0 ? true : _g, value = props.value, onInputChange = props.onInputChange, onSelect = props.onSelect, popoverProps = props.popoverProps, footer = props.footer, _h = props.listItemProps, listItemProps = _h === void 0 ? {} : _h, _j = props.listProps, listProps = _j === void 0 ? {} : _j, rest = __rest(props, ["options", "renderOption", "filterOption", "groupBy", "renderGroup", "noOptionsNode", "InputProps", "freeSolo", "focusOnSelect", "value", "onInputChange", "onSelect", "popoverProps", "footer", "listItemProps", "listProps"]);
32
+ var options = props.options, _c = props.renderOption, renderOption = _c === void 0 ? defaultRenderOption : _c, _d = props.filterOption, filterOption = _d === void 0 ? function () { return true; } : _d, groupBy = props.groupBy, renderGroup = props.renderGroup, noOptionsNode = props.noOptionsNode, _e = props.InputProps, InputProps = _e === void 0 ? {} : _e, _f = props.freeSolo, freeSolo = _f === void 0 ? false : _f, _g = props.focusOnSelect, focusOnSelect = _g === void 0 ? true : _g, value = props.value, onInputChange = props.onInputChange, onSelect = props.onSelect, popoverProps = props.popoverProps, footer = props.footer, _h = props.listItemProps, listItemProps = _h === void 0 ? {} : _h, _j = props.listProps, listProps = _j === void 0 ? {} : _j, onUnselectedEnter = props.onUnselectedEnter, rest = __rest(props, ["options", "renderOption", "filterOption", "groupBy", "renderGroup", "noOptionsNode", "InputProps", "freeSolo", "focusOnSelect", "value", "onInputChange", "onSelect", "popoverProps", "footer", "listItemProps", "listProps", "onUnselectedEnter"]);
33
33
  var inputContainerRef = React.useRef(null);
34
34
  var inputRef = React.useRef(null);
35
35
  var onRef = React.useRef(null);
@@ -64,7 +64,7 @@ var Autocomplete = function (props) {
64
64
  onSelect(v);
65
65
  var current = inputRef.current;
66
66
  closeMenu();
67
- if (focusOnSelect)
67
+ if (!focusOnSelect)
68
68
  return current === null || current === void 0 ? void 0 : current.focus();
69
69
  };
70
70
  var closeMenu = function () {
@@ -75,6 +75,7 @@ var Autocomplete = function (props) {
75
75
  setOpen(true);
76
76
  };
77
77
  var handleKeys = function (_a) {
78
+ var _b;
78
79
  var code = _a.code;
79
80
  if (code === "Escape") {
80
81
  closeMenu();
@@ -85,6 +86,12 @@ var Autocomplete = function (props) {
85
86
  if (modulo > 0 && current) {
86
87
  return current.click();
87
88
  }
89
+ else if (onUnselectedEnter) {
90
+ onUnselectedEnter();
91
+ closeMenu();
92
+ if (!focusOnSelect)
93
+ return (_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.blur();
94
+ }
88
95
  }
89
96
  if (modulo > 0 && code === "ArrowDown") {
90
97
  var newOn = ((on !== undefined ? on : -1) + 1) % modulo;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamjanicki/ui-extended",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "More advanced UI components and hooks for React in TypeScript",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",