Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions src/components/text-input.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useRef, useState } from 'react'
import { useCallback, useEffect, useRef, useState, forwardRef } from 'react'

enum TextInputSize {
XS = 'xs',
Expand All @@ -19,31 +19,32 @@ interface TextInputProps {
type?: string
direction?: 'rtl' | 'ltr' | ''
className?: string
ref?: React.RefObject<HTMLInputElement | null>
debounce?: boolean
debounceTime?: number
maxLength?: number
size?: TextInputSize
}

export function TextInput({
onChange,
value,
placeholder,
onFocus,
onKeyDown,
disabled = false,
name,
id,
type = 'text',
direction = '',
className = '',
ref,
debounce = false,
debounceTime = 150,
maxLength = 1000,
size = TextInputSize.MD,
}: TextInputProps) {
export const TextInput = forwardRef<HTMLInputElement, TextInputProps>(function TextInput(
{
onChange,
value,
placeholder,
onFocus,
onKeyDown,
disabled = false,
name,
id,
type = 'text',
direction = '',
className = '',
debounce = false,
debounceTime = 150,
maxLength = 1000,
size = TextInputSize.MD,
},
ref
) {
const sizes: Record<TextInputSize, string> = {
[TextInputSize.XS]: 'input-xs',
[TextInputSize.SM]: 'input-sm',
Expand Down Expand Up @@ -101,4 +102,4 @@ export function TextInput({
autoComplete="off"
/>
)
}
})
Loading