Tag Input
NewInstallation
npx shadcn@latest add https://uibrik.com/r/tag-input.jsonInstall the packages
npm install motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/tag-input/tag-input.tsx"use client"; import { useId, useLayoutEffect, useRef, useState, type ClipboardEvent, type KeyboardEvent } from "react"; import { AnimatePresence, LayoutGroup, MotionConfig, motion } from "motion/react"; import { cn } from "@/lib/utils"; // Tag input. What you type is drawn by a mirror under a transparent field, so // when Enter or a comma finishes a tag, the typed word itself flies into the // new chip (a shared layout animation from the mirror to the chip's label) // while the chip's fill grows in around it. The field glides along to its new // place, chips after a removed one close the gap, and the box eases to its // new height when a row wraps, so nothing ever jumps. Pasting a list ("a, b, // c" or one per line) adds them all at once. // // Backspace in an empty field first selects the last chip, a second press // removes it; arrows walk the selection along the chips. A duplicate isn't // added twice: the chip that already has it gives a small nudge instead. export type TagInputProps = { /** Tags (controlled). Pair with `onChange`. */ value?: readonly string[]; /** Tags on mount (uncontrolled). */ defaultValue?: readonly string[]; onChange?: (tags: string[]) => void;
Adds the files to
components/uibrik/tag-input and installs motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/tag-input.Props
TagInput- placeholder
- Type string
- "Add a tag"
- Shown while there are no tags.
- max
- Type number
- 8
- Most tags allowed.
- duration
- Type number
- 0.35
- How long chips and the field take to move.
- ignoreCase
- Type boolean
- true
- Treat Design and design as the same tag.
- disabled
- Type boolean
- false
- Grey the field out and ignore input.
- value / onChange
- Type string[] / (tags) => void
- –
- Controlled tags.
- defaultValue
- Type string[]
- –
- Tags on mount when uncontrolled.
- delimiters
- Type string[]
- [","]
- Keys besides Enter that finish a tag. Pasted text splits on these and on new lines.
- transform
- Type (text) => string | null
- –
- Turns typed text into a tag, or rejects it with null. Defaults to trimming.
- label
- Type string
- "Tags"
- Names the field for screen readers.
- className
- Type string
- –
- Classes for the box.