Input can provide a visual representations of its status with disabled, error, readonly and loading states. You can use any combination of those states for the experience.
Labels should be used to describe the information we're asking the user to give us. Placeholders should be used to show an example of the content we're asking the user for. If we use placeholders as labels, once the user starts typing into the field, they lose the description of what we're asking for.
Input addons can be used to show an icon or a text that help users enter information in the Input. These serve as decorative additions, not additional actions.
<Form>
<Form.Groupwidths="5">
<Form.Inputlabel="Cost"shortLabel="$"small/>
</Form.Group>
<Form.Groupwidths="4">
<Form.Input
label="Job Duration"
shortLabel="days"
shortLabelPosition="right"
/>
</Form.Group>
<Form.Groupwidths="3">
<Form.Input
label="Technician Name"
shortLabel={<Iconname="person"/>}
large
/>
</Form.Group>
</Form>
Addon Guidance
Addons are helpful when they enhance the understanding of an input. This can be particularly useful with units of measurement, where fields may have specific formats, and with icons that are universally understood.
Addons should be avoided when they don't serve a use for users or when the addon's meaning is not well understood. A good default is to design without an addon, and only adding one to further enhance its usability.
Caution. Addons may not convey additional context, adding unnecessary visual weight
Inputs can appear in three different sizes. The medium size is the default size, while small and large will allow the inputs to resize to take up more and less space in a layout. These match up with our Button sizes.
<Form>
<Form.Inputlabel="Small Input"small/>
<Form.Inputlabel="Default Input"/>
<Form.Inputlabel="Large Input"large/>
</Form>
Focus
An input can be focused via a ref
()=>{
const ref = React.createRef();
constonClick=()=>{
ref.current.focus();
};
return(
<Form>
<Stackspacing="1">
<ButtononClick={onClick}>Focus</Button>
<Inputref={ref}style={{flexGrow:1}}/>
</Stack>
</Form>
);
};
Best Practices
Inputs should:
Be clearly labeled so it’s obvious to the user what they should enter into the field
Only ask for information that’s really needed
Validate input as soon as merchant has finished interacting with a field (but not before)
Content Guidelines
Use a label for all input fields
A label is a short, meaningful description that clearly indicates what the user is expected to enter. Labels should be 1 to 3 words and written in title case. Labels should primarily be nouns. Avoid using labels as CTAs. A label is not inline help and shouldn’t be used to provide instruction.
Do
Don't
Follow capitalization rules
Input labels should be written in title case.
Do
Don't
Avoid using placeholder text
Placeholder text has several accessibility issues:
Text has low contrast which makes the text hard to read
Text disappears as soon as the user starts typing
Can’t accommodate additional context due to limited space
Unreliable for screen readers
Use inline help to provide hints, formatting, and requirements.
Form design pattern for how related controls are ordered.
Importing
We recommend using the Form shorthand component <Form.Input />. It automatically provide the correct Form grouping structure and spacing. You can import the standalone component for custom Form layouts.