Skip to content

Commit ab32a19

Browse files
authored
fix(tag-input): add onInputChange to clear errors when new text is entered (#2765)
* fix(tag-input): add onInputChange to clear errors when new text is entered * added paste case too
1 parent ead2413 commit ab32a19

File tree

2 files changed

+12
-3
lines changed
  • apps/sim
    • app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/components/invite-modal
    • components/emcn/components/tag-input

2 files changed

+12
-3
lines changed

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/components/invite-modal/invite-modal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ export function InviteModal({ open, onOpenChange, workspaceName }: InviteModalPr
657657
items={emailItems}
658658
onAdd={(value) => addEmail(value)}
659659
onRemove={removeEmailItem}
660+
onInputChange={() => setErrorMessage(null)}
660661
placeholder={
661662
!userPerms.canAdmin
662663
? 'Only administrators can invite new members'

apps/sim/components/emcn/components/tag-input/tag-input.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ export interface TagInputProps extends VariantProps<typeof tagInputVariants> {
166166
onAdd: (value: string) => boolean
167167
/** Callback when a tag is removed (receives value, index, and isValid) */
168168
onRemove: (value: string, index: number, isValid: boolean) => void
169+
/** Callback when the input value changes (useful for clearing errors) */
170+
onInputChange?: (value: string) => void
169171
/** Placeholder text for the input */
170172
placeholder?: string
171173
/** Placeholder text when there are existing tags */
@@ -207,6 +209,7 @@ const TagInput = React.forwardRef<HTMLInputElement, TagInputProps>(
207209
items,
208210
onAdd,
209211
onRemove,
212+
onInputChange,
210213
placeholder = 'Enter values',
211214
placeholderWithTags = 'Add another',
212215
disabled = false,
@@ -344,10 +347,12 @@ const TagInput = React.forwardRef<HTMLInputElement, TagInputProps>(
344347
})
345348

346349
if (addedCount === 0 && pastedValues.length === 1) {
347-
setInputValue(inputValue + pastedValues[0])
350+
const newValue = inputValue + pastedValues[0]
351+
setInputValue(newValue)
352+
onInputChange?.(newValue)
348353
}
349354
},
350-
[onAdd, inputValue]
355+
[onAdd, inputValue, onInputChange]
351356
)
352357

353358
const handleBlur = React.useCallback(() => {
@@ -422,7 +427,10 @@ const TagInput = React.forwardRef<HTMLInputElement, TagInputProps>(
422427
name={name}
423428
type='text'
424429
value={inputValue}
425-
onChange={(e) => setInputValue(e.target.value)}
430+
onChange={(e) => {
431+
setInputValue(e.target.value)
432+
onInputChange?.(e.target.value)
433+
}}
426434
onKeyDown={handleKeyDown}
427435
onPaste={handlePaste}
428436
onBlur={handleBlur}

0 commit comments

Comments
 (0)