@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
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { ThemeProps, HTMLUIProps } from '@yamada-ui/core';
|
|
|
3
3
|
import { FC, MouseEventHandler } from 'react';
|
|
4
4
|
import { AutocompleteIconProps } from './autocomplete-icon.mjs';
|
|
5
5
|
import { AutocompleteListProps } from './autocomplete-list.mjs';
|
|
6
|
-
import { c as UseAutocompleteProps } from './use-autocomplete-
|
|
6
|
+
import { c as UseAutocompleteProps } from './use-autocomplete-72ef1a50.js';
|
|
7
7
|
import 'react/jsx-runtime';
|
|
8
8
|
import '@yamada-ui/form-control';
|
|
9
9
|
import '@yamada-ui/popover';
|
|
@@ -3,7 +3,7 @@ import { ThemeProps, HTMLUIProps } from '@yamada-ui/core';
|
|
|
3
3
|
import { FC, MouseEventHandler } from 'react';
|
|
4
4
|
import { AutocompleteIconProps } from './autocomplete-icon.js';
|
|
5
5
|
import { AutocompleteListProps } from './autocomplete-list.js';
|
|
6
|
-
import { c as UseAutocompleteProps } from './use-autocomplete-
|
|
6
|
+
import { c as UseAutocompleteProps } from './use-autocomplete-72ef1a50.js';
|
|
7
7
|
import 'react/jsx-runtime';
|
|
8
8
|
import '@yamada-ui/form-control';
|
|
9
9
|
import '@yamada-ui/popover';
|
|
@@ -25,7 +25,7 @@ __export(multi_autocomplete_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(multi_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
|
var import_react3 = require("react");
|
|
31
31
|
|
|
@@ -39,6 +39,7 @@ var import_react2 = require("react");
|
|
|
39
39
|
// src/use-autocomplete.tsx
|
|
40
40
|
var import_core6 = require("@yamada-ui/core");
|
|
41
41
|
var import_form_control = require("@yamada-ui/form-control");
|
|
42
|
+
var import_popover2 = require("@yamada-ui/popover");
|
|
42
43
|
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
|
43
44
|
var import_use_descendant = require("@yamada-ui/use-descendant");
|
|
44
45
|
var import_use_outside_click = require("@yamada-ui/use-outside-click");
|
|
@@ -389,6 +390,7 @@ var useAutocomplete = ({
|
|
|
389
390
|
closeOnBlur = true,
|
|
390
391
|
closeOnEsc = true,
|
|
391
392
|
allowCreate = false,
|
|
393
|
+
allowFree = false,
|
|
392
394
|
insertPositionItem = "first",
|
|
393
395
|
emptyMessage = "No results found",
|
|
394
396
|
format = defaultFormat,
|
|
@@ -405,12 +407,13 @@ var useAutocomplete = ({
|
|
|
405
407
|
const formControlProps = (0, import_utils6.pickObject)(rest, import_form_control.formControlProperties);
|
|
406
408
|
const [containerProps, inputProps] = (0, import_utils6.splitObject)(
|
|
407
409
|
(0, import_utils6.omitObject)(rest, [
|
|
410
|
+
...import_popover2.popoverProperties,
|
|
408
411
|
"id",
|
|
409
412
|
"value",
|
|
410
413
|
"defaultValue",
|
|
411
414
|
"onChange",
|
|
412
|
-
"
|
|
413
|
-
"
|
|
415
|
+
"onCreate",
|
|
416
|
+
"onSearch"
|
|
414
417
|
]),
|
|
415
418
|
import_core6.layoutStylesProperties
|
|
416
419
|
);
|
|
@@ -675,6 +678,10 @@ var useAutocomplete = ({
|
|
|
675
678
|
var _a;
|
|
676
679
|
return (_a = node.textContent) != null ? _a : "";
|
|
677
680
|
});
|
|
681
|
+
if (allowFree && selectedValues2.length === 0) {
|
|
682
|
+
selectedValues2.push(newValue);
|
|
683
|
+
setInputValue("");
|
|
684
|
+
}
|
|
678
685
|
setDisplayValue((prev) => {
|
|
679
686
|
if (!isMulti) {
|
|
680
687
|
return selectedValues2[0];
|
|
@@ -691,7 +698,7 @@ var useAutocomplete = ({
|
|
|
691
698
|
}
|
|
692
699
|
});
|
|
693
700
|
},
|
|
694
|
-
[descendants, isMulti]
|
|
701
|
+
[descendants, isMulti, allowFree]
|
|
695
702
|
);
|
|
696
703
|
const onChange = (0, import_react.useCallback)(
|
|
697
704
|
(newValue) => {
|
|
@@ -707,11 +714,26 @@ var useAutocomplete = ({
|
|
|
707
714
|
}
|
|
708
715
|
}
|
|
709
716
|
});
|
|
717
|
+
const isHit2 = descendants.values().filter(
|
|
718
|
+
({ node }) => {
|
|
719
|
+
var _a;
|
|
720
|
+
return format((_a = node.textContent) != null ? _a : "").includes(newValue);
|
|
721
|
+
}
|
|
722
|
+
).length > 0;
|
|
710
723
|
onChangeDisplayValue(newValue);
|
|
711
|
-
|
|
724
|
+
if (!allowFree || isHit2) {
|
|
725
|
+
setInputValue("");
|
|
726
|
+
}
|
|
712
727
|
rebirthOptions(false);
|
|
713
728
|
},
|
|
714
|
-
[
|
|
729
|
+
[
|
|
730
|
+
allowFree,
|
|
731
|
+
onChangeDisplayValue,
|
|
732
|
+
rebirthOptions,
|
|
733
|
+
setValue,
|
|
734
|
+
descendants,
|
|
735
|
+
format
|
|
736
|
+
]
|
|
715
737
|
);
|
|
716
738
|
const onSelect = (0, import_react.useCallback)(() => {
|
|
717
739
|
var _a, _b;
|
|
@@ -845,11 +867,15 @@ var useAutocomplete = ({
|
|
|
845
867
|
return;
|
|
846
868
|
if (!closeOnBlur && isHit)
|
|
847
869
|
return;
|
|
848
|
-
|
|
870
|
+
if (allowFree && !!inputValue) {
|
|
871
|
+
onChange(inputValue);
|
|
872
|
+
} else {
|
|
873
|
+
setInputValue("");
|
|
874
|
+
}
|
|
849
875
|
if (isOpen)
|
|
850
876
|
onClose();
|
|
851
877
|
},
|
|
852
|
-
[closeOnBlur, isHit, isOpen, onClose]
|
|
878
|
+
[closeOnBlur, isHit, isOpen, inputValue, allowFree, onClose, onChange]
|
|
853
879
|
);
|
|
854
880
|
const onKeyDown = (0, import_react.useCallback)(
|
|
855
881
|
(ev) => {
|
|
@@ -864,7 +890,11 @@ var useAutocomplete = ({
|
|
|
864
890
|
ArrowDown: isFocused ? () => onFocusNext() : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
|
|
865
891
|
ArrowUp: isFocused ? () => onFocusPrev() : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusLastOrSelected) : void 0,
|
|
866
892
|
Space: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
|
|
867
|
-
Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) :
|
|
893
|
+
Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) : allowFree && isMulti ? () => {
|
|
894
|
+
if (inputValue)
|
|
895
|
+
onChange(inputValue);
|
|
896
|
+
setFocusedIndex(0);
|
|
897
|
+
} : void 0,
|
|
868
898
|
Home: isOpen ? onFocusFirst : void 0,
|
|
869
899
|
End: isOpen ? onFocusLast : void 0,
|
|
870
900
|
Escape: closeOnEsc ? onClose : void 0,
|
|
@@ -878,11 +908,13 @@ var useAutocomplete = ({
|
|
|
878
908
|
action(ev);
|
|
879
909
|
},
|
|
880
910
|
[
|
|
911
|
+
allowFree,
|
|
881
912
|
formControlProps,
|
|
882
913
|
displayValue,
|
|
883
914
|
inputValue,
|
|
884
915
|
onOpen,
|
|
885
916
|
isFocused,
|
|
917
|
+
isMulti,
|
|
886
918
|
onFocusFirstOrSelected,
|
|
887
919
|
onFocusNext,
|
|
888
920
|
onFocusLastOrSelected,
|
|
@@ -896,7 +928,8 @@ var useAutocomplete = ({
|
|
|
896
928
|
closeOnEsc,
|
|
897
929
|
onClose,
|
|
898
930
|
isEmptyValue,
|
|
899
|
-
onDelete
|
|
931
|
+
onDelete,
|
|
932
|
+
onChange
|
|
900
933
|
]
|
|
901
934
|
);
|
|
902
935
|
(0, import_react.useEffect)(() => {
|
|
@@ -921,7 +954,7 @@ var useAutocomplete = ({
|
|
|
921
954
|
maxSelectedValues
|
|
922
955
|
]);
|
|
923
956
|
(0, import_utils6.useUpdateEffect)(() => {
|
|
924
|
-
if (isOpen)
|
|
957
|
+
if (isOpen || allowFree)
|
|
925
958
|
return;
|
|
926
959
|
setFocusedIndex(-1);
|
|
927
960
|
setInputValue("");
|
|
@@ -941,6 +974,7 @@ var useAutocomplete = ({
|
|
|
941
974
|
});
|
|
942
975
|
const getPopoverProps = (0, import_react.useCallback)(
|
|
943
976
|
(props) => ({
|
|
977
|
+
matchWidth: true,
|
|
944
978
|
...rest,
|
|
945
979
|
...props,
|
|
946
980
|
isOpen,
|
|
@@ -991,6 +1025,7 @@ var useAutocomplete = ({
|
|
|
991
1025
|
omitSelectedValues,
|
|
992
1026
|
closeOnSelect,
|
|
993
1027
|
allowCreate,
|
|
1028
|
+
allowFree,
|
|
994
1029
|
emptyMessage,
|
|
995
1030
|
isOpen,
|
|
996
1031
|
isAllSelected,
|
|
@@ -1517,7 +1552,6 @@ var MultiAutocomplete = (0, import_core8.forwardRef)(
|
|
|
1517
1552
|
h != null ? h : h = height;
|
|
1518
1553
|
minH != null ? minH : minH = minHeight;
|
|
1519
1554
|
const css = {
|
|
1520
|
-
position: "relative",
|
|
1521
1555
|
w: "100%",
|
|
1522
1556
|
h: "fit-content",
|
|
1523
1557
|
color,
|
|
@@ -1535,33 +1569,42 @@ var MultiAutocomplete = (0, import_core8.forwardRef)(
|
|
|
1535
1569
|
isEmpty,
|
|
1536
1570
|
styles
|
|
1537
1571
|
},
|
|
1538
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1572
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_popover3.Popover, { ...getPopoverProps(), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
1539
1573
|
import_core8.ui.div,
|
|
1540
1574
|
{
|
|
1541
|
-
className: (0, import_utils8.cx)("ui-autocomplete", className),
|
|
1575
|
+
className: (0, import_utils8.cx)("ui-multi-autocomplete", className),
|
|
1542
1576
|
__css: css,
|
|
1543
1577
|
...getContainerProps(containerProps),
|
|
1544
1578
|
children: [
|
|
1545
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.
|
|
1546
|
-
|
|
1579
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
1580
|
+
import_core8.ui.div,
|
|
1547
1581
|
{
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1582
|
+
className: "ui-multi-autocomplete__inner",
|
|
1583
|
+
__css: { position: "relative", ...styles.inner },
|
|
1584
|
+
children: [
|
|
1585
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1586
|
+
MultiAutocompleteField,
|
|
1587
|
+
{
|
|
1588
|
+
component,
|
|
1589
|
+
separator,
|
|
1590
|
+
keepPlaceholder,
|
|
1591
|
+
h,
|
|
1592
|
+
minH,
|
|
1593
|
+
inputProps,
|
|
1594
|
+
...getFieldProps({}, ref)
|
|
1595
|
+
}
|
|
1596
|
+
),
|
|
1597
|
+
isClearable && value.length ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1598
|
+
AutocompleteClearIcon,
|
|
1599
|
+
{
|
|
1600
|
+
...clearIconProps,
|
|
1601
|
+
onClick: (0, import_utils8.handlerAll)(clearIconProps == null ? void 0 : clearIconProps.onClick, onClear),
|
|
1602
|
+
...formControlProps
|
|
1603
|
+
}
|
|
1604
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteIcon, { ...iconProps, ...formControlProps })
|
|
1605
|
+
]
|
|
1555
1606
|
}
|
|
1556
1607
|
),
|
|
1557
|
-
isClearable && value.length ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1558
|
-
AutocompleteClearIcon,
|
|
1559
|
-
{
|
|
1560
|
-
...clearIconProps,
|
|
1561
|
-
onClick: (0, import_utils8.handlerAll)(clearIconProps == null ? void 0 : clearIconProps.onClick, onClear),
|
|
1562
|
-
...formControlProps
|
|
1563
|
-
}
|
|
1564
|
-
) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteIcon, { ...iconProps, ...formControlProps }),
|
|
1565
1608
|
!isEmpty ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(AutocompleteList, { ...listProps, children: [
|
|
1566
1609
|
allowCreate ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteCreate, {}) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteEmpty, {}),
|
|
1567
1610
|
children != null ? children : computedChildren
|
|
@@ -1640,10 +1683,10 @@ var MultiAutocompleteField = (0, import_core8.forwardRef)(
|
|
|
1640
1683
|
...styles.field,
|
|
1641
1684
|
cursor: "text"
|
|
1642
1685
|
};
|
|
1643
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1686
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_popover3.PopoverTrigger, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
1644
1687
|
import_core8.ui.div,
|
|
1645
1688
|
{
|
|
1646
|
-
className: (0, import_utils8.cx)("ui-autocomplete__field", className),
|
|
1689
|
+
className: (0, import_utils8.cx)("ui-multi-autocomplete__field", className),
|
|
1647
1690
|
__css: css,
|
|
1648
1691
|
py: (displayValue == null ? void 0 : displayValue.length) && component ? "0.125rem" : void 0,
|
|
1649
1692
|
...rest,
|
|
@@ -1652,7 +1695,7 @@ var MultiAutocompleteField = (0, import_core8.forwardRef)(
|
|
|
1652
1695
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1653
1696
|
import_core8.ui.input,
|
|
1654
1697
|
{
|
|
1655
|
-
className:
|
|
1698
|
+
className: "ui-multi-autocomplete__field__input",
|
|
1656
1699
|
display: "inline-block",
|
|
1657
1700
|
flex: "1",
|
|
1658
1701
|
overflow: "hidden",
|
|
@@ -3407,6 +3407,10 @@ type UseAutocompleteBaseProps<T extends string | string[] = string> = Omit<Popov
|
|
|
3407
3407
|
* @default false
|
|
3408
3408
|
*/
|
|
3409
3409
|
allowCreate?: boolean;
|
|
3410
|
+
/**
|
|
3411
|
+
* If `true`, enables the free input.
|
|
3412
|
+
*/
|
|
3413
|
+
allowFree?: boolean;
|
|
3410
3414
|
/**
|
|
3411
3415
|
* If `true`, the selected item(s) will be excluded from the list.
|
|
3412
3416
|
*
|
|
@@ -3427,7 +3431,7 @@ type UseAutocompleteBaseProps<T extends string | string[] = string> = Omit<Popov
|
|
|
3427
3431
|
items?: AutocompleteItem[];
|
|
3428
3432
|
};
|
|
3429
3433
|
type UseAutocompleteProps<T extends string | string[] = string> = Omit<HTMLUIProps<"input">, keyof UseAutocompleteBaseProps | "list" | "disabled" | "required" | "readOnly" | "size"> & UseAutocompleteBaseProps<T>;
|
|
3430
|
-
declare const useAutocomplete: <T extends string | string[] = string>({ defaultIsOpen, closeOnSelect, omitSelectedValues, maxSelectedValues, closeOnBlur, closeOnEsc, allowCreate, insertPositionItem, emptyMessage, format, placement, duration, optionProps, placeholder, items, children, ...rest }: UseAutocompleteProps<T>) => {
|
|
3434
|
+
declare const useAutocomplete: <T extends string | string[] = string>({ defaultIsOpen, closeOnSelect, omitSelectedValues, maxSelectedValues, closeOnBlur, closeOnEsc, allowCreate, allowFree, insertPositionItem, emptyMessage, format, placement, duration, optionProps, placeholder, items, children, ...rest }: UseAutocompleteProps<T>) => {
|
|
3431
3435
|
id: string | undefined;
|
|
3432
3436
|
descendants: {
|
|
3433
3437
|
register: (nodeOrOptions: HTMLElement | {
|
|
@@ -4036,6 +4040,7 @@ declare const useAutocomplete: <T extends string | string[] = string>({ defaultI
|
|
|
4036
4040
|
omitSelectedValues: boolean;
|
|
4037
4041
|
closeOnSelect: boolean;
|
|
4038
4042
|
allowCreate: boolean;
|
|
4043
|
+
allowFree: boolean;
|
|
4039
4044
|
emptyMessage: string;
|
|
4040
4045
|
isOpen: boolean;
|
|
4041
4046
|
isAllSelected: boolean;
|
|
@@ -4065,7 +4070,7 @@ declare const useAutocomplete: <T extends string | string[] = string>({ defaultI
|
|
|
4065
4070
|
getPopoverProps: (props?: PopoverProps) => PopoverProps;
|
|
4066
4071
|
getContainerProps: PropGetter;
|
|
4067
4072
|
getFieldProps: PropGetter;
|
|
4068
|
-
inputProps: Omit<
|
|
4073
|
+
inputProps: Omit<Dict, string>;
|
|
4069
4074
|
};
|
|
4070
4075
|
type UseAutocompleteReturn = ReturnType<typeof useAutocomplete>;
|
|
4071
4076
|
declare const useAutocompleteInput: () => {
|
|
@@ -4,4 +4,4 @@ import '@yamada-ui/core';
|
|
|
4
4
|
import '@yamada-ui/form-control';
|
|
5
5
|
import '@yamada-ui/popover';
|
|
6
6
|
import '@yamada-ui/utils';
|
|
7
|
-
export { d as AutocompleteDescendantsContextProvider, b as AutocompleteItem, g as AutocompleteProvider, t as UseAutocompleteCreateReturn, w as UseAutocompleteEmptyReturn, l as UseAutocompleteInputReturn, U as UseAutocompleteOptionGroupProps, o as UseAutocompleteOptionGroupReturn, p as UseAutocompleteOptionProps, r as UseAutocompleteOptionReturn, c as UseAutocompleteProps, j as UseAutocompleteReturn, i as useAutocomplete, h as useAutocompleteContext, s as useAutocompleteCreate, f as useAutocompleteDescendant, e as useAutocompleteDescendants, u as useAutocompleteDescendantsContext, v as useAutocompleteEmpty, k as useAutocompleteInput, m as useAutocompleteList, q as useAutocompleteOption, n as useAutocompleteOptionGroup } from './use-autocomplete-
|
|
7
|
+
export { d as AutocompleteDescendantsContextProvider, b as AutocompleteItem, g as AutocompleteProvider, t as UseAutocompleteCreateReturn, w as UseAutocompleteEmptyReturn, l as UseAutocompleteInputReturn, U as UseAutocompleteOptionGroupProps, o as UseAutocompleteOptionGroupReturn, p as UseAutocompleteOptionProps, r as UseAutocompleteOptionReturn, c as UseAutocompleteProps, j as UseAutocompleteReturn, i as useAutocomplete, h as useAutocompleteContext, s as useAutocompleteCreate, f as useAutocompleteDescendant, e as useAutocompleteDescendants, u as useAutocompleteDescendantsContext, v as useAutocompleteEmpty, k as useAutocompleteInput, m as useAutocompleteList, q as useAutocompleteOption, n as useAutocompleteOptionGroup } from './use-autocomplete-72ef1a50.js';
|
|
@@ -4,4 +4,4 @@ import '@yamada-ui/core';
|
|
|
4
4
|
import '@yamada-ui/form-control';
|
|
5
5
|
import '@yamada-ui/popover';
|
|
6
6
|
import '@yamada-ui/utils';
|
|
7
|
-
export { d as AutocompleteDescendantsContextProvider, b as AutocompleteItem, g as AutocompleteProvider, t as UseAutocompleteCreateReturn, w as UseAutocompleteEmptyReturn, l as UseAutocompleteInputReturn, U as UseAutocompleteOptionGroupProps, o as UseAutocompleteOptionGroupReturn, p as UseAutocompleteOptionProps, r as UseAutocompleteOptionReturn, c as UseAutocompleteProps, j as UseAutocompleteReturn, i as useAutocomplete, h as useAutocompleteContext, s as useAutocompleteCreate, f as useAutocompleteDescendant, e as useAutocompleteDescendants, u as useAutocompleteDescendantsContext, v as useAutocompleteEmpty, k as useAutocompleteInput, m as useAutocompleteList, q as useAutocompleteOption, n as useAutocompleteOptionGroup } from './use-autocomplete-
|
|
7
|
+
export { d as AutocompleteDescendantsContextProvider, b as AutocompleteItem, g as AutocompleteProvider, t as UseAutocompleteCreateReturn, w as UseAutocompleteEmptyReturn, l as UseAutocompleteInputReturn, U as UseAutocompleteOptionGroupProps, o as UseAutocompleteOptionGroupReturn, p as UseAutocompleteOptionProps, r as UseAutocompleteOptionReturn, c as UseAutocompleteProps, j as UseAutocompleteReturn, i as useAutocomplete, h as useAutocompleteContext, s as useAutocompleteCreate, f as useAutocompleteDescendant, e as useAutocompleteDescendants, u as useAutocompleteDescendantsContext, v as useAutocompleteEmpty, k as useAutocompleteInput, m as useAutocompleteList, q as useAutocompleteOption, n as useAutocompleteOptionGroup } from './use-autocomplete-72ef1a50.js';
|
package/dist/use-autocomplete.js
CHANGED
|
@@ -38,6 +38,7 @@ __export(use_autocomplete_exports, {
|
|
|
38
38
|
module.exports = __toCommonJS(use_autocomplete_exports);
|
|
39
39
|
var import_core4 = require("@yamada-ui/core");
|
|
40
40
|
var import_form_control = require("@yamada-ui/form-control");
|
|
41
|
+
var import_popover = 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");
|
|
@@ -340,6 +341,7 @@ var useAutocomplete = ({
|
|
|
340
341
|
closeOnBlur = true,
|
|
341
342
|
closeOnEsc = true,
|
|
342
343
|
allowCreate = false,
|
|
344
|
+
allowFree = false,
|
|
343
345
|
insertPositionItem = "first",
|
|
344
346
|
emptyMessage = "No results found",
|
|
345
347
|
format = defaultFormat,
|
|
@@ -356,12 +358,13 @@ var useAutocomplete = ({
|
|
|
356
358
|
const formControlProps = (0, import_utils4.pickObject)(rest, import_form_control.formControlProperties);
|
|
357
359
|
const [containerProps, inputProps] = (0, import_utils4.splitObject)(
|
|
358
360
|
(0, import_utils4.omitObject)(rest, [
|
|
361
|
+
...import_popover.popoverProperties,
|
|
359
362
|
"id",
|
|
360
363
|
"value",
|
|
361
364
|
"defaultValue",
|
|
362
365
|
"onChange",
|
|
363
|
-
"
|
|
364
|
-
"
|
|
366
|
+
"onCreate",
|
|
367
|
+
"onSearch"
|
|
365
368
|
]),
|
|
366
369
|
import_core4.layoutStylesProperties
|
|
367
370
|
);
|
|
@@ -626,6 +629,10 @@ var useAutocomplete = ({
|
|
|
626
629
|
var _a;
|
|
627
630
|
return (_a = node.textContent) != null ? _a : "";
|
|
628
631
|
});
|
|
632
|
+
if (allowFree && selectedValues2.length === 0) {
|
|
633
|
+
selectedValues2.push(newValue);
|
|
634
|
+
setInputValue("");
|
|
635
|
+
}
|
|
629
636
|
setDisplayValue((prev) => {
|
|
630
637
|
if (!isMulti) {
|
|
631
638
|
return selectedValues2[0];
|
|
@@ -642,7 +649,7 @@ var useAutocomplete = ({
|
|
|
642
649
|
}
|
|
643
650
|
});
|
|
644
651
|
},
|
|
645
|
-
[descendants, isMulti]
|
|
652
|
+
[descendants, isMulti, allowFree]
|
|
646
653
|
);
|
|
647
654
|
const onChange = (0, import_react2.useCallback)(
|
|
648
655
|
(newValue) => {
|
|
@@ -658,11 +665,26 @@ var useAutocomplete = ({
|
|
|
658
665
|
}
|
|
659
666
|
}
|
|
660
667
|
});
|
|
668
|
+
const isHit2 = descendants.values().filter(
|
|
669
|
+
({ node }) => {
|
|
670
|
+
var _a;
|
|
671
|
+
return format((_a = node.textContent) != null ? _a : "").includes(newValue);
|
|
672
|
+
}
|
|
673
|
+
).length > 0;
|
|
661
674
|
onChangeDisplayValue(newValue);
|
|
662
|
-
|
|
675
|
+
if (!allowFree || isHit2) {
|
|
676
|
+
setInputValue("");
|
|
677
|
+
}
|
|
663
678
|
rebirthOptions(false);
|
|
664
679
|
},
|
|
665
|
-
[
|
|
680
|
+
[
|
|
681
|
+
allowFree,
|
|
682
|
+
onChangeDisplayValue,
|
|
683
|
+
rebirthOptions,
|
|
684
|
+
setValue,
|
|
685
|
+
descendants,
|
|
686
|
+
format
|
|
687
|
+
]
|
|
666
688
|
);
|
|
667
689
|
const onSelect = (0, import_react2.useCallback)(() => {
|
|
668
690
|
var _a, _b;
|
|
@@ -796,11 +818,15 @@ var useAutocomplete = ({
|
|
|
796
818
|
return;
|
|
797
819
|
if (!closeOnBlur && isHit)
|
|
798
820
|
return;
|
|
799
|
-
|
|
821
|
+
if (allowFree && !!inputValue) {
|
|
822
|
+
onChange(inputValue);
|
|
823
|
+
} else {
|
|
824
|
+
setInputValue("");
|
|
825
|
+
}
|
|
800
826
|
if (isOpen)
|
|
801
827
|
onClose();
|
|
802
828
|
},
|
|
803
|
-
[closeOnBlur, isHit, isOpen, onClose]
|
|
829
|
+
[closeOnBlur, isHit, isOpen, inputValue, allowFree, onClose, onChange]
|
|
804
830
|
);
|
|
805
831
|
const onKeyDown = (0, import_react2.useCallback)(
|
|
806
832
|
(ev) => {
|
|
@@ -815,7 +841,11 @@ var useAutocomplete = ({
|
|
|
815
841
|
ArrowDown: isFocused ? () => onFocusNext() : !isOpen ? (0, import_utils4.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
|
|
816
842
|
ArrowUp: isFocused ? () => onFocusPrev() : !isOpen ? (0, import_utils4.funcAll)(onOpen, onFocusLastOrSelected) : void 0,
|
|
817
843
|
Space: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils4.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
|
|
818
|
-
Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils4.funcAll)(onOpen, onFocusFirstOrSelected) :
|
|
844
|
+
Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils4.funcAll)(onOpen, onFocusFirstOrSelected) : allowFree && isMulti ? () => {
|
|
845
|
+
if (inputValue)
|
|
846
|
+
onChange(inputValue);
|
|
847
|
+
setFocusedIndex(0);
|
|
848
|
+
} : void 0,
|
|
819
849
|
Home: isOpen ? onFocusFirst : void 0,
|
|
820
850
|
End: isOpen ? onFocusLast : void 0,
|
|
821
851
|
Escape: closeOnEsc ? onClose : void 0,
|
|
@@ -829,11 +859,13 @@ var useAutocomplete = ({
|
|
|
829
859
|
action(ev);
|
|
830
860
|
},
|
|
831
861
|
[
|
|
862
|
+
allowFree,
|
|
832
863
|
formControlProps,
|
|
833
864
|
displayValue,
|
|
834
865
|
inputValue,
|
|
835
866
|
onOpen,
|
|
836
867
|
isFocused,
|
|
868
|
+
isMulti,
|
|
837
869
|
onFocusFirstOrSelected,
|
|
838
870
|
onFocusNext,
|
|
839
871
|
onFocusLastOrSelected,
|
|
@@ -847,7 +879,8 @@ var useAutocomplete = ({
|
|
|
847
879
|
closeOnEsc,
|
|
848
880
|
onClose,
|
|
849
881
|
isEmptyValue,
|
|
850
|
-
onDelete
|
|
882
|
+
onDelete,
|
|
883
|
+
onChange
|
|
851
884
|
]
|
|
852
885
|
);
|
|
853
886
|
(0, import_react2.useEffect)(() => {
|
|
@@ -872,7 +905,7 @@ var useAutocomplete = ({
|
|
|
872
905
|
maxSelectedValues
|
|
873
906
|
]);
|
|
874
907
|
(0, import_utils4.useUpdateEffect)(() => {
|
|
875
|
-
if (isOpen)
|
|
908
|
+
if (isOpen || allowFree)
|
|
876
909
|
return;
|
|
877
910
|
setFocusedIndex(-1);
|
|
878
911
|
setInputValue("");
|
|
@@ -892,6 +925,7 @@ var useAutocomplete = ({
|
|
|
892
925
|
});
|
|
893
926
|
const getPopoverProps = (0, import_react2.useCallback)(
|
|
894
927
|
(props) => ({
|
|
928
|
+
matchWidth: true,
|
|
895
929
|
...rest,
|
|
896
930
|
...props,
|
|
897
931
|
isOpen,
|
|
@@ -942,6 +976,7 @@ var useAutocomplete = ({
|
|
|
942
976
|
omitSelectedValues,
|
|
943
977
|
closeOnSelect,
|
|
944
978
|
allowCreate,
|
|
979
|
+
allowFree,
|
|
945
980
|
emptyMessage,
|
|
946
981
|
isOpen,
|
|
947
982
|
isAllSelected,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yamada-ui/autocomplete",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Yamada UI autocomplete component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yamada",
|
|
@@ -36,16 +36,16 @@
|
|
|
36
36
|
"url": "https://github.com/hirotomoyamada/yamada-ui/issues"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@yamada-ui/core": "0.12.
|
|
39
|
+
"@yamada-ui/core": "0.12.7",
|
|
40
40
|
"@yamada-ui/utils": "0.3.3",
|
|
41
|
-
"@yamada-ui/icon": "0.3.
|
|
42
|
-
"@yamada-ui/select": "0.5.
|
|
43
|
-
"@yamada-ui/form-control": "0.3.
|
|
44
|
-
"@yamada-ui/popover": "0.3.
|
|
45
|
-
"@yamada-ui/use-descendant": "0.2.
|
|
46
|
-
"@yamada-ui/use-clickable": "0.3.
|
|
47
|
-
"@yamada-ui/use-outside-click": "0.2.
|
|
48
|
-
"@yamada-ui/use-controllable-state": "0.3.
|
|
41
|
+
"@yamada-ui/icon": "0.3.17",
|
|
42
|
+
"@yamada-ui/select": "0.5.6",
|
|
43
|
+
"@yamada-ui/form-control": "0.3.20",
|
|
44
|
+
"@yamada-ui/popover": "0.3.24",
|
|
45
|
+
"@yamada-ui/use-descendant": "0.2.6",
|
|
46
|
+
"@yamada-ui/use-clickable": "0.3.6",
|
|
47
|
+
"@yamada-ui/use-outside-click": "0.2.6",
|
|
48
|
+
"@yamada-ui/use-controllable-state": "0.3.2"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"react": "^18.0.0",
|