Skip to content

Commit 58b70da

Browse files
waleedlatif1emir-karabeg
authored andcommitted
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 d18c95d commit 58b70da

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
@@ -658,6 +658,7 @@ export function InviteModal({ open, onOpenChange, workspaceName }: InviteModalPr
658658
items={emailItems}
659659
onAdd={(value) => addEmail(value)}
660660
onRemove={removeEmailItem}
661+
onInputChange={() => setErrorMessage(null)}
661662
placeholder={
662663
!userPerms.canAdmin
663664
? '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
@@ -169,6 +169,8 @@ export interface TagInputProps extends VariantProps<typeof tagInputVariants> {
169169
onAdd: (value: string) => boolean
170170
/** Callback when a tag is removed (receives value, index, and isValid) */
171171
onRemove: (value: string, index: number, isValid: boolean) => void
172+
/** Callback when the input value changes (useful for clearing errors) */
173+
onInputChange?: (value: string) => void
172174
/** Placeholder text for the input */
173175
placeholder?: string
174176
/** Placeholder text when there are existing tags */
@@ -210,6 +212,7 @@ const TagInput = React.forwardRef<HTMLInputElement, TagInputProps>(
210212
items,
211213
onAdd,
212214
onRemove,
215+
onInputChange,
213216
placeholder = 'Enter values',
214217
placeholderWithTags = 'Add another',
215218
disabled = false,
@@ -347,10 +350,12 @@ const TagInput = React.forwardRef<HTMLInputElement, TagInputProps>(
347350
})
348351

349352
if (addedCount === 0 && pastedValues.length === 1) {
350-
setInputValue(inputValue + pastedValues[0])
353+
const newValue = inputValue + pastedValues[0]
354+
setInputValue(newValue)
355+
onInputChange?.(newValue)
351356
}
352357
},
353-
[onAdd, inputValue]
358+
[onAdd, inputValue, onInputChange]
354359
)
355360

356361
const handleBlur = React.useCallback(() => {
@@ -425,7 +430,10 @@ const TagInput = React.forwardRef<HTMLInputElement, TagInputProps>(
425430
name={name}
426431
type='text'
427432
value={inputValue}
428-
onChange={(e) => setInputValue(e.target.value)}
433+
onChange={(e) => {
434+
setInputValue(e.target.value)
435+
onInputChange?.(e.target.value)
436+
}}
429437
onKeyDown={handleKeyDown}
430438
onPaste={handlePaste}
431439
onBlur={handleBlur}

0 commit comments

Comments
 (0)