Background
Description
The Field component is used to collect user input in form layouts. A good Field component should be easy to scan and easy to interact with.
User stories
- As a designer or developer I need to create forms with label, field and other information for the user such as helper text, validation messages or tooltips.
History
There was some discussion of a Field component in T293271 when we were first discussing the scope of the TextInput component. Other discussions about Required/Optional field were started in T306427.
Known use cases
Users of Codex should be able to wrap inputs and controls within forms in a component that provides a consistent experience in terms of accessibility and error feedback across all forms.
| Helper text and inline feedback message in Create account | |
| Wikifunctions | |
| When the user fills an error, a tooltip with a feedback message appears in user's preferences | |
| Label (and description) before the field (on the left) like in this example from Wikifunctions | |
| Required field with asterisk next to the label in Wikidata | |
| Required field with asterisk within the field in the Calendar widget | |
| Optional field and tooltip in Event creation | |
Existing implementations
These artifacts are listed for historical context. The figma spec, linked below, is the source of truth for the new component.
Wikimedia community:
- Design style guide: n/a
- OOUI: FieldLayout
- Vue: Wikit's TextInput has validation handling
External libraries:
- Vuetify: Has a Form component, with some field functionality contained in form inputs/controls (e.g. labeling and validation within the TextField component)
- Buefy: Has a Field component with label, help text, grouping, and other layout features
Codex implementation
Component task owners
- Designer: @bmartinezcalvo
- Developer: add the main developer's name
Open questions
- Component architecture: Do we want a Form component or a Field component, or maybe both? Could any of this be handled within the input/control components themselves via composables?
- Required/Optional: Since all form fields are required by default, we will indicate just the optional ones in order to avoid too many asterisks across the form page. Optional text will appear next to the label and it will be included within the text when the label is multiline. It will be indicated with the whole word in order to be translated into different languages.
- Tooltip: it will be placed next to the label (also when the label wraps into two lines) to be always connected with the label text.
- Characters counter: it will not be implemented as part of the MVP task. It will be implemented in this other task T331000
- Helper text Vs. Inline message: For this MVP task, we will implement the same as we have in production to avoid possible problems. So inline message will appear bellow the helper text and both texts will be visible in the Field in some cases.
- Padding between label and field: we will use 4px padding between label, field and helper text.
- Description text: The description will be implemented as part of the MVP and we will provide guidelines to indicate when the designers should use the description text and when should they use other field elements such as helper text or a tooltip.
- Field action: Inline or stacked action could be displayed as part of the Field component. So we will implement them as properties.
- Label placement: We will implement the label on top for the MVP task. The option with the label on the left will be implemented in future iterations just if it's really needed in the product.
- Stacked fields vs. FieldSet: We will implement both the Field component (in this task) and the FieldSet (a combination of different Field components, this one will be implemented in another task).
Design spec
Anatomy
- Label style will be Bold as default and it could be customized to Regular. Regular will be used in field layouts where a combination of fields is grouped.
- Label section could display the following optional properties:
- Start icon
- Optional indicator when the form field is not required
- Tooltip. It will be created with a small 24px icon-only quiet button.
- Additional information could be added in the field using the following optional properties:
- Description text that could contain a link
- Helper text that could contain a link
- Inline action. The field component can contain an action that will affect the entire component, such as remove.
- Validation message. An InlineMessage will appear to provide feedback related to the field when warning, error or success.
- Field item can be replaced with any form item (such as text input, select, file input, etc.) or group (such as checkbox group, radio group or toggle switch group)
Style
- Label will be Bold as default and will use color-base
- Optional indicator will be Regular and color-subtle
- Description will be Regular and color-subtle
- Helper text will be Regular and color-subtle
- Padding between label section, field and helper text will be 4px on desktop and 8px on mobile
Interaction
The following states will be implemented:
- Default
- Hover, Active-Focus (just on field item)
- Read-only
- Disabled
- Loading (when we implement skeleton T311874)
- Filled
- Warning (the warning inline message will be displayed just when filled)
- Success (the warning inline message will be displayed just when filled)
- Error default (if the field is required and the user doesn't fill it, an error message will appear indicating that this field is mandatory)
- Error focus
- Error filled (an error message will appear indicating to the user how to fix the error)
Documentation
The configurable demo should include:
- Label + Field (text input) + Helper text will be displayed by default in the configurable demo
- Configurable properties:
- startIcon: the user will be able to type in a text input the icon they want to display
- optional field
- tooltip: the user will be able to type the text they want to display in the tooltip when hover/select it
- description: the user will be able to type in a text input the text they want to display in the demo
- helper text: the user will be able to type in a text input the text they want to display in the demo
- status: the user will select with radios the different status (warning, error or success) and an inline message will appear below the field
- disabled: the user will be able to select the disabled state with a toggle switch
- Reading direction: LTR/RTL will be selected with radios
Other standalone demos could include:
- A field component displaying the description with a link within the text
- A field component displaying the helper text with a link within the text
- A field component displaying another form item that is not a text input (e.g. a select)
- A field component displaying a group of form items (e.g. a checkbox group)
- A field component displaying an inline action that affects the entire field (e.g. remove)
Acceptance criteria
Minimum viable product
This task covers the minimum viable product (MVP) version of this component. MVP includes basic layout, default states, and most important functionality.
MVP scope
- A baseline set of components is supported for use within Field (Checkbox, Combobox, Lookup, Radio, SearchInput, Select, TextInput, ToggleSwitch)
- Single inputs or groups of inputs are supported
- <label> element (or <legend> for fieldsets) that is paired with an input or control component in a consistent way. See T309246 for MVP scope of the Label component. Description and optional flag are included here.
- Helper text
- Validation message (error only)
- Demos with various inputs (TextInput, Radio group, and other groups of inputs)
Design
- Design the Figma spec sheet and add a link to it in this task
- Update the component in the Figma library. This step will be done by a DST member.
Code
- Implement the component in Codex















