Skip to main content

InputField

Allows users to enter text into a UI.

Submit feedback
github
import { InputField } from '@uhg-abyss/mobile';
    () => {
    const form = useForm();
    return (
    <FormProvider state={form}>
    <InputField
    model="input-field-sandbox"
    label="Sandbox Label"
    hintText="Sandbox Hint Text"
    />
    </FormProvider>
    );
    };

    Note: If the InputField is inside a ScrollView, verify the keyboardShouldPersistTaps prop on the ScrollView is set to "always" or "handled" to allow pressing icons within the InputField when the keyboard is open.

    Using the useForm hook with FormProvider sets state for the component.

    Note: If the InputField is inside a ScrollView, verify the keyboardShouldPersistTaps prop on the ScrollView is set to "always" or "handled" to allow pressing icons within the InputField when the keyboard is open.

    useState

    Using the useState hook gets values from the component state.

    Placeholder

    Use the placeholder prop to give users a short description in the input field before they enter a value.

    Label

    Use the label prop to display a label above the input.

    Error Message

    Use the errorMessage prop to display a custom error message below the input field.

    Success Message

    Use the successMessage prop to display a custom success message below the input field.

    Disabled

    Set the isDisabled prop to true to disable the input field so users cannot enter a value.

    Types

    Use the type prop to set the type of input field to be displayed. Types include: 'text', 'email', 'password', 'price', 'number' and 'phone'. The default is text.

    Text

    Password

    Price

    Prefix

    Use the prefix prop to display content before the input field. This is meant for text and decorative icons. The default prefix for type='price' is '$'.

    Suffix

    Use the suffix prop to display content after the input field.

    Action Icon

    Use the actionIcon prop to pass in an actionable button. This can be used to further customize the input component.

    Validation

    Use the validations prop to set rules for the field to be valid. Each validation must have a key for it's name and an object that describes the validation. The object must have a message to display what should be validated. To create a custom validation, you can add a validate function that takes in the text as an argument and should return a boolean.

    There are 5 built in validations: minLength, maxLength, hasUppercaseLetters, hasLowercaseLetters and hasNumbers. For the minLength and maxLength validations, you can pass in a value to determine the amount of characters to check for.

    • minLength - Returns true if the amount of characters is less than the value. Default: 8
    • maxLength - Returns true if the amount of characters is less than the value. Default: 20
    • hasUppercaseLetters - Returns true if the text contains uppercase letters.
    • hasLowercaseLetters - Returns true if the text contains lowercase letters.
    • hasNumbers - Returns true if the text contains numbers.

    To check the status of the validations, use the second parameter of the onChangeText prop.

    Help Content

    Use the helpContent prop to display a help icon in the top right of the container, which will display the provided content in a modal screen when pressed.

    InputField Props

    Prop NameTypeDefaultDescription
    actionIconnode-Sets the action button to be displayed after the text entry field
    errorMessagestring-Error message to be displayed below input field
    helpButtonAccessibilityLabelstring-Set the accessibility label for the help button
    helpContentstring | ReactNode-When defined, displays a help icon that can be tapped to view the provided content in a modal screen
    hintTextstring-Set the text displayed below label
    isDisabledbooleanfalseFlag to enable/disable the input. If true, the input will be disabled
    isRequiredbooleanfalseFlag to require text
    keyboardTypestring-Determines which keyboard to open
    labelstring-Label for input field
    onActionIconPressfunction-Callback fired when the action button is pressed
    onBlurfunction-Callback fired every time the component is unfocused
    onChangeTextfunction-Callback that is called when the input field text changes. Changed text is passed as a single string argument to the callback handler
    onFocusfunction-Callback fired every time the component is focused
    placeholderstring-Short description displayed in the input before the user enters a value
    prefixstring | node-Sets the content to be displayed before the text entry field
    requirementsTextstring-Set the text displayed above validations
    showOptionalLabelbooleanfalseFlag to display "optional" next to the label
    successMessagestring-Success message to be displayed below input field
    suffixstring | node-Sets the content to be displayed after the text entry field
    textContentTypestring-Give the keyboard and the system information about the expected semantic meaning for the content that users enter
    type'text' | 'email' | 'password' | 'price' | 'phone' | 'number'textSet the type of input field
    validationsobject-Set rules for the input field to be valid
    valuestring-Value of the input field

    InputField Classes

    Class NameDescription
    abyss-input-fieldInput container
    abyss-input-field-cancel-buttonCancel button
    abyss-input-field-cancel-iconCancel icon
    abyss-input-field-containerThe container around the input field
    abyss-input-field-headerHeader element
    abyss-input-field-help-buttonHelp button
    abyss-input-field-help-modalHelp modal
    abyss-input-field-hint-textInput hint text
    abyss-input-field-icon-buttonIcon button
    abyss-input-field-labelLabel element
    abyss-input-field-messageMessage element
    abyss-input-field-prefixPrefix text
    abyss-input-field-rootRoot element
    abyss-input-field-show-password-iconShow password icon
    abyss-input-field-validation-checked-iconValid icon
    abyss-input-field-validation-textValidation text
    abyss-input-field-validation-unchecked-iconInvalid icon
    abyss-input-help-iconHelp icon element
    abyss-input-help-modal-close-buttonHelp modal close button
    abyss-input-help-modal-footerHelp modal footer
    abyss-input-message-iconMessage icon
    abyss-input-message-textMessage text

    InputField Translations

    Translation KeyValue
    helpHelp
    closeClose
    errorError
    successSuccess
    InputField.priceInDollarsIn Dollars.
    InputField.clearTextClear Text
    InputField.hidePasswordHide Password
    InputField.revealPasswordReveal Password
    InputField.passPass:

    Focus Guidance

    Abyss does not control the focus of components on the screen when handling validation errors. The useSetFocus hook can be used for this.

    For input fields, the focus should move back to the input when there is an error (e.g user typed too many characters).

    InputField Tokens

    Token NameValue
    input-header.color.text.label
    #4B4D4F
    input-header.color.text.hint
    #4B4D4F
    input-header.color.icon.help.rest
    #196ECF
    input-header.color.icon.help.active
    #004BA0
    input-message.color.text.error
    #990000
    input-message.color.text.success
    #007000
    input-message.color.icon.error
    #990000
    input-message.color.icon.success
    #007000
    input-field.color.surface.default
    #FFFFFF
    input-field.color.surface.disabled
    #F3F3F3
    input-field.color.text.input
    #4B4D4F
    input-field.color.border.rest.default
    #4B4D4F
    input-field.color.border.rest.error
    #990000
    input-field.color.border.rest.success
    #007000
    input-field.color.border.active.default
    #196ECF
    input-field.color.border.active.error
    #990000
    input-field.color.border.active.success
    #007000
    input-field.color.icon.utility.rest
    #4B4D4F
    input-field.color.icon.utility.disabled
    #929496
    input-field.color.icon.utility.active
    #323334
    input-requirements.color.text.label.header
    #4B4D4F
    input-requirements.color.text.label.default
    #4B4D4F
    input-requirements.color.text.label.success
    #007000
    input-requirements.color.icon.default
    #4B4D4F
    input-requirements.color.icon.success
    #007000
    input-field.border-radius.all.container
    4
    input-field.border-width.all.container.rest
    1
    input-field.border-width.all.container.active
    3
    input-header.sizing.all.icon.help
    24
    input-message.sizing.all.icon.leading
    20
    input-field.sizing.icon.all.utility
    20
    input-field.sizing.icon.all.picker
    20
    input-requirements.sizing.all.icon.leading
    16
    input-container.spacing.gap.vertical.container
    8
    input-header.spacing.gap.horizontal.container
    12
    input-header.spacing.gap.horizontal.label
    4
    input-header.spacing.gap.vertical.content
    4
    input-message.spacing.gap.horizontal.container
    4
    input-field.spacing.padding.all.field
    12
    input-field.spacing.gap.horizontal.field
    12
    input-field.spacing.gap.horizontal.input-indicator
    2
    input-field.spacing.gap.horizontal.prefix-input
    2
    input-requirements.spacing.gap.vertical.container
    8
    input-requirements.spacing.gap.vertical.requirements-list
    8
    input-requirements.spacing.gap.horizontal.requirement
    8
    input-field.box-shadow.container.active
    • Shadow Color: $core.color.brand.60
    • Shadow Offset:
      • Width: 0
      • Height: 0
    • Shadow Opacity: 1
    • Shadow Radius: 4
    input-field.box-shadow.container.error
    • Shadow Color: $core.color.red.120
    • Shadow Offset:
      • Width: 0
      • Height: 0
    • Shadow Opacity: 1
    • Shadow Radius: 4
    input-field.box-shadow.container.success
    • Shadow Color: $core.color.green.100
    • Shadow Offset:
      • Width: 0
      • Height: 0
    • Shadow Opacity: 1
    • Shadow Radius: 4
    Table of Contents