@yamada-ui/autocomplete 0.5.5 → 0.6.0
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/dist/autocomplete-create.js +1 -0
- package/dist/autocomplete-create.mjs +1 -1
- package/dist/autocomplete-empty.js +1 -0
- package/dist/autocomplete-empty.mjs +1 -1
- package/dist/autocomplete-icon.js +1 -0
- package/dist/autocomplete-icon.mjs +1 -1
- package/dist/autocomplete-list.js +3 -2
- package/dist/autocomplete-list.mjs +1 -1
- package/dist/autocomplete-option-group.d.mts +1 -1
- package/dist/autocomplete-option-group.d.ts +1 -1
- package/dist/autocomplete-option-group.js +1 -0
- package/dist/autocomplete-option-group.mjs +1 -1
- package/dist/autocomplete-option.d.mts +1 -1
- package/dist/autocomplete-option.d.ts +1 -1
- package/dist/autocomplete-option.js +1 -0
- package/dist/autocomplete-option.mjs +1 -1
- package/dist/autocomplete.d.mts +1 -1
- package/dist/autocomplete.d.ts +1 -1
- package/dist/autocomplete.js +64 -21
- package/dist/autocomplete.mjs +1 -1
- package/dist/{chunk-GQ4NNX5K.mjs → chunk-TZHEVPHW.mjs} +94 -56
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +98 -47
- package/dist/index.mjs +1 -1
- package/dist/multi-autocomplete.d.mts +1 -1
- package/dist/multi-autocomplete.d.ts +1 -1
- package/dist/multi-autocomplete.js +77 -34
- package/dist/multi-autocomplete.mjs +1 -1
- package/dist/{use-autocomplete-3e77a4da.d.ts → use-autocomplete-72ef1a50.d.ts} +7 -2
- package/dist/use-autocomplete.d.mts +1 -1
- package/dist/use-autocomplete.d.ts +1 -1
- package/dist/use-autocomplete.js +45 -10
- package/dist/use-autocomplete.mjs +1 -1
- package/package.json +10 -10
|
@@ -37,6 +37,7 @@ var import_react2 = require("react");
|
|
|
37
37
|
// src/use-autocomplete.tsx
|
|
38
38
|
var import_core = require("@yamada-ui/core");
|
|
39
39
|
var import_form_control = require("@yamada-ui/form-control");
|
|
40
|
+
var import_popover = require("@yamada-ui/popover");
|
|
40
41
|
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
|
41
42
|
var import_use_descendant = require("@yamada-ui/use-descendant");
|
|
42
43
|
var import_use_outside_click = require("@yamada-ui/use-outside-click");
|
|
@@ -37,6 +37,7 @@ var import_react2 = require("react");
|
|
|
37
37
|
// src/use-autocomplete.tsx
|
|
38
38
|
var import_core = require("@yamada-ui/core");
|
|
39
39
|
var import_form_control = require("@yamada-ui/form-control");
|
|
40
|
+
var import_popover = require("@yamada-ui/popover");
|
|
40
41
|
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
|
41
42
|
var import_use_descendant = require("@yamada-ui/use-descendant");
|
|
42
43
|
var import_use_outside_click = require("@yamada-ui/use-outside-click");
|
|
@@ -35,6 +35,7 @@ var import_react2 = require("react");
|
|
|
35
35
|
// src/use-autocomplete.tsx
|
|
36
36
|
var import_core = require("@yamada-ui/core");
|
|
37
37
|
var import_form_control = require("@yamada-ui/form-control");
|
|
38
|
+
var import_popover = require("@yamada-ui/popover");
|
|
38
39
|
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
|
39
40
|
var import_use_descendant = require("@yamada-ui/use-descendant");
|
|
40
41
|
var import_use_outside_click = require("@yamada-ui/use-outside-click");
|
|
@@ -25,12 +25,13 @@ __export(autocomplete_list_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(autocomplete_list_exports);
|
|
27
27
|
var import_core2 = require("@yamada-ui/core");
|
|
28
|
-
var
|
|
28
|
+
var import_popover2 = require("@yamada-ui/popover");
|
|
29
29
|
var import_utils2 = require("@yamada-ui/utils");
|
|
30
30
|
|
|
31
31
|
// src/use-autocomplete.tsx
|
|
32
32
|
var import_core = require("@yamada-ui/core");
|
|
33
33
|
var import_form_control = require("@yamada-ui/form-control");
|
|
34
|
+
var import_popover = require("@yamada-ui/popover");
|
|
34
35
|
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
|
35
36
|
var import_use_descendant = require("@yamada-ui/use-descendant");
|
|
36
37
|
var import_use_outside_click = require("@yamada-ui/use-outside-click");
|
|
@@ -118,7 +119,7 @@ var AutocompleteList = (0, import_core2.forwardRef)(
|
|
|
118
119
|
minW = (_h = minW != null ? minW : minWidth) != null ? _h : (_g = (_e = styles.list) == null ? void 0 : _e.minW) != null ? _g : (_f = styles.list) == null ? void 0 : _f.minWidth;
|
|
119
120
|
const css = { ...styles.list };
|
|
120
121
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
121
|
-
|
|
122
|
+
import_popover2.PopoverContent,
|
|
122
123
|
{
|
|
123
124
|
className: (0, import_utils2.cx)("ui-autocomplete__list", className),
|
|
124
125
|
w,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _yamada_ui_core from '@yamada-ui/core';
|
|
2
2
|
import { HTMLUIProps } from '@yamada-ui/core';
|
|
3
|
-
import { U as UseAutocompleteOptionGroupProps } from './use-autocomplete-
|
|
3
|
+
import { U as UseAutocompleteOptionGroupProps } from './use-autocomplete-72ef1a50.js';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import 'react';
|
|
6
6
|
import '@yamada-ui/form-control';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _yamada_ui_core from '@yamada-ui/core';
|
|
2
2
|
import { HTMLUIProps } from '@yamada-ui/core';
|
|
3
|
-
import { U as UseAutocompleteOptionGroupProps } from './use-autocomplete-
|
|
3
|
+
import { U as UseAutocompleteOptionGroupProps } from './use-autocomplete-72ef1a50.js';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import 'react';
|
|
6
6
|
import '@yamada-ui/form-control';
|
|
@@ -30,6 +30,7 @@ var import_utils2 = require("@yamada-ui/utils");
|
|
|
30
30
|
// src/use-autocomplete.tsx
|
|
31
31
|
var import_core = require("@yamada-ui/core");
|
|
32
32
|
var import_form_control = require("@yamada-ui/form-control");
|
|
33
|
+
var import_popover = require("@yamada-ui/popover");
|
|
33
34
|
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
|
34
35
|
var import_use_descendant = require("@yamada-ui/use-descendant");
|
|
35
36
|
var import_use_outside_click = require("@yamada-ui/use-outside-click");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '@yamada-ui/core';
|
|
2
2
|
import 'react';
|
|
3
|
-
export { A as AutocompleteOption, a as AutocompleteOptionProps } from './use-autocomplete-
|
|
3
|
+
export { A as AutocompleteOption, a as AutocompleteOptionProps } from './use-autocomplete-72ef1a50.js';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import '@yamada-ui/form-control';
|
|
6
6
|
import '@yamada-ui/popover';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '@yamada-ui/core';
|
|
2
2
|
import 'react';
|
|
3
|
-
export { A as AutocompleteOption, a as AutocompleteOptionProps } from './use-autocomplete-
|
|
3
|
+
export { A as AutocompleteOption, a as AutocompleteOptionProps } from './use-autocomplete-72ef1a50.js';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import '@yamada-ui/form-control';
|
|
6
6
|
import '@yamada-ui/popover';
|
|
@@ -37,6 +37,7 @@ var import_react2 = require("react");
|
|
|
37
37
|
// src/use-autocomplete.tsx
|
|
38
38
|
var import_core = require("@yamada-ui/core");
|
|
39
39
|
var import_form_control = require("@yamada-ui/form-control");
|
|
40
|
+
var import_popover = require("@yamada-ui/popover");
|
|
40
41
|
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
|
41
42
|
var import_use_descendant = require("@yamada-ui/use-descendant");
|
|
42
43
|
var import_use_outside_click = require("@yamada-ui/use-outside-click");
|
package/dist/autocomplete.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import * as _yamada_ui_core from '@yamada-ui/core';
|
|
|
2
2
|
import { ThemeProps, HTMLUIProps } from '@yamada-ui/core';
|
|
3
3
|
import { AutocompleteIconProps } from './autocomplete-icon.mjs';
|
|
4
4
|
import { AutocompleteListProps } from './autocomplete-list.mjs';
|
|
5
|
-
import { c as UseAutocompleteProps } from './use-autocomplete-
|
|
5
|
+
import { c as UseAutocompleteProps } from './use-autocomplete-72ef1a50.js';
|
|
6
6
|
import 'react';
|
|
7
7
|
import 'react/jsx-runtime';
|
|
8
8
|
import '@yamada-ui/form-control';
|
package/dist/autocomplete.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as _yamada_ui_core from '@yamada-ui/core';
|
|
|
2
2
|
import { ThemeProps, HTMLUIProps } from '@yamada-ui/core';
|
|
3
3
|
import { AutocompleteIconProps } from './autocomplete-icon.js';
|
|
4
4
|
import { AutocompleteListProps } from './autocomplete-list.js';
|
|
5
|
-
import { c as UseAutocompleteProps } from './use-autocomplete-
|
|
5
|
+
import { c as UseAutocompleteProps } from './use-autocomplete-72ef1a50.js';
|
|
6
6
|
import 'react';
|
|
7
7
|
import 'react/jsx-runtime';
|
|
8
8
|
import '@yamada-ui/form-control';
|
package/dist/autocomplete.js
CHANGED
|
@@ -25,7 +25,7 @@ __export(autocomplete_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(autocomplete_exports);
|
|
27
27
|
var import_core8 = require("@yamada-ui/core");
|
|
28
|
-
var
|
|
28
|
+
var import_popover3 = require("@yamada-ui/popover");
|
|
29
29
|
var import_utils8 = require("@yamada-ui/utils");
|
|
30
30
|
|
|
31
31
|
// src/autocomplete-icon.tsx
|
|
@@ -38,6 +38,7 @@ var import_react2 = require("react");
|
|
|
38
38
|
// src/use-autocomplete.tsx
|
|
39
39
|
var import_core6 = require("@yamada-ui/core");
|
|
40
40
|
var import_form_control = require("@yamada-ui/form-control");
|
|
41
|
+
var import_popover2 = require("@yamada-ui/popover");
|
|
41
42
|
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
|
42
43
|
var import_use_descendant = require("@yamada-ui/use-descendant");
|
|
43
44
|
var import_use_outside_click = require("@yamada-ui/use-outside-click");
|
|
@@ -388,6 +389,7 @@ var useAutocomplete = ({
|
|
|
388
389
|
closeOnBlur = true,
|
|
389
390
|
closeOnEsc = true,
|
|
390
391
|
allowCreate = false,
|
|
392
|
+
allowFree = false,
|
|
391
393
|
insertPositionItem = "first",
|
|
392
394
|
emptyMessage = "No results found",
|
|
393
395
|
format = defaultFormat,
|
|
@@ -404,12 +406,13 @@ var useAutocomplete = ({
|
|
|
404
406
|
const formControlProps = (0, import_utils6.pickObject)(rest, import_form_control.formControlProperties);
|
|
405
407
|
const [containerProps, inputProps] = (0, import_utils6.splitObject)(
|
|
406
408
|
(0, import_utils6.omitObject)(rest, [
|
|
409
|
+
...import_popover2.popoverProperties,
|
|
407
410
|
"id",
|
|
408
411
|
"value",
|
|
409
412
|
"defaultValue",
|
|
410
413
|
"onChange",
|
|
411
|
-
"
|
|
412
|
-
"
|
|
414
|
+
"onCreate",
|
|
415
|
+
"onSearch"
|
|
413
416
|
]),
|
|
414
417
|
import_core6.layoutStylesProperties
|
|
415
418
|
);
|
|
@@ -674,6 +677,10 @@ var useAutocomplete = ({
|
|
|
674
677
|
var _a;
|
|
675
678
|
return (_a = node.textContent) != null ? _a : "";
|
|
676
679
|
});
|
|
680
|
+
if (allowFree && selectedValues2.length === 0) {
|
|
681
|
+
selectedValues2.push(newValue);
|
|
682
|
+
setInputValue("");
|
|
683
|
+
}
|
|
677
684
|
setDisplayValue((prev) => {
|
|
678
685
|
if (!isMulti) {
|
|
679
686
|
return selectedValues2[0];
|
|
@@ -690,7 +697,7 @@ var useAutocomplete = ({
|
|
|
690
697
|
}
|
|
691
698
|
});
|
|
692
699
|
},
|
|
693
|
-
[descendants, isMulti]
|
|
700
|
+
[descendants, isMulti, allowFree]
|
|
694
701
|
);
|
|
695
702
|
const onChange = (0, import_react.useCallback)(
|
|
696
703
|
(newValue) => {
|
|
@@ -706,11 +713,26 @@ var useAutocomplete = ({
|
|
|
706
713
|
}
|
|
707
714
|
}
|
|
708
715
|
});
|
|
716
|
+
const isHit2 = descendants.values().filter(
|
|
717
|
+
({ node }) => {
|
|
718
|
+
var _a;
|
|
719
|
+
return format((_a = node.textContent) != null ? _a : "").includes(newValue);
|
|
720
|
+
}
|
|
721
|
+
).length > 0;
|
|
709
722
|
onChangeDisplayValue(newValue);
|
|
710
|
-
|
|
723
|
+
if (!allowFree || isHit2) {
|
|
724
|
+
setInputValue("");
|
|
725
|
+
}
|
|
711
726
|
rebirthOptions(false);
|
|
712
727
|
},
|
|
713
|
-
[
|
|
728
|
+
[
|
|
729
|
+
allowFree,
|
|
730
|
+
onChangeDisplayValue,
|
|
731
|
+
rebirthOptions,
|
|
732
|
+
setValue,
|
|
733
|
+
descendants,
|
|
734
|
+
format
|
|
735
|
+
]
|
|
714
736
|
);
|
|
715
737
|
const onSelect = (0, import_react.useCallback)(() => {
|
|
716
738
|
var _a, _b;
|
|
@@ -844,11 +866,15 @@ var useAutocomplete = ({
|
|
|
844
866
|
return;
|
|
845
867
|
if (!closeOnBlur && isHit)
|
|
846
868
|
return;
|
|
847
|
-
|
|
869
|
+
if (allowFree && !!inputValue) {
|
|
870
|
+
onChange(inputValue);
|
|
871
|
+
} else {
|
|
872
|
+
setInputValue("");
|
|
873
|
+
}
|
|
848
874
|
if (isOpen)
|
|
849
875
|
onClose();
|
|
850
876
|
},
|
|
851
|
-
[closeOnBlur, isHit, isOpen, onClose]
|
|
877
|
+
[closeOnBlur, isHit, isOpen, inputValue, allowFree, onClose, onChange]
|
|
852
878
|
);
|
|
853
879
|
const onKeyDown = (0, import_react.useCallback)(
|
|
854
880
|
(ev) => {
|
|
@@ -863,7 +889,11 @@ var useAutocomplete = ({
|
|
|
863
889
|
ArrowDown: isFocused ? () => onFocusNext() : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
|
|
864
890
|
ArrowUp: isFocused ? () => onFocusPrev() : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusLastOrSelected) : void 0,
|
|
865
891
|
Space: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
|
|
866
|
-
Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) :
|
|
892
|
+
Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) : allowFree && isMulti ? () => {
|
|
893
|
+
if (inputValue)
|
|
894
|
+
onChange(inputValue);
|
|
895
|
+
setFocusedIndex(0);
|
|
896
|
+
} : void 0,
|
|
867
897
|
Home: isOpen ? onFocusFirst : void 0,
|
|
868
898
|
End: isOpen ? onFocusLast : void 0,
|
|
869
899
|
Escape: closeOnEsc ? onClose : void 0,
|
|
@@ -877,11 +907,13 @@ var useAutocomplete = ({
|
|
|
877
907
|
action(ev);
|
|
878
908
|
},
|
|
879
909
|
[
|
|
910
|
+
allowFree,
|
|
880
911
|
formControlProps,
|
|
881
912
|
displayValue,
|
|
882
913
|
inputValue,
|
|
883
914
|
onOpen,
|
|
884
915
|
isFocused,
|
|
916
|
+
isMulti,
|
|
885
917
|
onFocusFirstOrSelected,
|
|
886
918
|
onFocusNext,
|
|
887
919
|
onFocusLastOrSelected,
|
|
@@ -895,7 +927,8 @@ var useAutocomplete = ({
|
|
|
895
927
|
closeOnEsc,
|
|
896
928
|
onClose,
|
|
897
929
|
isEmptyValue,
|
|
898
|
-
onDelete
|
|
930
|
+
onDelete,
|
|
931
|
+
onChange
|
|
899
932
|
]
|
|
900
933
|
);
|
|
901
934
|
(0, import_react.useEffect)(() => {
|
|
@@ -920,7 +953,7 @@ var useAutocomplete = ({
|
|
|
920
953
|
maxSelectedValues
|
|
921
954
|
]);
|
|
922
955
|
(0, import_utils6.useUpdateEffect)(() => {
|
|
923
|
-
if (isOpen)
|
|
956
|
+
if (isOpen || allowFree)
|
|
924
957
|
return;
|
|
925
958
|
setFocusedIndex(-1);
|
|
926
959
|
setInputValue("");
|
|
@@ -940,6 +973,7 @@ var useAutocomplete = ({
|
|
|
940
973
|
});
|
|
941
974
|
const getPopoverProps = (0, import_react.useCallback)(
|
|
942
975
|
(props) => ({
|
|
976
|
+
matchWidth: true,
|
|
943
977
|
...rest,
|
|
944
978
|
...props,
|
|
945
979
|
isOpen,
|
|
@@ -990,6 +1024,7 @@ var useAutocomplete = ({
|
|
|
990
1024
|
omitSelectedValues,
|
|
991
1025
|
closeOnSelect,
|
|
992
1026
|
allowCreate,
|
|
1027
|
+
allowFree,
|
|
993
1028
|
emptyMessage,
|
|
994
1029
|
isOpen,
|
|
995
1030
|
isAllSelected,
|
|
@@ -1477,7 +1512,6 @@ var Autocomplete = (0, import_core8.forwardRef)(
|
|
|
1477
1512
|
h != null ? h : h = height;
|
|
1478
1513
|
minH != null ? minH : minH = minHeight;
|
|
1479
1514
|
const css = {
|
|
1480
|
-
position: "relative",
|
|
1481
1515
|
w: "100%",
|
|
1482
1516
|
h: "fit-content",
|
|
1483
1517
|
color,
|
|
@@ -1494,23 +1528,32 @@ var Autocomplete = (0, import_core8.forwardRef)(
|
|
|
1494
1528
|
isEmpty,
|
|
1495
1529
|
styles
|
|
1496
1530
|
},
|
|
1497
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1531
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_popover3.Popover, { ...getPopoverProps(), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
1498
1532
|
import_core8.ui.div,
|
|
1499
1533
|
{
|
|
1500
1534
|
className: (0, import_utils8.cx)("ui-autocomplete", className),
|
|
1501
1535
|
__css: css,
|
|
1502
1536
|
...getContainerProps(containerProps),
|
|
1503
1537
|
children: [
|
|
1504
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.
|
|
1505
|
-
|
|
1538
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
1539
|
+
import_core8.ui.div,
|
|
1506
1540
|
{
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1541
|
+
className: "ui-autocomplete__inner",
|
|
1542
|
+
__css: { position: "relative", ...styles.inner },
|
|
1543
|
+
children: [
|
|
1544
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1545
|
+
AutocompleteField,
|
|
1546
|
+
{
|
|
1547
|
+
h,
|
|
1548
|
+
minH,
|
|
1549
|
+
inputProps,
|
|
1550
|
+
...getFieldProps({}, ref)
|
|
1551
|
+
}
|
|
1552
|
+
),
|
|
1553
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteIcon, { ...iconProps, ...formControlProps })
|
|
1554
|
+
]
|
|
1511
1555
|
}
|
|
1512
1556
|
),
|
|
1513
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteIcon, { ...iconProps, ...formControlProps }),
|
|
1514
1557
|
!isEmpty ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(AutocompleteList, { ...listProps, children: [
|
|
1515
1558
|
allowCreate ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteCreate, {}) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteEmpty, {}),
|
|
1516
1559
|
children != null ? children : computedChildren
|
|
@@ -1535,7 +1578,7 @@ var AutocompleteField = (0, import_core8.forwardRef)(
|
|
|
1535
1578
|
...styles.field,
|
|
1536
1579
|
cursor: "text"
|
|
1537
1580
|
};
|
|
1538
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1581
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_popover3.PopoverTrigger, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1539
1582
|
import_core8.ui.div,
|
|
1540
1583
|
{
|
|
1541
1584
|
className: (0, import_utils8.cx)("ui-autocomplete__field", className),
|