Marigold
Marigold

Application

MarigoldProvider
RouterProvider

Layout

AppLayoutbeta
Aside
Aspect
Breakout
Center
Columns
Container
Grid
Inline
Inset
Scrollable
Split
Stack
Tiles

Actions

ActionBaralpha
Button
Link
LinkButton
ToggleButtonalpha
ToggleButtonGroupalpha

Form

Autocomplete
Calendarupdated
Checkbox
ComboBox
DateField
DatePicker
FileField
Form
Multiselectdeprecated
NumberField
Radio
SearchField
Select
Slider
Switch
TagFieldbeta
TextArea
TextField
TimeField

Collection

SelectList
Tableupdated
Tag

Navigation

Accordion
Breadcrumbs
Pagination
Sidebarbeta
Tabs
TopNavigationbeta

Overlay

ContextualHelp
Dialog
Drawer
Menu
Toastbeta
Tooltip

Content

Badge
Card
Divider
EmptyStatebeta
Headline
Icon
List
Loader
SectionMessage
SVG
Text

Formatters

DateFormat
NumericFormat

Hooks and Utils

cn
cva
extendTheme
parseFormData
useAsyncListData
useListData
useResponsiveValue
useTheme
VisuallyHidden
Components

TextField

Component for input forms.

The <TextField> is a form component which allows user to enter text with a keyboard. It creates interactive controls for web-based forms in order to accept data from the user. It is also one of the most powerful and complex elements in all of HTML due to the sheer number of combinations of input types and attributes.

Anatomy

Text fields consist of an input element, which is a container in which the user enters data, and a label which informs the user about the content they need to enter in the field. <TextField> automatically manages the relationship between these two elements. It also supports optional description and error message elements, which can be used to provide more context about the field, and any validation messages.

Anatomy of table

Appearance

The appearance of a component can be customized using the variant and size props. These props adjust the visual style and dimensions of the component, available values are based on the active theme.

The selected theme does not has any options for"variant" and "size".

Usage

Use a <TextField> if a user needs to input unique information that cannot be predicted with a preset of options (e.g. Radio, Select etc.) and also a user needs to input memorable data that can be entered more quickly in a free-hand format versus a more complex control.

Avoid using <TextField> if a user can only enter an option from a predefined list then avoid using a free-form text input as it is likely to result in an error. Consider using a selection control such as a dropdown, select, or radio button group instead.

Label

In general label should be short and precise about what is expected from the user. Avoid unnecessary instructional verbs (doing words) in your labels and hints because it's already implied by the input field. Avoid placeholder text in most cases, as there's no need for it (more about it in the next section).

Do
Do: Use short labels
Use short labels.
Don't
Don't use unnecessary instructional verbs

Don't use unnecessary instructional verbs.

Placeholder

Placeholder text is a short hint displayed inside an input field before a user enters a value. To save space, placeholder text is often used instead of a label, as shown in the first example. This is problematic for the following reasons:

  • Placeholder text disappears once a person starts filling in an input field, causing some to forget what the field was for
  • Some might miss or skip fields with placeholder text, as it can look like the field has already been pre-filled.
  • Placeholder text colour contrast is almost always inaccessible, as it's very light by design. This means many will struggle to read the label.
Do
Do: Use label instead of a placeholder
Use label instead of a placeholder.
Don't
Don't use placeholder text instead of a label

Don't use placeholder text instead of a label.

Additional description

Sometimes the label isn't enough for the user. In this case, to gather additional support for the user we can use the help text. With this we can add helpful hints for the user below the input field. Beside that the help text is placed in close proximity to the associated input field.

Do
Do: Use help text to show an example what's expected

Use help text to show an example what's expected.

Do
Do: Explain why certain information is needed
Explain why certain information is needed.

Textfield with an error

Error messages should let people know that a problem occurred, why it happened, and provide a solution to fix it and move forward.

Don't
Don't: Never blame the user

Never blame the user. Always be positive and helpful.

Don't
Don't: Be concise and avoid unnecessary words

Be concise and avoid unnecessary words like "please", "sorry" and "oops"

Do
Do: Use detailed messages instead of global messages

Use detailed messages instead of global messages.

The error prop toggles the error state of a field. The errorMessage prop can then be used to provide feedback to the user about the error. The message disappears automatically when all requirements are met.

Enter your 5 digit zip code.
import { useState } from 'react';import { TextField } from '@marigold/components';export default () => {  const [zipCode, setZipCpode] = useState<string>('7911');  return (    <TextField      label="Zip code"      pattern="[0-9]{5}"      value={zipCode}      description="Enter your 5 digit zip code."      errorMessage="Your zip code hasn't 5 digits. Update it and try again."      onChange={setZipCpode}    />  );};

Note

Press Enter, after typing your text, to trigger the validation.

Props

Did you know? You can explore, test, and customize props live in Marigold's storybook. Watch the effects they have in real-time!
View TextField stories

TextField

Prop

Type

Related

Form developement guide

This page should introduce you on how to build forms with Marigold.
Last update: 10 days ago

TextArea

Component for entering multiline text input.

TimeField

Component for entering time in forms.

On this page

AnatomyAppearanceUsageLabelPlaceholderAdditional descriptionTextfield with an errorPropsTextFieldRelated