@diceui/tags-input 0.4.0 → 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/index.cjs CHANGED
@@ -333,9 +333,9 @@ var TagsInputRoot = React__namespace.forwardRef((props, ref) => {
333
333
  shared.Primitive.div,
334
334
  {
335
335
  id,
336
- "data-disabled": disabled ? "" : void 0,
337
- "data-invalid": isInvalidInput ? "" : void 0,
338
- "data-readonly": readOnly ? "" : void 0,
336
+ "data-disabled": disabled ? "" : undefined,
337
+ "data-invalid": isInvalidInput ? "" : undefined,
338
+ "data-readonly": readOnly ? "" : undefined,
339
339
  dir,
340
340
  ...rootProps,
341
341
  ref: composedRef,
@@ -362,7 +362,7 @@ var TagsInputRoot = React__namespace.forwardRef((props, ref) => {
362
362
  },
363
363
  typeof children === "function" ? /* @__PURE__ */ React__namespace.createElement(React__namespace.Fragment, null, children({ value })) : children,
364
364
  isFormControl && name && /* @__PURE__ */ React__namespace.createElement(
365
- shared.BubbleInput,
365
+ shared.VisuallyHiddenInput,
366
366
  {
367
367
  type: "hidden",
368
368
  control: collectionRef.current,
@@ -427,16 +427,16 @@ var TagsInputItem = React__namespace.forwardRef(
427
427
  /* @__PURE__ */ React__namespace.createElement(
428
428
  shared.Primitive.div,
429
429
  {
430
- ...{ [shared.DATA_ITEM_ATTR]: "" },
430
+ id,
431
431
  "aria-labelledby": textId,
432
432
  "aria-current": isHighlighted,
433
433
  "aria-disabled": itemDisabled,
434
+ ...{ [shared.DATA_ITEM_ATTR]: "" },
434
435
  "data-state": isHighlighted ? "active" : "inactive",
435
- "data-highlighted": isHighlighted ? "" : void 0,
436
- "data-editing": isEditing ? "" : void 0,
437
- "data-editable": context.editable ? "" : void 0,
438
- "data-disabled": itemDisabled ? "" : void 0,
439
- id,
436
+ "data-highlighted": isHighlighted ? "" : undefined,
437
+ "data-editing": isEditing ? "" : undefined,
438
+ "data-editable": context.editable ? "" : undefined,
439
+ "data-disabled": itemDisabled ? "" : undefined,
440
440
  ...itemProps,
441
441
  ref,
442
442
  onClick: shared.composeEventHandlers(itemProps.onClick, (event) => {
@@ -528,7 +528,7 @@ var TagsInputInput = React__namespace.forwardRef(
528
528
  autoFocus,
529
529
  "aria-labelledby": context.labelId,
530
530
  "aria-readonly": context.readOnly,
531
- "data-invalid": context.isInvalidInput ? "" : void 0,
531
+ "data-invalid": context.isInvalidInput ? "" : undefined,
532
532
  dir: context.dir,
533
533
  disabled: context.disabled,
534
534
  readOnly: context.readOnly,
@@ -593,12 +593,12 @@ var TagsInputItemDelete = React__namespace.forwardRef((props, ref) => {
593
593
  shared.Primitive.button,
594
594
  {
595
595
  type: "button",
596
- tabIndex: -1,
596
+ tabIndex: disabled ? undefined : -1,
597
597
  "aria-labelledby": itemContext.textId,
598
598
  "aria-controls": itemContext.id,
599
599
  "aria-current": itemContext.isHighlighted,
600
600
  "data-state": itemContext.isHighlighted ? "active" : "inactive",
601
- "data-disabled": disabled ? "" : void 0,
601
+ "data-disabled": disabled ? "" : undefined,
602
602
  ...props,
603
603
  ref,
604
604
  onClick: shared.composeEventHandlers(props.onClick, () => {
@@ -616,63 +616,86 @@ var TagsInputItemText = React__namespace.forwardRef((props, ref) => {
616
616
  const { children, ...itemTextProps } = props;
617
617
  const context = useTagsInput(ITEM_TEXT_NAME);
618
618
  const itemContext = useTagsInputItem(ITEM_TEXT_NAME);
619
- const [editValue, setEditValue] = React__namespace.useState(itemContext.displayValue);
620
619
  if (itemContext.isEditing && context.editable && !itemContext.disabled) {
621
- return /* @__PURE__ */ React__namespace.createElement(
622
- shared.Primitive.input,
623
- {
624
- type: "text",
625
- autoCapitalize: "off",
626
- autoComplete: "off",
627
- autoCorrect: "off",
628
- spellCheck: "false",
629
- autoFocus: true,
630
- "aria-describedby": itemContext.textId,
631
- value: editValue,
632
- onInput: (event) => {
633
- const target = event.target;
634
- if (!(target instanceof HTMLInputElement)) return;
635
- target.style.width = "0";
636
- target.style.width = `${target.scrollWidth + 4}px`;
637
- },
638
- onChange: (event) => setEditValue(event.target.value),
639
- onKeyDown: (event) => {
640
- if (event.key === "Enter") {
641
- const index = context.value.findIndex(
642
- (v) => v === itemContext.value
643
- );
644
- context.onItemUpdate(index, editValue);
645
- } else if (event.key === "Escape") {
646
- setEditValue(itemContext.displayValue);
647
- context.setEditingIndex(null);
648
- context.inputRef.current?.focus();
649
- }
650
- event.stopPropagation();
651
- },
652
- onFocus: (event) => {
653
- event.target.select();
654
- event.target.style.width = "0";
655
- event.target.style.width = `${event.target.scrollWidth + 4}px`;
656
- },
657
- onBlur: () => {
658
- setEditValue(itemContext.displayValue);
659
- context.setEditingIndex(null);
660
- },
661
- style: {
662
- outline: "none",
663
- background: "inherit",
664
- border: "none",
665
- font: "inherit",
666
- color: "inherit",
667
- padding: 0,
668
- minWidth: "1ch"
669
- }
670
- }
671
- );
620
+ return /* @__PURE__ */ React__namespace.createElement(TagsInputEditableItemText, null);
672
621
  }
673
622
  return /* @__PURE__ */ React__namespace.createElement(shared.Primitive.span, { id: itemContext.textId, ...itemTextProps, ref }, children ?? itemContext.displayValue);
674
623
  });
675
624
  var ItemText = TagsInputItemText;
625
+ function TagsInputEditableItemText() {
626
+ const context = useTagsInput(ITEM_TEXT_NAME);
627
+ const itemContext = useTagsInputItem(ITEM_TEXT_NAME);
628
+ const [editValue, setEditValue] = React__namespace.useState(itemContext.displayValue);
629
+ const onBlur = React__namespace.useCallback(() => {
630
+ setEditValue(itemContext.displayValue);
631
+ context.setEditingIndex(null);
632
+ }, [context.setEditingIndex, itemContext.displayValue]);
633
+ const onChange = React__namespace.useCallback(
634
+ (event) => {
635
+ const target = event.target;
636
+ target.style.width = "0";
637
+ target.style.width = `${target.scrollWidth + 4}px`;
638
+ setEditValue(event.target.value);
639
+ },
640
+ []
641
+ );
642
+ const onFocus = React__namespace.useCallback(
643
+ (event) => {
644
+ event.target.select();
645
+ event.target.style.width = "0";
646
+ event.target.style.width = `${event.target.scrollWidth + 4}px`;
647
+ },
648
+ []
649
+ );
650
+ const onKeyDown = React__namespace.useCallback(
651
+ (event) => {
652
+ if (event.key === "Enter") {
653
+ const index = context.value.findIndex((v) => v === itemContext.value);
654
+ context.onItemUpdate(index, editValue);
655
+ } else if (event.key === "Escape") {
656
+ setEditValue(itemContext.displayValue);
657
+ context.setEditingIndex(null);
658
+ context.inputRef.current?.focus();
659
+ }
660
+ event.stopPropagation();
661
+ },
662
+ [
663
+ context.value,
664
+ context.onItemUpdate,
665
+ context.setEditingIndex,
666
+ itemContext.displayValue,
667
+ context.inputRef.current?.focus,
668
+ editValue,
669
+ itemContext.value
670
+ ]
671
+ );
672
+ return /* @__PURE__ */ React__namespace.createElement(
673
+ shared.Primitive.input,
674
+ {
675
+ type: "text",
676
+ autoCapitalize: "off",
677
+ autoComplete: "off",
678
+ autoCorrect: "off",
679
+ spellCheck: "false",
680
+ autoFocus: true,
681
+ "aria-describedby": itemContext.textId,
682
+ value: editValue,
683
+ onChange,
684
+ onKeyDown,
685
+ onFocus,
686
+ onBlur,
687
+ style: {
688
+ outline: "none",
689
+ background: "inherit",
690
+ border: "none",
691
+ font: "inherit",
692
+ color: "inherit",
693
+ padding: 0,
694
+ minWidth: "1ch"
695
+ }
696
+ }
697
+ );
698
+ }
676
699
  var CLEAR_NAME = "TagsInputClear";
677
700
  var TagsInputClear = React__namespace.forwardRef(
678
701
  (props, ref) => {
@@ -684,7 +707,7 @@ var TagsInputClear = React__namespace.forwardRef(
684
707
  type: "button",
685
708
  "aria-disabled": context.disabled,
686
709
  "data-state": context.value.length > 0 ? "visible" : "invisible",
687
- "data-disabled": context.disabled ? "" : void 0,
710
+ "data-disabled": context.disabled ? "" : undefined,
688
711
  ...clearProps,
689
712
  ref,
690
713
  onClick: shared.composeEventHandlers(props.onClick, () => {
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import * as React from 'react';
4
- import { createContext, useControllableState, useId, useDirection, useItemCollection, useFormControl, useComposedRefs, DATA_ITEM_ATTR, Primitive, composeEventHandlers, BubbleInput, composeRefs, Presence } from '@diceui/shared';
4
+ import { createContext, useControllableState, useId, useDirection, useItemCollection, useFormControl, useComposedRefs, DATA_ITEM_ATTR, Primitive, composeEventHandlers, VisuallyHiddenInput, composeRefs, Presence } from '@diceui/shared';
5
5
 
6
6
  var ROOT_NAME = "TagsInputRoot";
7
7
  var [TagsInputProvider, useTagsInput] = createContext(ROOT_NAME);
@@ -311,9 +311,9 @@ var TagsInputRoot = React.forwardRef((props, ref) => {
311
311
  Primitive.div,
312
312
  {
313
313
  id,
314
- "data-disabled": disabled ? "" : void 0,
315
- "data-invalid": isInvalidInput ? "" : void 0,
316
- "data-readonly": readOnly ? "" : void 0,
314
+ "data-disabled": disabled ? "" : undefined,
315
+ "data-invalid": isInvalidInput ? "" : undefined,
316
+ "data-readonly": readOnly ? "" : undefined,
317
317
  dir,
318
318
  ...rootProps,
319
319
  ref: composedRef,
@@ -340,7 +340,7 @@ var TagsInputRoot = React.forwardRef((props, ref) => {
340
340
  },
341
341
  typeof children === "function" ? /* @__PURE__ */ React.createElement(React.Fragment, null, children({ value })) : children,
342
342
  isFormControl && name && /* @__PURE__ */ React.createElement(
343
- BubbleInput,
343
+ VisuallyHiddenInput,
344
344
  {
345
345
  type: "hidden",
346
346
  control: collectionRef.current,
@@ -405,16 +405,16 @@ var TagsInputItem = React.forwardRef(
405
405
  /* @__PURE__ */ React.createElement(
406
406
  Primitive.div,
407
407
  {
408
- ...{ [DATA_ITEM_ATTR]: "" },
408
+ id,
409
409
  "aria-labelledby": textId,
410
410
  "aria-current": isHighlighted,
411
411
  "aria-disabled": itemDisabled,
412
+ ...{ [DATA_ITEM_ATTR]: "" },
412
413
  "data-state": isHighlighted ? "active" : "inactive",
413
- "data-highlighted": isHighlighted ? "" : void 0,
414
- "data-editing": isEditing ? "" : void 0,
415
- "data-editable": context.editable ? "" : void 0,
416
- "data-disabled": itemDisabled ? "" : void 0,
417
- id,
414
+ "data-highlighted": isHighlighted ? "" : undefined,
415
+ "data-editing": isEditing ? "" : undefined,
416
+ "data-editable": context.editable ? "" : undefined,
417
+ "data-disabled": itemDisabled ? "" : undefined,
418
418
  ...itemProps,
419
419
  ref,
420
420
  onClick: composeEventHandlers(itemProps.onClick, (event) => {
@@ -506,7 +506,7 @@ var TagsInputInput = React.forwardRef(
506
506
  autoFocus,
507
507
  "aria-labelledby": context.labelId,
508
508
  "aria-readonly": context.readOnly,
509
- "data-invalid": context.isInvalidInput ? "" : void 0,
509
+ "data-invalid": context.isInvalidInput ? "" : undefined,
510
510
  dir: context.dir,
511
511
  disabled: context.disabled,
512
512
  readOnly: context.readOnly,
@@ -571,12 +571,12 @@ var TagsInputItemDelete = React.forwardRef((props, ref) => {
571
571
  Primitive.button,
572
572
  {
573
573
  type: "button",
574
- tabIndex: -1,
574
+ tabIndex: disabled ? undefined : -1,
575
575
  "aria-labelledby": itemContext.textId,
576
576
  "aria-controls": itemContext.id,
577
577
  "aria-current": itemContext.isHighlighted,
578
578
  "data-state": itemContext.isHighlighted ? "active" : "inactive",
579
- "data-disabled": disabled ? "" : void 0,
579
+ "data-disabled": disabled ? "" : undefined,
580
580
  ...props,
581
581
  ref,
582
582
  onClick: composeEventHandlers(props.onClick, () => {
@@ -594,63 +594,86 @@ var TagsInputItemText = React.forwardRef((props, ref) => {
594
594
  const { children, ...itemTextProps } = props;
595
595
  const context = useTagsInput(ITEM_TEXT_NAME);
596
596
  const itemContext = useTagsInputItem(ITEM_TEXT_NAME);
597
- const [editValue, setEditValue] = React.useState(itemContext.displayValue);
598
597
  if (itemContext.isEditing && context.editable && !itemContext.disabled) {
599
- return /* @__PURE__ */ React.createElement(
600
- Primitive.input,
601
- {
602
- type: "text",
603
- autoCapitalize: "off",
604
- autoComplete: "off",
605
- autoCorrect: "off",
606
- spellCheck: "false",
607
- autoFocus: true,
608
- "aria-describedby": itemContext.textId,
609
- value: editValue,
610
- onInput: (event) => {
611
- const target = event.target;
612
- if (!(target instanceof HTMLInputElement)) return;
613
- target.style.width = "0";
614
- target.style.width = `${target.scrollWidth + 4}px`;
615
- },
616
- onChange: (event) => setEditValue(event.target.value),
617
- onKeyDown: (event) => {
618
- if (event.key === "Enter") {
619
- const index = context.value.findIndex(
620
- (v) => v === itemContext.value
621
- );
622
- context.onItemUpdate(index, editValue);
623
- } else if (event.key === "Escape") {
624
- setEditValue(itemContext.displayValue);
625
- context.setEditingIndex(null);
626
- context.inputRef.current?.focus();
627
- }
628
- event.stopPropagation();
629
- },
630
- onFocus: (event) => {
631
- event.target.select();
632
- event.target.style.width = "0";
633
- event.target.style.width = `${event.target.scrollWidth + 4}px`;
634
- },
635
- onBlur: () => {
636
- setEditValue(itemContext.displayValue);
637
- context.setEditingIndex(null);
638
- },
639
- style: {
640
- outline: "none",
641
- background: "inherit",
642
- border: "none",
643
- font: "inherit",
644
- color: "inherit",
645
- padding: 0,
646
- minWidth: "1ch"
647
- }
648
- }
649
- );
598
+ return /* @__PURE__ */ React.createElement(TagsInputEditableItemText, null);
650
599
  }
651
600
  return /* @__PURE__ */ React.createElement(Primitive.span, { id: itemContext.textId, ...itemTextProps, ref }, children ?? itemContext.displayValue);
652
601
  });
653
602
  var ItemText = TagsInputItemText;
603
+ function TagsInputEditableItemText() {
604
+ const context = useTagsInput(ITEM_TEXT_NAME);
605
+ const itemContext = useTagsInputItem(ITEM_TEXT_NAME);
606
+ const [editValue, setEditValue] = React.useState(itemContext.displayValue);
607
+ const onBlur = React.useCallback(() => {
608
+ setEditValue(itemContext.displayValue);
609
+ context.setEditingIndex(null);
610
+ }, [context.setEditingIndex, itemContext.displayValue]);
611
+ const onChange = React.useCallback(
612
+ (event) => {
613
+ const target = event.target;
614
+ target.style.width = "0";
615
+ target.style.width = `${target.scrollWidth + 4}px`;
616
+ setEditValue(event.target.value);
617
+ },
618
+ []
619
+ );
620
+ const onFocus = React.useCallback(
621
+ (event) => {
622
+ event.target.select();
623
+ event.target.style.width = "0";
624
+ event.target.style.width = `${event.target.scrollWidth + 4}px`;
625
+ },
626
+ []
627
+ );
628
+ const onKeyDown = React.useCallback(
629
+ (event) => {
630
+ if (event.key === "Enter") {
631
+ const index = context.value.findIndex((v) => v === itemContext.value);
632
+ context.onItemUpdate(index, editValue);
633
+ } else if (event.key === "Escape") {
634
+ setEditValue(itemContext.displayValue);
635
+ context.setEditingIndex(null);
636
+ context.inputRef.current?.focus();
637
+ }
638
+ event.stopPropagation();
639
+ },
640
+ [
641
+ context.value,
642
+ context.onItemUpdate,
643
+ context.setEditingIndex,
644
+ itemContext.displayValue,
645
+ context.inputRef.current?.focus,
646
+ editValue,
647
+ itemContext.value
648
+ ]
649
+ );
650
+ return /* @__PURE__ */ React.createElement(
651
+ Primitive.input,
652
+ {
653
+ type: "text",
654
+ autoCapitalize: "off",
655
+ autoComplete: "off",
656
+ autoCorrect: "off",
657
+ spellCheck: "false",
658
+ autoFocus: true,
659
+ "aria-describedby": itemContext.textId,
660
+ value: editValue,
661
+ onChange,
662
+ onKeyDown,
663
+ onFocus,
664
+ onBlur,
665
+ style: {
666
+ outline: "none",
667
+ background: "inherit",
668
+ border: "none",
669
+ font: "inherit",
670
+ color: "inherit",
671
+ padding: 0,
672
+ minWidth: "1ch"
673
+ }
674
+ }
675
+ );
676
+ }
654
677
  var CLEAR_NAME = "TagsInputClear";
655
678
  var TagsInputClear = React.forwardRef(
656
679
  (props, ref) => {
@@ -662,7 +685,7 @@ var TagsInputClear = React.forwardRef(
662
685
  type: "button",
663
686
  "aria-disabled": context.disabled,
664
687
  "data-state": context.value.length > 0 ? "visible" : "invisible",
665
- "data-disabled": context.disabled ? "" : void 0,
688
+ "data-disabled": context.disabled ? "" : undefined,
666
689
  ...clearProps,
667
690
  ref,
668
691
  onClick: composeEventHandlers(props.onClick, () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diceui/tags-input",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -49,10 +49,10 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "tsup": "^8.3.5",
52
- "typescript": "^5.7.2"
52
+ "typescript": "^5.7.3"
53
53
  },
54
54
  "dependencies": {
55
- "@diceui/shared": "0.7.0"
55
+ "@diceui/shared": "0.9.0"
56
56
  },
57
57
  "scripts": {
58
58
  "dev": "tsup --watch",