@diceui/tags-input 1.0.0 → 1.0.1

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 (2) hide show
  1. package/dist/index.mjs +22 -20
  2. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -319,16 +319,17 @@ const INPUT_NAME = "TagsInputInput";
319
319
  const TagsInputInput = React.forwardRef((props, ref) => {
320
320
  const { autoFocus, ...inputProps } = props;
321
321
  const context = useTagsInput(INPUT_NAME);
322
+ const { onItemAdd, setHighlightedIndex } = context;
322
323
  const onCustomKeydown = React.useCallback((event) => {
323
324
  if (event.defaultPrevented) return;
324
325
  const value = event.currentTarget.value;
325
326
  if (!value) return;
326
- if (context.onItemAdd(value)) {
327
+ if (onItemAdd(value)) {
327
328
  event.currentTarget.value = "";
328
- context.setHighlightedIndex(null);
329
+ setHighlightedIndex(null);
329
330
  }
330
331
  event.preventDefault();
331
- }, [context.onItemAdd, context.setHighlightedIndex]);
332
+ }, [onItemAdd, setHighlightedIndex]);
332
333
  const onTab = React.useCallback((event) => {
333
334
  if (!context.addOnTab) return;
334
335
  onCustomKeydown(event);
@@ -405,6 +406,7 @@ const TagsInputItem = React.forwardRef((props, ref) => {
405
406
  const { value, disabled, ...itemProps } = props;
406
407
  const pointerTypeRef = React.useRef("touch");
407
408
  const context = useTagsInput(ITEM_NAME);
409
+ const { inputRef, setHighlightedIndex } = context;
408
410
  const id = useId();
409
411
  const textId = `${id}text`;
410
412
  const index = context.value.indexOf(value);
@@ -413,11 +415,11 @@ const TagsInputItem = React.forwardRef((props, ref) => {
413
415
  const itemDisabled = disabled || context.disabled;
414
416
  const displayValue = context.displayValue(value);
415
417
  const onItemSelect = React.useCallback(() => {
416
- context.setHighlightedIndex(index);
417
- context.inputRef.current?.focus();
418
+ setHighlightedIndex(index);
419
+ inputRef.current?.focus();
418
420
  }, [
419
- context.setHighlightedIndex,
420
- context.inputRef,
421
+ setHighlightedIndex,
422
+ inputRef,
421
423
  index
422
424
  ]);
423
425
  return /* @__PURE__ */ jsx(TagsInputItemProvider, {
@@ -510,13 +512,13 @@ const TagsInputItemText = React.forwardRef((props, ref) => {
510
512
  });
511
513
  const ItemText = TagsInputItemText;
512
514
  function TagsInputEditableItemText() {
513
- const context = useTagsInput(ITEM_TEXT_NAME);
515
+ const { inputRef, onItemUpdate, setEditingIndex, setHighlightedIndex, value } = useTagsInput(ITEM_TEXT_NAME);
514
516
  const itemContext = useTagsInputItem(ITEM_TEXT_NAME);
515
517
  const [editValue, setEditValue] = React.useState(itemContext.displayValue);
516
518
  const onBlur = React.useCallback(() => {
517
519
  setEditValue(itemContext.displayValue);
518
- context.setEditingIndex(null);
519
- }, [context.setEditingIndex, itemContext.displayValue]);
520
+ setEditingIndex(null);
521
+ }, [setEditingIndex, itemContext.displayValue]);
520
522
  const onChange = React.useCallback((event) => {
521
523
  const target = event.target;
522
524
  target.style.width = "0";
@@ -530,24 +532,24 @@ function TagsInputEditableItemText() {
530
532
  }, []);
531
533
  const onKeyDown = React.useCallback((event) => {
532
534
  if (event.key === "Enter") {
533
- const index = context.value.indexOf(itemContext.value);
534
- context.onItemUpdate(index, editValue);
535
+ const index = value.indexOf(itemContext.value);
536
+ onItemUpdate(index, editValue);
535
537
  } else if (event.key === "Escape") {
536
538
  setEditValue(itemContext.displayValue);
537
- context.setEditingIndex(null);
538
- context.setHighlightedIndex(itemContext.index);
539
- context.inputRef.current?.focus();
539
+ setEditingIndex(null);
540
+ setHighlightedIndex(itemContext.index);
541
+ inputRef.current?.focus();
540
542
  }
541
543
  event.stopPropagation();
542
544
  }, [
543
- context.value,
544
- context.onItemUpdate,
545
- context.setEditingIndex,
545
+ value,
546
+ onItemUpdate,
547
+ setEditingIndex,
546
548
  itemContext.displayValue,
547
- context.inputRef.current?.focus,
549
+ inputRef,
548
550
  editValue,
549
551
  itemContext.value,
550
- context.setHighlightedIndex,
552
+ setHighlightedIndex,
551
553
  itemContext.index
552
554
  ]);
553
555
  return /* @__PURE__ */ jsx(Primitive.input, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diceui/tags-input",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -46,7 +46,7 @@
46
46
  }
47
47
  },
48
48
  "devDependencies": {
49
- "tsdown": "^0.22.14",
49
+ "tsdown": "^0.23.1",
50
50
  "typescript": "^7.0.2"
51
51
  },
52
52
  "dependencies": {
@@ -56,6 +56,6 @@
56
56
  "dev": "tsdown --watch",
57
57
  "build": "tsdown",
58
58
  "typecheck": "tsc --noEmit",
59
- "test": "vitest run"
59
+ "test": "vitest run --config ../../vitest.config.ts"
60
60
  }
61
61
  }