diff --git a/packages/emblor/src/tag/tag-input.tsx b/packages/emblor/src/tag/tag-input.tsx index 6ac3230..6b5ed2f 100644 --- a/packages/emblor/src/tag/tag-input.tsx +++ b/packages/emblor/src/tag/tag-input.tsx @@ -1,6 +1,6 @@ 'use client'; -import React, { useMemo } from 'react'; +import React, { useEffect, useMemo } from 'react'; import { Input } from '../ui/input'; import { Button } from '../ui/button'; import { type VariantProps } from 'class-variance-authority'; @@ -158,6 +158,14 @@ const TagInput = React.forwardRef((props, ref) return null; } + useEffect(() => { + if (inputValue === "") { + setActiveTagIndex(tags.length - 1); + } else { + setActiveTagIndex(null); + } + }, [inputValue]); + const handleInputChange = (e: React.ChangeEvent) => { const newValue = e.target.value; if (addOnPaste && newValue.includes(delimiter)) {