Installation
import { TextField } from "@octopusdeploy/design-system-components"
Properties
Using the Text Field component
When setting up a Text Field component you will need to import TextField from the design-system-components package.
For example:
<TextField
value={value}
onChange={onChange}
label="Input Label"
description="Input Description"
error={error}
type="text"
/>
Type of Textfield
Depending on what the TextField is used for, determines which type you should use, as each type provides different features. We currently support the following types listed in the table below. If you would like to use a type that is not currently supported please reach out to #team-frontend-foundations-requests or follow the Contribution guidelines.
|
Type |
Description |
|---|---|
|
text |
The default value. A single-line text field. Line-breaks are automatically removed from the input value. |
|
|
A field for editing an email address. Looks like a text input, displays more helpful keypad in some devices with dynamic keypads. Includes some additional validation relevant to emails. |
|
password |
A single-line text field with an obscured value. Will alert the user if site is not secure. |
|
number |
For entering a number. Displays a numeric keypad in some devices with dynamic keypads. |
|
tel |
For telephone numbers. Displays a telephone keypad in some devices with dynamic keypads. |
|
url |
Use when entering a URL. Looks like a text input, but has validation parameters and relevant keyboard in supporting browsers and devices with dynamic keyboards. |
|
search |
A single-line text field for entering search strings. Line-breaks are automatically removed from the input value. Displays a search icon instead of enter key on some devices with dynamic keypads. |
|
time |
A control for entering a time value with no time zone. We use this type for the Time Picker component. |
You can also refer to the MDN documentation on Input Types for further information and additional types.
Expandable form sections
When a form component is used inside an Expandable Form Section, we sometimes hide its field label and description, for example with RadioGroup. That’s because RadioGroup already includes a group legend plus labels/descriptions for each option. In those cases we are hiding the legend not the input label.
This doesn’t apply to TextField, which needs its own label and a description at the input level.
Form Description
Form descriptions allow you to pass in a string, with the option to include an inline code descriptor or link. It has a particular format to allow for flexibility. You can include as many links or code descriptors as you need.
For example:
descriptionText`Set ${descriptionText.code("itemEnabled")} to true or see our ${descriptionText.link("guide", "/docs/guide")} for more details.`
The above code will render the following:
Adding a Popover to the label
This is used to display a Popover with more content explaining the context of a field. It should only be used when the Helper Text is not sufficient.
To include this you can pass the PopoverBasicHelp component to the popover prop, e.g.:
<TextField
label="With Popover"
value="Popover"
popover={<PopoverBasicHelp placement="right-start" description="A popover" />}
onChange={handleChange}
/>
Suffix and Prefix
The Textfield accepts a suffix and a prefix which can be used together or on their own. The suffix and prefix will not be saved with the value, they are for display purposes only.
When using a string the suffix is truncated at 4 characters, the prefix has no restriction. The Textfield will adjust the spacing in the component according to the size of the text automatically.
Prefix
The prefix, which appears at the start of the component accepts a string as mentioned above but it also allows the a Design System Icon. The prefix does not allow interactive elements, if you require interactive elements you should use a suffix .
The icon should be set to size of 20 and include relevant aria-label for accessibility purposes.
<TextField label="Icon prefix" onChange={handleChange} prefix={<MagnifyingGlassIcon size={20} ariaLabel="Search" />} />
If you need an Icon that that is not currently supported please follow the Proposing an icon guidelines or reach out to #team-frontend-foundations-requests.
Suffix
The suffix appears at the end of the input and can be a string as mentioned above, or a button. Buttons should be used for interactive elements such as dropdown menus.
The button can be passed into the suffix prop following the example below.
- Button importance: ghost
- Button size: medium
- Icon size should be 20
<TextField label="With suffix" onChange={handleChange} suffix={<Button icon={<CaretDownIcon size={20} />} onClick={() => {}} importance="ghost" size="medium" />} />
Actions
TextField accepts an optional actions prop which is an array of a maximum of two icon-only Button elements rendered inside the field. They appear after the value (and after the clear button when one is shown).
They can be used for field-scoped actions such as adding a related entity or revealing extra options.
TextField will also accept custom buttons, however you should always use importance="ghost" and size="small" so they sit correctly within the field.
If an action needs to read or modify the input directly (for example, inserting text at the caret), give both the action and the TextField the same inputRef.
If the input is disabled or read-only, you must also pass the disabled state via the buttons disabled prop to ensure it is disabled as well.
<TextField
label="Worker pool"
value={value}
onChange={setValue}
actions={[
<Button
key="add"
icon={<PlusIcon size={20} />}
importance="ghost"
size="small"
accessibleName="Add worker pool"
onClick={openAddWorkerPoolDrawer}
/>,
]}
/>
Action Buttons can also be wrapped in a Tooltip component if extra information is required, though we recommend adding this only when necessary as it can create a noisy interface.
Displaying a validation message
To display a validation message, use the validationMessage prop. By default this will be displayed as an error. The validationState prop can be set to "success" if a success message is needed.
Code Sub-components
Sub-components are used to compose the Form components in the Design System, however they are not exposed via the design system package and therefore cannot be used on their own. Instead, use the packaged components we ship, e.g. TextField , etc.
Should you require changes to the sub components please reach out in #team-frontend-foundations-requests or follow the Contribution guidelines.
|
Name |
Description |
|---|---|
|
InputLabel |
Renders the label for the input item |
|
InputError |
Renders the error message and icon for the component |
|
FormDescription |
Renders a text description with optional links, or inline code descriptors |