Skip to main content
Brand and assets
Build
Monitor and contribute
/
Component library
  • All components
  • Buttons & actions
  • Forms & inputs
    • Checkbox
    • ChoiceGroup
    • CurrencyInput
    • DateInput
    • FileInputZone
    • Filters
    • Form
    • MaskedTextInput
    • PasswordInput
    • Pill
    • Pill
    • Radio
    • SearchInput
    • SegmentedSlider
    • Select
    • Switch
    • TextArea
    • TextInput
  • Layout & containers
  • Overlays
  • Feedback & status
  • Data display
  • Typography
  • Accessibility
  • Contrib
  • Deprecated
  • Forms & inputs
  • MaskedTextInput

MaskedTextInput

Formats what the member types against a mask, such as an IBAN. Shows the formatted value, reports the raw one.

Health
Component health
Source
View on Github
Playground
No Example
Accessibility

compliant

Platform
Universal
  • Overview
  • Props

Text input that formats user input according to a mask pattern. The displayed value is formatted (e.g. FR76 3000 6000), while onChange always receives the raw unmasked value (e.g. FR7630006000).

import { MaskedTextInput } from "murray";

Accepts all TextInput props (label, error, placeholder, suffix, etc.) plus mask and a required helpText. Like TextInput, it is controlled through value and onChange, or uncontrolled through defaultValue. Either way the input shows the formatted value and onChange receives the raw one.

Usage​

Help text​

helpText is required: show the expected format with a real example, such as Expected format: FR76 3000 1007 9412 3456 7890 185. A placeholder disappears as soon as the user types and screen readers don't reliably announce it. Help text stays visible while typing and next to an error, and is linked to the input through aria-describedby.

Pass helpText={null} only when the label already states the format.

Uncontrolled​

Pass defaultValue and let the input keep its own state. onChange still receives the raw value as the user types.

Expected format: 732 829 320

Error state​

Invalid IBAN

Expected format: FR76 3000 1007 9412 3456 7890 185

Expected format: 1 85 05 78 006 084 91

Masking​

Common Formats​

Use COMMON_MASKS instead of writing your own pattern.

import { COMMON_MASKS, MaskedTextInput } from "murray";

<MaskedTextInput mask={COMMON_MASKS.IBAN} helpText="Expected format: FR76 3000 1007 9412 3456 7890 185" />;
MaskAcceptsWhile blurred
IBANUp to 34 letters or digits (ISO 13616)Full value
IBAN_OBFUSCATEDSame as IBANFR76 ●●●● ●●●● ●●●● ●●●● ●●●● 189
FR_SSN15 characters, 2A / 2B for CorsicaFull value
FR_SSN_OBFUSCATEDSame as FR_SSN1 ●● ●● ●● ●●● ●●● 78
SIREN9 digitsFull value
SIRET14 digitsFull value
  • Obfuscated masks show the full value on focus. onChange always gets the real value.
  • Set autoComplete="off" on these fields.
  • Another format: write a function mask that reads focused (Dynamic Mask Function).

Outside an input, obfuscate hides a stored value the same way. It keeps the first and last space-separated group.

import { COMMON_MASKS, createMaskArray, obfuscate } from "murray";

const IBAN_MASK = createMaskArray(COMMON_MASKS.IBAN);
const FR_SSN_MASK = createMaskArray(COMMON_MASKS.FR_SSN);

obfuscate("FR7630006000011234567890189", IBAN_MASK); // "FR76 ●●●● ●●●● ●●●● ●●●● ●●●● 189"
obfuscate("185052A12345678", FR_SSN_MASK); // "1 ●● ●● ●● ●●● ●●● 78"

IBAN​

Expected format: FR76 3000 1007 9412 3456 7890 185

Obfuscated while blurred:

Expected format: FR76 3000 1007 9412 3456 7890 185

onChange value: FR7630006000011234567890189

SSN​

Expected format: 1 85 05 78 006 084 91

Obfuscated while blurred:

Expected format: 1 85 05 78 006 084 91

Custom Format String​

mask is a string where each character defines what the user can type at that position:

CharMatchesExample
9Digit [0-9]99 99 → 12 34
ALetter [a-zA-Z]AA → AB
SAlphanumeric [a-zA-Z0-9]SS → A1
*Any non-whitespace character**** → FR76
otherInserted as-is (formatting)9-9 → 1-2

Spaces in the mask are inserted as visual separators: "99 99" formats 1234 as 12 34.

Dynamic Mask Function​

For advanced cases, mask also accepts a function. It receives the current unmasked value and { focused }. createMaskArray, imported from "murray", converts a mask format string into the array format it can return. The function must return either:

  • A mask array — the component applies formatting (use this when the user is typing)
  • A string — used as the display value directly (use this to show a custom representation)

For example, a Spanish DNI (8 digits and a letter) that hides all but the last 4 characters while blurred:

Loading...

Usage in <Form>​

On web, Form.MaskedTextInput stores the raw value, without mask literals, in the Formik values: validate the raw string (length(14) for a SIRET, not length(17)). Errors show once the field is touched.

Expected format: 732 829 320 00074

Accessibility​

MaskedTextInput inherits the accessibility features of TextInput:

  • label is automatically associated with the input via InputWrapper
  • error and helpText are announced to screen readers via aria-describedby / accessibilityHint, error first
  • Supports all standard input accessibility props (accessibilityLabel, accessibilityHint, etc.)

Playground​

Loading...
tip
This component is universal, its usage is the same in murray and murray/mobile.

MaskedTextInput props

NameTypeDefault ValueDescriptionUsage count
aria-describedbystringId of an element outside the input that also describes it, such as an error shared by several inputs
aria-labelstringAccessibility label, only necessary when not associated with a label
aria-labelledbystring
aria-requiredbooleanOverrides `aria-required` set by `required`, to mark the input as mandatory without the asterisk
autoFocusbooleanIf true, focuses the input on componentDidMount.The default value is false.
cursorCursorEnforce a cursor type
defaultValuestringUncontrolled default value.
disabledbooleanDisable input
enterKeyHint"search""done""go""next""send"
errorReactNodeContents of `InputError` component, if not set, error is not rendered.
focusedbooleanShow focus styles even when the input isn't focused, e.g. while a readonly input's picker is open
groupLabelReactNodeName of the group the input belongs to, such as the date its day field is part of. VoiceOver and TalkBack don't announce it when focus lands on the input, so on native it ends the input's accessible name, after `label`. Ignored without a `label`.
helpText*Exclude<ReactNode, undefined>Expected format with a real example ([WCAG 3.3.2](https://www.w3.org/WAI/WCAG22/Understanding/labels-or-instructions.html)). `null` only when the label already states the format.
idstring
labelReactNode
mask*MaskProp
maxstringnumber
maxLengthnumberMaximum string length that the user can enter in UTF-16 code units
minstringnumber
minLengthnumberMaximum string length that the user can enter in UTF-16 code units
namestringHtml input name
onChange((value: string) => void)Trigger when input value is changing
onPress((event: GestureResponderEvent) => void)
placeholderstring
prefixReactNodeContent section rendered on the left side of the input
prefixPointerEvents"none""auto""box-none""box-only"Sets pointer-events styles on the `prefix` element, `none` by default
readonlybooleanMake input readonly
render
1 possibilities((elements: { input: ReactNode; prefix?: ReactNode; suffix?: ReactNode; }, pseudoState: PseudoState) => ReactNode)
Fully control how input, prefix and suffix are rendererd
renderPlaceholder(() => ReactNode)To render a custom placeholder view when the field is empty
requiredbooleanAdds required attribute to the input and a red asterisk on the right side of label, `false` by default Determines whether the input should have `aria-required` attribute
stepstringnumber
suffixReactNodeContent section rendered on the right side of the input
suffixPointerEvents"none""auto""box-none""box-only"Sets pointer-events styles on the `suffix` element, `none` by default
sxPositionPropsPositioning properties
titlestringHtml input title
typeHTMLInputTypeAttributeHTML input type
valuestringControl the input.

Undocumented props

NameTypeDefault ValueDescriptionUsage count
autoCapitalizeany
autoCompleteany
autoCorrectany
clearButtonModeany
inputModeany
onBlurany
onFocusany
onKeyPressany
onSubmitEditingany
refany
returnKeyTypeany

Style API​

Use sx for one-off adjustments. It accepts these style keys:

alignSelfanimationaspectRatiobottomcursordisplayendflexflexBasisflexGrowflexShrinkheightinsetinsetInlineinsetInlineEndinsetInlineStartleftmarginmarginBottommarginHorizontalmarginInlinemarginInlineEndmarginInlineStartmarginLeftmarginRightmarginTopmarginVerticalmatrixmaxHeightmaxWidthminHeightminWidthopacityperspectivepositionrightrotaterotateXrotateYrotateZscalescaleXscaleYskewXskewYstarttoptransformtransformOriginwidthxyzIndex

Each can be overridden per breakpoint with:

$lg$ltLg$ltMd$ltSm$ltVs$ltXl$ltXxl$md$sm$vs$xl$xs$xxl
Edit this page
Previous
Form
Next
PasswordInput
  • Usage
    • Help text
    • Uncontrolled
    • Error state
  • Masking
    • Common Formats
      • IBAN
      • SSN
    • Custom Format String
    • Dynamic Mask Function
  • Usage in <Form>
  • Accessibility
  • Playground