Search the documentation

Type to search page titles, component names and descriptions.

    Data Entry

    Text and number fields

    Text, long text, search, exact numbers and money.

    import { MoneyField, NumberField, SearchField, TextArea, TextField } from 'faifo-design'

    TextField, TextArea, SearchField, NumberField and MoneyField share one field contract: label, help, error, disabled and read-only states. Numbers are typed and shown in the reader's language and submitted as a plain decimal.

    #When to use

    • Use NumberField for a quantity and MoneyField for an amount with its currency; both keep exact decimals.
    • Use SearchField for a query that filters what is on screen.
    • Use TextArea when the value is more than one line.

    #Notes

    showFieldError and clearFieldError let a client island show a server refusal under the field that caused it, exactly where Field renders its own error.

    #Examples

    Each example is a specimen of the package catalogue, rendered on the server exactly as shown in its code.

    #Scalar fields

    Text, long text, search, exact numeric and money values share one field contract.

    Show codeHide code
    import { Grid, MoneyField, NumberField, SearchField, TextArea, TextField } from 'faifo-design'
    
    export const Example = () => (
      <Grid
        columns={2}
        items={[
          <TextField id="customer" name="customer" label="Customer" value="An Việt" required />,
          <SearchField id="reference" name="reference" label="Reference" value="SO-1042" />,
          <NumberField id="quantity" name="quantity" label="Quantity" value="12" min="0" />,
          <MoneyField id="total" name="total" label="Total" value="18450000.00" />,
          <TextArea
            id="note"
            name="note"
            label="Internal note"
            value="Deliver before 17:00."
            span="full"
          />,
        ]}
      />
    )

    #Contract

    #Server field errors after a fetch submit

    A form that posts with fetch learns about a field error only after the page has rendered, so it cannot pass error to Field. Do not call setCustomValidity/reportValidity for it: the browser bubble covers the help text, disappears on the next click and leaves nothing for a screen reader to find again. Call showFieldError(control, message) from faifo-design with the control the server named (for a checkbox or radio group, any of its inputs). It adds the same field-error markup Field renders with error, after the help, sets data-invalid on the Field and aria-invalid plus the error ID in aria-describedby on the control (on the group and every choice for an option group), and focuses the control; pass { focus: false } when another error already took focus. A second call replaces the message. The next input or change inside that Field removes it and restores the attributes it found; the returned function and clearFieldError(control) remove it earlier, including an error the Field was rendered with. A check that answers while the person is still typing (an email someone already uses) passes { focus: false, announce: true }: focus stays in the field, and the message is an alert that is read out when it appears. A control outside a Field is a no-op, so say that message elsewhere (a toast or a Notice).

    #API

    Generated from the package source. A property without a description has none in the source yet.

    #clearFieldErrorFunction

    Removes a message showFieldError put on the Field holding control, or one the Field was rendered with. Does nothing when the Field shows no error.

    function clearFieldError(control: Element): void
    ParameterType
    controlrequiredElement
    Returnsvoid

    #showFieldErrorFunction

    Shows message under the Field that holds control, as Field renders its error, and focuses the control. A second call replaces the first message. Returns a function that removes the message, which also happens on the next input or change in the Field. announce is for a check that answers while the person is still typing in the Field: focus stays where it is, so the message is an alert and is read out when it appears.

    function showFieldError(control: HTMLElement, message: string, options?: { focus?: boolean | undefined; announce?: boolean | undefined; } | undefined) => (): void
    ParameterType
    controlrequiredHTMLElement
    messagerequiredstring
    options{ focus?: boolean, announce?: boolean }
    Returns() => void

    #formatLocaleNumberFunction

    A plain decimal written for a language ("1.800.000" in Vietnamese). Anything else, such as text a reader typed that is not a number, is shown as it is.

    function formatLocaleNumber(value: string | number | null | undefined, locale: string): string
    ParameterType
    valuerequiredstring | number | null | undefined
    localerequiredstring
    Returnsstring

    #numberControlValueFunction

    What a control holds as data: the plain decimal of a localized number field (its text, or the given text such as its default value), and the text unchanged for any other control or a typo.

    function numberControlValue(control: { value?: string | undefined; getAttribute?: ((name: string) => string | null) | undefined; }, text?: string | undefined): string
    ParameterType
    controlrequired{ value?: string, getAttribute?: (name: string) => string | null }
    textstring
    Returnsstring

    #parseLocaleNumberFunction

    The plain decimal ("-1234.5") a reader meant, or null when the text is not a number in that language. Grouping marks are accepted only in groups of three; a single mark that cannot be grouping (Vietnamese "12.5") reads as the decimal point of the other habit. Empty text stays empty.

    function parseLocaleNumber(text: string, locale: string): string | null
    ParameterType
    textrequiredstring
    localerequiredstring
    Returnsstring | null

    #MoneyFieldComponent

    PropertyDescriptionTypeDefault
    idrequired–string–
    namerequired–string–
    labelrequired–string–
    sizeOpt-in matched input/action height: 36px desktop, 44px mobile.'default' | 'large'–
    labelHiddenEmbedded controls share the frame of a compound field.boolean–
    required–boolean–
    disabled–boolean–
    help–string | null–
    span–'half' | 'full'–
    widthHow long the value is: the control is no wider than it needs (FieldFrame).'xs' | 'sm' | 'md'–
    issues–readonly FieldIssue[]–
    error–string | null–
    value–string | number | boolean | null–
    prefix–JSXChild–
    suffix–JSXChild–
    align–'start' | 'center' | 'end''end'
    appearance–'default' | 'embedded'–
    placeholder–string | null–
    readOnly–boolean–
    min–string | number–
    max–string | number–
    step–string | null–
    localeType and show the number as this language writes it: "28.600" is 28600 in vi. Submits the plain decimal through the design-system runtime; without a locale the native number input is kept.string–
    currency–string–
    precision–number–

    #NumberFieldComponent

    PropertyDescriptionTypeDefault
    idrequired–string–
    namerequired–string–
    labelrequired–string–
    sizeOpt-in matched input/action height: 36px desktop, 44px mobile.'default' | 'large'–
    labelHiddenEmbedded controls share the frame of a compound field.boolean–
    required–boolean–
    disabled–boolean–
    help–string | null–
    span–'half' | 'full'–
    widthHow long the value is: the control is no wider than it needs (FieldFrame).'xs' | 'sm' | 'md'–
    issues–readonly FieldIssue[]–
    error–string | null–
    value–string | number | boolean | null–
    prefix–JSXChild–
    suffix–JSXChild–
    align–'start' | 'center' | 'end'–
    appearance–'default' | 'embedded'–
    placeholder–string | null–
    readOnly–boolean–
    min–string | number–
    max–string | number–
    step–string | null–
    localeType and show the number as this language writes it: "28.600" is 28600 in vi. Submits the plain decimal through the design-system runtime; without a locale the native number input is kept.string–

    #SearchFieldComponent

    PropertyDescriptionTypeDefault
    idrequired–string–
    namerequired–string–
    labelrequired–string–
    sizeOpt-in matched input/action height: 36px desktop, 44px mobile.'default' | 'large'–
    value–string | number | boolean | null–
    prefix–JSXChild–
    suffix–JSXChild–
    inputMode–'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url'–
    align–'start' | 'center' | 'end'–
    maxLength–number–
    minLength–number–
    pattern–string–
    labelHiddenEmbedded controls share the frame of a compound field.boolean–
    appearance–'default' | 'embedded'–
    placeholder–string | null–
    required–boolean–
    disabled–boolean–
    readOnly–boolean–
    help–string | null–
    span–'half' | 'full'–
    widthHow long the value is: the control is no wider than it needs (FieldFrame).'xs' | 'sm' | 'md'–
    autocomplete–string | null–
    issues–readonly FieldIssue[]–
    error–string | null–
    clearable–boolean–
    clearLabel–string–

    #TextAreaComponent

    PropertyDescriptionTypeDefault
    idrequired–string–
    namerequired–string–
    labelrequired–string–
    sizeOpt-in matched input/action height: 36px desktop, 44px mobile.'default' | 'large'–
    labelHiddenEmbedded controls share the frame of a compound field.boolean–
    required–boolean–
    disabled–boolean–
    help–string | null–
    span–'half' | 'full'–
    widthHow long the value is: the control is no wider than it needs (FieldFrame).'xs' | 'sm' | 'md'–
    issues–readonly FieldIssue[]–
    error–string | null–
    value–string | number | boolean | null–
    rows–number–
    resize–'vertical' | 'none'–
    maxLength–number–
    minLength–number–
    appearance–'default' | 'embedded'–
    placeholder–string | null–
    readOnly–boolean–

    #TextFieldComponent

    PropertyDescriptionTypeDefault
    idrequired–string–
    namerequired–string–
    labelrequired–string–
    sizeOpt-in matched input/action height: 36px desktop, 44px mobile.'default' | 'large'–
    labelHiddenEmbedded controls share the frame of a compound field.boolean–
    required–boolean–
    disabled–boolean–
    help–string | null–
    span–'half' | 'full'–
    widthHow long the value is: the control is no wider than it needs (FieldFrame).'xs' | 'sm' | 'md'–
    issues–readonly FieldIssue[]–
    error–string | null–
    value–string | number | boolean | null–
    prefix–JSXChild–
    suffix–JSXChild–
    inputMode–'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url'–
    align–'start' | 'center' | 'end'–
    maxLength–number–
    minLength–number–
    pattern–string–
    appearance–'default' | 'embedded'–
    placeholder–string | null–
    readOnly–boolean–
    autocomplete–string | null–
    type–'text' | 'email' | 'tel' | 'password' | 'url''text'

    #Types

    #FieldIssue

    PropertyDescriptionTypeDefault
    pathrequired–string–
    messagerequired–string–

    #ScalarFieldProps

    PropertyDescriptionTypeDefault
    readOnlyWhenIn a RecordForm, lock/hide this field while the named peer has a non-empty value.string–
    hiddenWhen–string–
    open–boolean–
    onInputNative input events, also emitted by progressively enhanced controls.(event: Event) => void–
    onChange–(event: Event) => void–
    onBlur–(event: Event) => void–
    idrequired–string–
    namerequired–string–
    labelrequired–string–
    localeForward the host locale to date/time controls; omitted keeps their existing default.'vi' | 'en' | 'ja'–
    sizeOpt-in matched input/action height: 36px desktop, 44px mobile.'default' | 'large'–
    layoutKeep an enhanced control and its label in one row at narrow widths.'inline'–
    actionA command right after a short single-line entry, such as an Add or Apply Button. The entry keeps a compact width and Enter in it runs the command instead of the form's first submit button.JSXChild–
    value–string | number | boolean | null–
    checked–boolean | 'indeterminate'–
    submitValueLegacy checkbox value used checked state; submitValue opts into separate form data.string–
    prefix–JSXChild–
    suffix–JSXChild–
    clearable–boolean–
    clearLabel–string–
    inputMode–'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url'–
    numberLocaleA number or decimal typed and shown as this language writes it ("1.800.000" in vi). The control becomes a text input; the design-system runtime submits the plain decimal ("1800000").string–
    align–'start' | 'center' | 'end'–
    rows–number–
    resize–'vertical' | 'none'–
    maxLength–number–
    minLength–number–
    pattern–string–
    labelHiddenEmbedded controls share the frame of a compound field.boolean–
    selectionHiddenKeep the selected value accessible while showing only the select chevron.boolean–
    appearance–'default' | 'embedded'–
    placeholder–string | null–
    required–boolean–
    disabled–boolean–
    readOnly–boolean–
    min–string | number–
    max–string | number–
    help–string | null–
    options–readonly FieldOption[]–
    optionsOrientationHow checkbox-group and radio options flow. horizontal (default) wraps them on a line; vertical lists one option per line under the shared label, for choices whose labels should scan as a column.'horizontal' | 'vertical'–
    span–'half' | 'full'–
    widthHow long the value is: the control is no wider than it needs (FieldFrame).'xs' | 'sm' | 'md'–
    step–string | null–
    autocomplete–string | null–
    issues–readonly FieldIssue[]–
    error–string | null–

    #ScalarFieldBase

    Shared field metadata. Each scalar exposes only the options it implements.

    PropertyDescriptionTypeDefault
    idrequired–string–
    namerequired–string–
    labelrequired–string–
    sizeOpt-in matched input/action height: 36px desktop, 44px mobile.'default' | 'large'–
    labelHiddenEmbedded controls share the frame of a compound field.boolean–
    required–boolean–
    disabled–boolean–
    help–string | null–
    span–'half' | 'full'–
    widthHow long the value is: the control is no wider than it needs (FieldFrame).'xs' | 'sm' | 'md'–
    issues–readonly FieldIssue[]–
    error–string | null–

    #TextFieldProps

    The properties of TextField, listed above.

    #TextAreaProps

    The properties of TextArea, listed above.

    #NumberFieldProps

    The properties of NumberField, listed above.

    #MoneyFieldProps

    The properties of MoneyField, listed above.

    #SearchFieldProps

    The properties of SearchField, listed above.