Components
Loading preview...
Upgaraded shadcn/ui Input
npx shadcn@latest add https://21st.dev/r/originui/input"use client";
import { useCharacterLimit } from "@/components/hooks/use-character-limit";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { useId } from "react";
function Component() {
const id = useId();
const maxLength = 8;
const {
value,
characterCount,
handleChange,
maxLength: limit,
} = useCharacterLimit({ maxLength });
return (
<div className="space-y-2 min-w-[300px]">
<Label htmlFor={id}>Input with characters left</Label>
<Input
id={id}
type="text"
value={value}
maxLength={maxLength}
onChange={handleChange}
aria-describedby={`${id}-description`}
/>
<p
id={`${id}-description`}
className="mt-2 text-xs text-muted-foreground"
role="status"
aria-live="polite"
>
<span className="tabular-nums">{limit - characterCount}</span> characters left
</p>
</div>
);
}
export { Component };