An official website of the United States government
Official websites use .gov A .gov website belongs to an official government organization in the United States.
Secure .gov websites use HTTPS A lock or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.
A masked field is an enhanced input field that improves readability by providing visual and non-visual cues to a user about the expected value.
Masked field
<TextField mask={...}>
A Mask component renders a controlled input field that applies formatting to the input value when the field is blurred.
Passing a mask prop into the TextField component with a valid value will
enable formatting to occur when the field is blurred. To "unmask" the
value, you can import and call the unmaskValue method.
$
Code snippet
<divclass="ds-u-clearfix"><labelclass="ds-c-label ds-u-margin-top--0"for="field_1103"id="field_1103-label"><spanclass="">Currency</span></label><divclass="ds-c-field-mask ds-c-field-mask--currency"><divclass="ds-c-field__before ds-c-field__before--currency">$</div><inputtype="text"class="ds-c-field ds-c-field--currency"inputmode="numeric"pattern="[0-9.,-]*"aria-invalid="false"name="currency_example"id="field_1103"value="2,500"aria-label="Enter monthly income amount in dollars."/></div></div><divclass="ds-u-clearfix"><labelclass="ds-c-label"for="field_1104"id="field_1104-label"><spanclass="">Phone number</span></label><divclass="ds-c-field-mask ds-c-field-mask--phone"><inputtype="text"class="ds-c-field ds-c-field--phone"inputmode="numeric"pattern="[0-9-]*"aria-invalid="false"name="phone_example"id="field_1104"value="123-456-7890"/></div></div><divclass="ds-u-clearfix"><labelclass="ds-c-label"for="field_1105"id="field_1105-label"><spanclass="">Social security number (SSN)</span></label><divclass="ds-c-field-mask ds-c-field-mask--ssn"><inputtype="text"class="ds-c-field ds-c-field--ssn"inputmode="numeric"pattern="[0-9-*]*"aria-invalid="false"name="ssn_example"id="field_1105"value="123-45-6789"/></div></div><divclass="ds-u-clearfix"><labelclass="ds-c-label"for="field_1106"id="field_1106-label"><spanclass="">Zip code</span></label><divclass="ds-c-field-mask ds-c-field-mask--zip"><inputtype="text"class="ds-c-field ds-c-field--zip"inputmode="numeric"pattern="[0-9-]*"aria-invalid="false"name="zip_example"id="field_1106"value="12345-6789"/></div></div>
Props
React Properties Documentation
Name
Type
Default
Description
ariaLabel
string
Apply an aria-label to the text field to provide additional
context to assistive devices.
className
string
Additional classes to be added to the root div element
defaultValue
string | number
Sets the initial value. Use this for an uncontrolled component; otherwise,
use the value property.
disabled
boolean
errorMessage
React.ReactNode
errorMessageClassName
string
Additional classes to be added to the error message
errorPlacement
'top' | 'bottom'
Location of the error message relative to the field input
fieldClassName
string
Additional classes to be added to the field element
focusTrigger
boolean
Used to focus input on componentDidMount()
hint
React.ReactNode
Additional hint text to display
id
string
A unique id to be used on the text field.
inputRef
(...args: any[]) => any
Access a reference to the input or textarea element
Applies date format masking to the input value entered
and renders to a text field above the input.
Passing true to valueOnly will return just the
formatted value entered.
labelClassName
string
Additional classes to be added to the FormLabel.
labelId
string
A unique id to be used on the label field.
mask
'currency' | 'phone' | 'ssn' | 'zip'
Apply formatting to the field that's unique to the value
you expect to be entered. Depending on the mask, the
field's appearance and functionality may be affected.
multiline
boolean
Whether or not the text field is a multiline text field
namerequired
string
numeric
boolean
Sets inputMode, type, and pattern to improve accessibility and consistency for number fields. Use this prop instead of type="number", see here for more information.
onBlur
(...args: any[]) => any
onChange
(...args: any[]) => any
rows
number | string
Optionally specify the number of visible text lines for the field. Only
applicable if this is a multiline field.
size
'small' | 'medium'
Set the max-width of the input either to 'small' or 'medium'.
type
string
'text'
HTML inputtype attribute. If you are using type=number please use the numeric prop instead.
value
string | number
Sets the input's value. Use this in combination with onChange
for a controlled component; otherwise, set defaultValue.
Customization
The following Sass variables can be overridden to customize Input/Form components: