Updated
Reject Drop Input
Customize
Digits
Max length0
Color
Gravity1.0
Medium
Radius12px
Installation
npx shadcn@latest add https://uibrik.com/r/reject-drop-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/reject-drop-input/reject-drop-input.tsx"use client"; import { AnimatePresence, motion, useReducedMotion } from "motion/react"; import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState, type ChangeEvent, type CSSProperties, } from "react"; import { cn } from "@/lib/utils"; const EASE_OUT: [number, number, number, number] = [0.23, 1, 0.32, 1]; const SIZES = { sm: { height: 36, padX: 12, font: 14 }, md: { height: 44, padX: 14, font: 15 }, lg: { height: 52, padX: 16, font: 16 }, } as const; type Allow = (char: string, soFar: string) => boolean;
Adds the files to
components/uibrik/reject-drop-input and installs motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/reject-drop-input.Usage
import { RejectDropInput } from "@/components/uibrik/reject-drop-input/reject-drop-input";<RejectDropInput accept="digits" maxLength={0} color="#ef4444" gravity={1} shake={false} size="md" radius={12} defaultValue="" onChange={(value) => {}} onReject={(rejected) => {}} // allow={(char, soFar) => {}} // value="…" // placeholder="…" // label="…" // hint="…"/>Where to use Reject Drop Input
Phone and card numbers
Letters typed into a number field visibly fall out, so the user sees why nothing appeared.
Pairs with Phone Input and Card Input
Amounts
The amount preset keeps one decimal point and two decimals, and drops the rest.
Pairs with Amount Pad
Codes and handles
Usernames, promo codes and IDs reject spaces and symbols without a silent swallow.
Props
RejectDropInput- accept
- Type "digits" | "letters" | "alphanumeric" | "amount"
- "digits"
- Which characters the field keeps.
- maxLength
- Type number
- 0
- Characters past this count are rejected too. 0 for no limit.
- color
- Type string
- "#ef4444"
- Colour of rejected characters and the hint.
- gravity
- Type number
- 1
- How hard rejected characters fall.
- shake
- Type boolean
- false
- Nudge the field sideways on a rejection.
- size
- Type "sm" | "md" | "lg"
- "md"
- Height, padding and text size.
- radius
- Type number
- 12
- Corner radius.
- allow
- Type (char: string, soFar: string) => boolean
- –
- Custom rule; return true to keep the character. Overrides accept.
- value
- Type string
- –
- Controlled value.
- defaultValue
- Type string
- ""
- Starting value when uncontrolled.
- onChange
- Type (value: string) => void
- –
- Called with the cleaned value.
- onReject
- Type (rejected: string) => void
- –
- Called with the characters that were thrown out.
- placeholder
- Type string
- –
- Placeholder text.
- label
- Type string
- "Number"
- Accessible name for the field.
- hint
- Type string
- –
- Shown under the field after a rejection. Defaults to the preset's hint.
- className
- Type string
- –
- Classes for the wrapper.