MaskedInput
Input with built-in masks for Brazilian documents and phones. Formats as you type.
Examples
All masks with labels
<MaskedInputlabel="CPF"mask="CPF"value={cpf}onChange={(e) => setCpf(e.target.value)}placeholder="000.000.000-00"/>
Custom mask (any template)
Use `9` as the digit placeholder. Other characters are inserted literally.
import { useState } from 'react';import { MaskedInput } from '@kactostecnologia/benix-ds';export default function CustomMaskForm() {const [card, setCard] = useState('');const [time, setTime] = useState('');return (<><MaskedInputlabel="Credit card"mask="9999 9999 9999 9999"value={card}onChange={(e) => setCard(e.target.value)}placeholder="0000 0000 0000 0000"/><MaskedInputlabel="Time"mask="99h99"value={time}onChange={(e) => setTime(e.target.value)}placeholder="00h00"/></>);}
Error state
Invalid CPF.
import { MaskedInput } from '@kactostecnologia/benix-ds';export default function CpfValidation() {return (<MaskedInputlabel="CPF"mask="CPF"value="123.456.789-01"onChange={() => {}}error="Invalid CPF."/>);}
API Reference
Props of the MaskedInput component.
| Prop | Type | Default | Description |
|---|---|---|---|
mask* | 'CPF' | 'CNPJ' | 'CEP' | 'PHONE' | 'CELL' | — | — |
value* | string | — | — |
onChange* | (e: React.ChangeEvent<HTMLInputElement>) => void | — | — |
label | string | — | Renders an inline label above the input. |
error | string | — | Error message displayed below the input. |