@adamjanicki/ui-extended 1.1.1 → 1.1.2
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.
|
@@ -60,10 +60,6 @@ interface Props<T> {
|
|
|
60
60
|
* Allow free text input
|
|
61
61
|
*/
|
|
62
62
|
freeSolo?: boolean;
|
|
63
|
-
/**
|
|
64
|
-
* Focus on the input field after selecting an option
|
|
65
|
-
*/
|
|
66
|
-
focusOnSelect?: boolean;
|
|
67
63
|
/**
|
|
68
64
|
* Props for the input field
|
|
69
65
|
*/
|
|
@@ -93,6 +89,11 @@ interface Props<T> {
|
|
|
93
89
|
* A callback to be called when the user hits the enter key while no option is selected
|
|
94
90
|
*/
|
|
95
91
|
onUnselectedEnter?: () => void;
|
|
92
|
+
/**
|
|
93
|
+
* Whether or not to leave the popover open after a selection occurs
|
|
94
|
+
* @default false
|
|
95
|
+
*/
|
|
96
|
+
remainOpenOnSelectOrEnter?: boolean;
|
|
96
97
|
}
|
|
97
98
|
declare const Autocomplete: <T>(props: Props<T>) => JSX.Element;
|
|
98
99
|
export default Autocomplete;
|
|
@@ -29,7 +29,7 @@ import { classNames } from "@adamjanicki/ui/functions";
|
|
|
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,
|
|
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, value = props.value, onInputChange = props.onInputChange, onSelect = props.onSelect, popoverProps = props.popoverProps, footer = props.footer, _g = props.listItemProps, listItemProps = _g === void 0 ? {} : _g, _h = props.listProps, listProps = _h === void 0 ? {} : _h, onUnselectedEnter = props.onUnselectedEnter, _j = props.closeOnFooterClick, closeOnFooterClick = _j === void 0 ? true : _j, _k = props.remainOpenOnSelectOrEnter, remainOpenOnSelectOrEnter = _k === void 0 ? false : _k, rest = __rest(props, ["options", "renderOption", "filterOption", "groupBy", "renderGroup", "noOptionsNode", "InputProps", "freeSolo", "value", "onInputChange", "onSelect", "popoverProps", "footer", "listItemProps", "listProps", "onUnselectedEnter", "closeOnFooterClick", "remainOpenOnSelectOrEnter"]);
|
|
33
33
|
var inputContainerRef = React.useRef(null);
|
|
34
34
|
var inputRef = React.useRef(null);
|
|
35
35
|
var onRef = React.useRef(null);
|
|
@@ -60,22 +60,21 @@ var Autocomplete = function (props) {
|
|
|
60
60
|
if (freeSolo && value.length > 0 && filteredOptions.length === 0) {
|
|
61
61
|
filteredOptions.push(value);
|
|
62
62
|
}
|
|
63
|
+
var focusInput = function () { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
63
64
|
var handleChange = function (v) {
|
|
64
65
|
onSelect(v);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (!focusOnSelect)
|
|
68
|
-
return current === null || current === void 0 ? void 0 : current.focus();
|
|
66
|
+
if (!remainOpenOnSelectOrEnter)
|
|
67
|
+
closeMenu();
|
|
69
68
|
};
|
|
70
69
|
var closeMenu = function () {
|
|
70
|
+
var _a;
|
|
71
71
|
setOn(undefined);
|
|
72
72
|
setOpen(false);
|
|
73
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
73
74
|
};
|
|
74
|
-
var openMenu = function () {
|
|
75
|
-
setOpen(true);
|
|
76
|
-
};
|
|
75
|
+
var openMenu = function () { return setOpen(true); };
|
|
77
76
|
var handleKeys = function (_a) {
|
|
78
|
-
var _b
|
|
77
|
+
var _b;
|
|
79
78
|
var code = _a.code;
|
|
80
79
|
if (code === "Escape") {
|
|
81
80
|
closeMenu();
|
|
@@ -90,14 +89,11 @@ var Autocomplete = function (props) {
|
|
|
90
89
|
if (child && child.nodeName === "A")
|
|
91
90
|
(_b = child.click) === null || _b === void 0 ? void 0 : _b.call(child);
|
|
92
91
|
current.click();
|
|
93
|
-
if (!focusOnSelect)
|
|
94
|
-
return (_c = inputRef.current) === null || _c === void 0 ? void 0 : _c.blur();
|
|
95
92
|
}
|
|
96
93
|
else if (onUnselectedEnter) {
|
|
97
94
|
onUnselectedEnter();
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return (_d = inputRef.current) === null || _d === void 0 ? void 0 : _d.blur();
|
|
95
|
+
if (!remainOpenOnSelectOrEnter)
|
|
96
|
+
closeMenu();
|
|
101
97
|
}
|
|
102
98
|
}
|
|
103
99
|
if (modulo > 0 && code === "ArrowDown") {
|
|
@@ -132,8 +128,7 @@ var Autocomplete = function (props) {
|
|
|
132
128
|
!open && openMenu();
|
|
133
129
|
}
|
|
134
130
|
else {
|
|
135
|
-
|
|
136
|
-
current && current.focus();
|
|
131
|
+
focusInput();
|
|
137
132
|
}
|
|
138
133
|
}, onClick: function () {
|
|
139
134
|
!open && openMenu();
|