Input
Stablev1.0.0사용자 텍스트 입력 필드.
import { Input } from "@/components/ui/input";
<Input type="email" placeholder="Email" />Installation
pnpm dlx shadcn@latest add https://groudit.com/r/input.jsonExamples
With Label
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
<div className="space-y-2">
<Label htmlFor="email">Email</Label>
<Input id="email" type="email" placeholder="you@example.com" />
</div>Required
필수 입력은 라벨 옆에 별표(*)로 시각적으로 표시하고, required 속성으로 의미를 명확히 한다.
<div className="space-y-2">
<Label htmlFor="email">
이메일 <span className="text-destructive">*</span>
</Label>
<Input id="email" type="email" required />
</div>Helper text
보조 설명은 aria-describedby 로 연결하면 스크린리더가 함께 읽어준다.
다른 사용자가 회원님을 찾는 데 사용됩니다.
<div className="space-y-2">
<Label htmlFor="username">사용자명</Label>
<Input
id="username"
placeholder="영문 4–20자"
aria-describedby="username-help"
/>
<p id="username-help" className="text-xs text-muted-foreground">
다른 사용자가 회원님을 찾는 데 사용됩니다.
</p>
</div>Invalid (error)
aria-invalid="true" 를 주면 빨간 테두리 + 에러 ring 이 표시된다. 에러 메시지는 aria-describedby 로 연결한다.
올바른 이메일 형식이 아닙니다.
<div className="space-y-2">
<Label htmlFor="email">Email</Label>
<Input
id="email"
type="email"
defaultValue="not-an-email"
aria-invalid="true"
aria-describedby="email-error"
/>
<p id="email-error" className="text-xs text-destructive">
올바른 이메일 형식이 아닙니다.
</p>
</div>Controlled with live validation
입력 길이에 따라 invalid 상태가 즉시 토글된다.
현재 0자
const [value, setValue] = React.useState("");
const invalid = value.length > 0 && value.length < 4;
<Input
value={value}
onChange={(e) => setValue(e.target.value)}
aria-invalid={invalid || undefined}
aria-describedby="msg"
/>
<p id="msg" className={invalid ? "text-destructive" : "text-muted-foreground"}>
{invalid ? "4자 이상 입력해 주세요." : `현재 ${value.length}자`}
</p>Read-only
<Input defaultValue="읽기 전용 값" readOnly />Disabled
<Input placeholder="Disabled" disabled />Sizes
Input 은 단일 기본 사이즈만 제공하고, 더 크거나 작게 쓰려면 className 으로 높이/폰트 크기를 덮어쓴다.
<Input placeholder="Small" className="h-7 text-sm" />
<Input placeholder="Default" />
<Input placeholder="Medium" className="h-10" />
<Input placeholder="Large" className="h-12 text-base" />Types
표준 HTML input[type] 을 그대로 지원한다.
<Input type="text" />
<Input type="email" />
<Input type="password" />
<Input type="number" />
<Input type="tel" />
<Input type="url" />
<Input type="search" />
<Input type="date" />
<Input type="time" />
<Input type="file" />Composition
InputAccessibility
이 컴포넌트는 WAI-ARIA textbox 패턴을 따릅니다.
Keyboard interactions
| Key | Description |
|---|---|
Tab | 다음 필드로 이동. |
Shift + Tab | 이전 필드로 이동. |
Notes
- •반드시 <Label> 과 연결 (htmlFor).