Label
Labels describe the purpose of a form element in a UI
Resources
Name | Resource | Status |
---|---|---|
Figma | Design Kit (Figma) | Private |
On this page
On this page
import { Field, Label } from '@cerberus/react'
Usage
import { Field, Label } from '@cerberus/react'
function LabelBasicPreview() { return ( <Field required> <Label htmlFor="first_name">First Name</Label> <Input id="first_name" placeholder="Type your first name" type="text" /> </Field> )}
Hidden
import { Field, Label } from '@cerberus/react'
function LabelHiddenPreview() { return ( <Field required> <Label htmlFor="global_search" hidden> Search anything </Label> <Input id="global_search" placeholder="Search anything" type="text" /> </Field> )}
Optional
import { Field, Label } from '@cerberus/react'
function LabelOptionalPreview() { return ( <Field> <Label htmlFor="preferred">Preferred Name</Label> <Input id="preferred" placeholder="i.e. Johnny" type="text" /> </Field> )}
Customizing
import { Field, Label } from '@cerberus/react'
function LabelCustomPreview() { return ( <Field required> <Label className={css({ fontSize: '2rem', bgColor: 'black', color: 'yellow', })} htmlFor="global_search" > Killa Bees </Label> <input id="global_search" type="text" /> </Field> )}
API
export interface FieldProps { disabled?: boolean invalid?: boolean required?: boolean readOnly?: boolean}
define function Field(props: PropsWithChildren<FieldProps>): ReactNode
export interface LabelProps extends LabelHTMLAttributes<HTMLLabelElement> { htmlFor: string hidden?: boolean size?: 'sm' | 'md'}
define function Label(props: LabelProps): ReactNode
Props
The LabelProps
component accepts the following props:
Name | Default | Description |
---|---|---|
htmlFor | null | The name attribute of the Input the Label is associated with. |
hidden | false | Whether the Label content should be visually hidden. |
size | 'md' | The size of the Label. |
On this page
Use Cases
- Users should be able to:
- Navigate to and activate a text field with assistive technology
- Input information into the text field
- Receive and understand supporting text and error messages
- Navigate to and select interactive icons
Interaction & Style
The containers for both filled and outlined text fields provide the same functionality. Changes to color and thickness of stroke help provide clear visual cues for interaction.
Keyboard Navigation
Keys | Actions |
---|---|
Tab | Focus lands on (non-disabled) input |
Labeling Elements
If the UI text is correctly linked, assistive tech (such as a screenreader) will read the UI text followed by the component's role.
The accessibility label for a textfield is typically the same as the label for the textfield.
On this page