@yamada-ui/autocomplete 1.6.9-dev-20241213204523 → 1.6.9-dev-20241213210300

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.
Files changed (41) hide show
  1. package/dist/autocomplete-create.js.map +1 -1
  2. package/dist/autocomplete-create.mjs +2 -2
  3. package/dist/autocomplete-empty.js.map +1 -1
  4. package/dist/autocomplete-empty.mjs +2 -2
  5. package/dist/autocomplete-option.js +44 -43
  6. package/dist/autocomplete-option.js.map +1 -1
  7. package/dist/autocomplete-option.mjs +2 -2
  8. package/dist/autocomplete.js +44 -43
  9. package/dist/autocomplete.js.map +1 -1
  10. package/dist/autocomplete.mjs +6 -6
  11. package/dist/{chunk-PWV7X7G6.mjs → chunk-3FXEJSLI.mjs} +4 -4
  12. package/dist/chunk-3FXEJSLI.mjs.map +1 -0
  13. package/dist/{chunk-IFH3PPSD.mjs → chunk-3KSLP2QT.mjs} +4 -4
  14. package/dist/{chunk-YPKDYYEV.mjs → chunk-KG6IO6XB.mjs} +2 -2
  15. package/dist/{chunk-RK5E5J5E.mjs → chunk-M5EWJFSX.mjs} +2 -2
  16. package/dist/{chunk-2LP57WVB.mjs → chunk-NPRQXPV7.mjs} +44 -43
  17. package/dist/chunk-NPRQXPV7.mjs.map +1 -0
  18. package/dist/{chunk-ZR77IT3O.mjs → chunk-Y5WDMYXH.mjs} +2 -2
  19. package/dist/{chunk-2CVB4NO5.mjs → chunk-Y7WZLESA.mjs} +4 -4
  20. package/dist/index.js +44 -43
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +7 -7
  23. package/dist/multi-autocomplete.js +44 -43
  24. package/dist/multi-autocomplete.js.map +1 -1
  25. package/dist/multi-autocomplete.mjs +6 -6
  26. package/dist/use-autocomplete-option.d.mts +3 -3
  27. package/dist/use-autocomplete-option.d.ts +3 -3
  28. package/dist/use-autocomplete-option.js +42 -41
  29. package/dist/use-autocomplete-option.js.map +1 -1
  30. package/dist/use-autocomplete-option.mjs +1 -1
  31. package/dist/use-autocomplete.js +44 -43
  32. package/dist/use-autocomplete.js.map +1 -1
  33. package/dist/use-autocomplete.mjs +3 -3
  34. package/package.json +13 -13
  35. package/dist/chunk-2LP57WVB.mjs.map +0 -1
  36. package/dist/chunk-PWV7X7G6.mjs.map +0 -1
  37. /package/dist/{chunk-IFH3PPSD.mjs.map → chunk-3KSLP2QT.mjs.map} +0 -0
  38. /package/dist/{chunk-YPKDYYEV.mjs.map → chunk-KG6IO6XB.mjs.map} +0 -0
  39. /package/dist/{chunk-RK5E5J5E.mjs.map → chunk-M5EWJFSX.mjs.map} +0 -0
  40. /package/dist/{chunk-ZR77IT3O.mjs.map → chunk-Y5WDMYXH.mjs.map} +0 -0
  41. /package/dist/{chunk-2CVB4NO5.mjs.map → chunk-Y7WZLESA.mjs.map} +0 -0
@@ -159,7 +159,7 @@ var useAutocompleteOption = (props) => {
159
159
  inputRef,
160
160
  omitSelectedValues,
161
161
  setFocusedIndex,
162
- value,
162
+ value: selectedValue,
163
163
  optionProps,
164
164
  onChange,
165
165
  onClose,
@@ -167,43 +167,44 @@ var useAutocompleteOption = (props) => {
167
167
  } = useAutocompleteContext();
168
168
  const uuid = (0, import_react2.useId)();
169
169
  const itemRef = (0, import_react2.useRef)(null);
170
- let {
171
- id,
170
+ const {
171
+ id = uuid,
172
172
  children,
173
173
  closeOnSelect: customCloseOnSelect,
174
- disabled,
175
- focusable,
176
- icon: customIcon,
177
174
  isDisabled,
175
+ disabled = isDisabled,
178
176
  isFocusable,
177
+ focusable = isFocusable,
178
+ icon: customIcon,
179
179
  value: optionValue,
180
180
  ...computedProps
181
181
  } = { ...optionProps, ...props };
182
- disabled != null ? disabled : disabled = isDisabled;
183
- focusable != null ? focusable : focusable = isFocusable;
184
182
  const trulyDisabled = !!disabled && !focusable;
185
183
  const { descendants, index, register } = useAutocompleteDescendant({
186
184
  disabled: trulyDisabled
187
185
  });
188
186
  const values = descendants.values();
189
187
  const frontValues = values.slice(0, index);
190
- const isMulti = (0, import_utils3.isArray)(value);
191
- const isDuplicated = frontValues.some(
192
- ({ node }) => node.dataset.value === (optionValue != null ? optionValue : "")
193
- );
194
- const isSelected = !isDuplicated && (!isMulti ? (optionValue != null ? optionValue : "") === value : value.includes(optionValue != null ? optionValue : ""));
195
- const isTarget = "target" in ((_b = (_a = itemRef.current) == null ? void 0 : _a.dataset) != null ? _b : {});
196
- const isFocused = index === focusedIndex;
197
- id != null ? id : id = uuid;
198
- if ((0, import_utils3.isUndefined)(optionValue)) {
199
- if ((0, import_utils3.isString)(children) || (0, import_utils3.isNumber)(children)) {
200
- optionValue = children.toString();
201
- } else {
202
- console.warn(
203
- `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: Cannot infer the option value of complex children. Pass a \`value\` prop or use a plain string as children to <Option>.`
204
- );
188
+ const multi = (0, import_utils3.isArray)(selectedValue);
189
+ const target = "target" in ((_b = (_a = itemRef.current) == null ? void 0 : _a.dataset) != null ? _b : {});
190
+ const focused = index === focusedIndex;
191
+ const value = (0, import_react2.useMemo)(() => {
192
+ let value2 = optionValue;
193
+ if ((0, import_utils3.isUndefined)(optionValue)) {
194
+ if ((0, import_utils3.isString)(children) || (0, import_utils3.isNumber)(children)) {
195
+ value2 = children.toString();
196
+ } else {
197
+ console.warn(
198
+ `${!multi ? "Autocomplete" : "MultiAutocomplete"}: Cannot infer the option value of complex children. Pass a \`value\` prop or use a plain string as children to <Option>.`
199
+ );
200
+ }
205
201
  }
206
- }
202
+ return value2 != null ? value2 : "";
203
+ }, [children, multi, optionValue]);
204
+ const duplicated = frontValues.some(
205
+ ({ node }) => node.dataset.value === value
206
+ );
207
+ const selected = !duplicated && (!multi ? value === selectedValue : selectedValue.includes(value));
207
208
  const onClick = (0, import_react2.useCallback)(
208
209
  (ev) => {
209
210
  ev.stopPropagation();
@@ -211,18 +212,18 @@ var useAutocompleteOption = (props) => {
211
212
  if (inputRef.current) inputRef.current.focus();
212
213
  return;
213
214
  }
214
- if (!isDuplicated) setFocusedIndex(index);
215
- onChange(optionValue != null ? optionValue : "");
215
+ if (!duplicated) setFocusedIndex(index);
216
+ onChange(value);
216
217
  if (inputRef.current) inputRef.current.focus();
217
218
  if (customCloseOnSelect != null ? customCloseOnSelect : closeOnSelect) onClose();
218
219
  if (omitSelectedValues) onFocusNext(index);
219
220
  },
220
221
  [
221
- isDuplicated,
222
+ duplicated,
222
223
  onFocusNext,
223
224
  omitSelectedValues,
224
225
  disabled,
225
- optionValue,
226
+ value,
226
227
  setFocusedIndex,
227
228
  index,
228
229
  onChange,
@@ -234,7 +235,7 @@ var useAutocompleteOption = (props) => {
234
235
  );
235
236
  const getOptionProps = (0, import_react2.useCallback)(
236
237
  (props2 = {}, ref = null) => {
237
- const isHidden = !isTarget || omitSelectedValues && isSelected;
238
+ const isHidden = !target || omitSelectedValues && selected;
238
239
  const style = {
239
240
  border: "0px",
240
241
  clip: "rect(0px, 0px, 0px, 0px)",
@@ -255,37 +256,37 @@ var useAutocompleteOption = (props) => {
255
256
  style: isHidden ? style : void 0,
256
257
  "aria-disabled": (0, import_utils3.ariaAttr)(disabled),
257
258
  "aria-hidden": (0, import_utils3.ariaAttr)(isHidden),
258
- "aria-selected": isSelected,
259
+ "aria-selected": selected,
259
260
  "data-disabled": (0, import_utils3.dataAttr)(disabled),
260
- "data-duplicated": (0, import_utils3.dataAttr)(isDuplicated),
261
- "data-focus": (0, import_utils3.dataAttr)(isFocused),
261
+ "data-duplicated": (0, import_utils3.dataAttr)(duplicated),
262
+ "data-focus": (0, import_utils3.dataAttr)(focused),
262
263
  "data-target": (0, import_utils3.dataAttr)(true),
263
- "data-value": optionValue != null ? optionValue : "",
264
+ "data-value": value,
264
265
  tabIndex: -1,
265
266
  onClick: (0, import_utils3.handlerAll)(computedProps.onClick, props2.onClick, onClick)
266
267
  };
267
268
  },
268
269
  [
269
270
  id,
270
- isDuplicated,
271
- optionValue,
271
+ duplicated,
272
+ value,
272
273
  computedProps,
273
274
  disabled,
274
- isFocused,
275
- isSelected,
276
- isTarget,
275
+ focused,
276
+ selected,
277
+ target,
277
278
  omitSelectedValues,
278
279
  onClick,
279
280
  register
280
281
  ]
281
282
  );
282
283
  return {
284
+ target,
283
285
  children,
284
286
  customIcon,
285
- isFocused,
286
- isSelected,
287
- isTarget,
287
+ focused,
288
288
  omitSelectedValues,
289
+ selected,
289
290
  getOptionProps
290
291
  };
291
292
  };
@@ -605,7 +606,7 @@ var import_jsx_runtime5 = require("react/jsx-runtime");
605
606
  var AutocompleteOption = (0, import_core5.forwardRef)(
606
607
  ({ className, icon, ...rest }, ref) => {
607
608
  const { styles } = useAutocompleteContext();
608
- const { children, customIcon, isSelected, getOptionProps } = useAutocompleteOption(rest);
609
+ const { children, customIcon, selected, getOptionProps } = useAutocompleteOption(rest);
609
610
  icon != null ? icon : icon = customIcon;
610
611
  const css = {
611
612
  alignItems: "center",
@@ -627,7 +628,7 @@ var AutocompleteOption = (0, import_core5.forwardRef)(
627
628
  __css: css,
628
629
  ...getOptionProps({}, ref),
629
630
  children: [
630
- icon !== null ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AutocompleteItemIcon, { opacity: isSelected ? 1 : 0, children: icon || /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AutocompleteCheckIcon, {}) }) : null,
631
+ icon !== null ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AutocompleteItemIcon, { opacity: selected ? 1 : 0, children: icon || /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AutocompleteCheckIcon, {}) }) : null,
631
632
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_core5.ui.span, { style: { flex: 1 }, "data-label": true, children })
632
633
  ]
633
634
  }