victorjean9 / react-telefone-brasileiro

Máscara simples para input de número de telefone brasileiro com 8 ou 9 dígitos e DDD
MIT License
15 stars 1 forks source link

Material UI 5 + formik #2

Open PHDiniiz opened 2 years ago

PHDiniiz commented 2 years ago

Rola de usar com eles?

viniciusofp commented 1 year ago

Com MUI rola sim. Só seguir a seguinte parte da documentação: https://mui.com/material-ui/react-text-field/#integration-with-3rd-party-input-libraries

Meu código ficou assim:

const TelefoneInputCustom = React.forwardRef<HTMLElement, CustomProps>(
  function TelefoneInputCustom(props, ref) {
    const { onChange, ...other } = props
    return (
      <TelefoneBrasileiroInput
        onChange={onChange}
        inputRef={ref}
        {...other}
        temDDD
        separaDDD
        placeholder="(XX) XXXXX-XXXX"
        overwrite
      />
    )
  }
)
<TextField
  label="Telefone (com DDD)"
  value={formData.phone}
  onChange={e =>
    setFormData({ ...formData, phone: e.target.value })
  }
  InputProps={{
    inputComponent: TelefoneInputCustom as any,
  }}
/>