Skip to main content

Code Input

The CodeInput accepts numeric input, restricted to a certain number of digits. It's used for two-factor authentication.

Examples

Basic Code Input

Four (keyboard accessible!) boxes for entering a numeric code.

import { CodeInput } from '@curology/ui-components-web/react/CodeInput';

<CodeInput />

With Label, Helper Text, and Required

Like other inputs, CodeInput can have a label, helper text, and indicate if it's required.

You'll receive an SMS to your phone.
import { CodeInput } from '@curology/ui-components-web/react/CodeInput';

<CodeInput
...
label="Verification Code"
helperText="You'll receive an SMS to your phone."
required
/>

With Custom Length

Although it defaults to four boxes, the CodeInput can accept any number of digits.

import { CodeInput } from '@curology/ui-components-web/react/CodeInput';

<CodeInput digits="6" />

Controlled Code Input

Like all form inputs, a CodeInput can either be uncontrolled, or controlled (by providing a value and onChange listener).

import { CodeInput } from '@curology/ui-components-web/react/CodeInput';

<CodeInput
value={someValue}
onChange={(evt, value) => ...}
/>

Props

CodeInputProps

NameTypeDefault ValueRequiredDescription
All attributes of a <input />
digitsstring | number4NoHow many digits should the input support?
fieldClassNamestringNoA className to apply to the field.
fieldPropsRecord<string, unknown>NoAny props to spread onto the field container.
helperTextReactNodeNoA string or component to display as helper text beneath the input
highlightReactNodeNoHighlighted helper text to display at the bottom of the multiline text input
highlightClassNamestringNoA className to apply to the highlight.
labelReactNodeNoA string or component to display as a label above the input
onChangeFormControlChangeEventHandler<HTMLInputElement, string>NoEmit a new value when the input's selected value changes.
requiredfalse | truefalseNoIs the field required?
size"md" | "sm"'md'NoThe size of the field
state"" | "critical" | "warning" | "success"''NoThe state of the field