Mask

import Mask from 'frui/fields/Mask';
Copy

Props

Masks accepts all props of a standard HTML Input element. See Moz for standard input attributes.

NameTypeRequiredNotes
classNamestringNoStandard HTML class names
defaultValuestring|numberNoDefault value (Uncontrolled)
errorstring|booleanNoAny error message
maskstringYesMask format to validate input
namestringNoUsed for react server components.
onChangeFunctionNoEvent handler when value has changed
onUpdateFunctionNoUpdate event handler
passRefLegacyRefNoPasses ref to html input
styleCSS ObjectNoStandard CSS object
valuestring|numberNoDefault value (Controlled)

Basic

Masks are a wrapper for inputmask. This mask field extends Input with an additional mask prop.

<Mask mask="999-999-9999" placeholder="999-999-9999" />
Copy

Masks uses a combination of the following masking definitions to allow which characters to be entered and in which order.

  • 9 : numeric
  • a : alphabetical
  • * : alphanumeric

It is possible to define some parts in the mask as optional. This is done by using [ ].

<Mask mask="(99) 9999[9]-9999" placeholder="(99) 9999[9]-9999" />
Copy

Events

onUpdate is like onChange except the value is passed instead of the change event.

<Mask mask="999-999-9999" onUpdate={value => alert(value)} />
Copy

On Change

The onChange event is triggered when the value has changed. The following arguments are passed to the event handler:

NameTypeSample
eventEvent Objectsee: Change Event

On Update

The onUpdate event is triggered when the value has been updated. The following arguments are passed to the event handler:

NameTypeSample
valuestring`foobar`

Errors

You can pass the error prop to highlight the input field red.

<Mask error mask="999-999-9999" placeholder="999-999-9999" />
Copy