Input Mask 1

PreviousNext

An input field with custom alphanumeric mask pattern for structured data entry

Docs
shadcn-studiocomponent

Preview

Loading preview…
registry/new-york/components/input-mask/input-mask-01.tsx
'use client'

import { useId } from 'react'

import { withMask } from 'use-mask-input'

import { Input } from '@/registry/new-york/ui/input'
import { Label } from '@/registry/new-york/ui/label'

const InputWithMaskDemo = () => {
  const id = useId()

  return (
    <div className='w-full max-w-xs space-y-2'>
      <Label htmlFor={id}>Input with mask</Label>
      <Input
        id={id}
        type='text'
        placeholder='AB12 CDE'
        ref={withMask('AA99 AAA', {
          placeholder: '_',
          showMaskOnHover: false
        })}
      />
      <p className='text-muted-foreground text-xs'>
        Built with{' '}
        <a
          className='hover:text-foreground underline'
          href='https://github.com/eduardoborges/use-mask-input'
          target='_blank'
          rel='noopener noreferrer'
        >
          use-mask-input
        </a>
      </p>
    </div>
  )
}

export default InputWithMaskDemo

Installation

npx shadcn@latest add @shadcn-studio/input-mask-01

Usage

import { InputMask01 } from "@/components/input-mask-01"
<InputMask01 />