Examples
Filled labels
GreyGrey iconGrey removable Grey icon removable Grey link Grey link removable Grey label with icon that overflows Grey link removable (disabled)
Blue Blue icon Blue removable Blue icon removable Blue link Blue link removable Blue label with icon that overflows Blue link removable (disabled)
Green Green icon Green removable Green icon removable Green link Green link removable Green label with icon that overflows Green link removable (disabled)
Orange Orange icon Orange removable Orange icon removable Orange link Orange link removable Orange label with icon that overflows Orange link removable (disabled)
Red Red icon Red removable Red icon removable Red link Red link removable Red label with icon that overflows Red link removable (disabled)
Orange red Orange red icon Orange red removable Orange red icon removable Orange red link Orange red link removable Orange red label with icon that overflows
Purple Purple icon Purple removable Purple icon removable Purple link Purple link removable Purple label with icon that overflows Purple link removable (disabled)
Teal Teal icon Teal removable Teal icon removable Teal link Teal link removable Teal label with icon that overflows Teal link removable (disabled)
Yellow Yellow icon Yellow removable Yellow icon removable Yellow link Yellow link removable Yellow label with icon that overflows Yellow link removable (disabled)
Status:
Success Success removable Success link Success link removable Success label with text that overflows
Warning Warning removable Warning link Warning link removable Warning label with text that overflows
Danger Danger removable Danger link Danger link removable Danger label with text that overflows
Info Info removable Info link Info link removable Info label with text that overflows
Custom Custom removable Custom link Custom link removable Custom label with text that overflows
Outlined labels
Grey Grey icon Grey removable Grey icon removable Grey link Grey link removable Grey label with icon that overflows Grey link removable (disabled)
Blue Blue icon Blue removable Blue icon removable Blue link Blue link removable Blue label with icon that overflows Blue link removable (disabled)
Green Green icon Green removable Green icon removable Green link Green link removable Green label with icon that overflows Green link removable (disabled)
Orange Orange icon Orange removable Orange icon removable Orange link Orange link removable Orange label with icon that overflows Orange link removable (disabled)
Red Red icon Red removable Red icon removable Red link Red link removable Red label with icon that overflows
Orange red Orange red icon Orange red removable Orange red icon removable Orange red link Orange red link removable Orange red label with icon that overflows
Purple Purple icon Purple removable Purple icon removable Purple link Purple link removable Purple label with icon that overflows Purple link removable (disabled)
Teal Teal icon Teal removable Teal icon removable Teal link Teal link removable Teal label with icon that overflows Teal link removable (disabled)
Yellow Yellow icon Yellow removable Yellow icon removable Yellow link Yellow link removable Yellow label with icon that overflows Yellow link removable (disabled)
Status:
Success Success removable Success link Success link removable Success label with text that overflows
Warning Warning removable Warning link Warning link removable Warning label with text that overflows
Danger Danger removable Danger link Danger link removable Danger label with text that overflows
Info Info removable Info link Info link removable Info label with text that overflows
Custom Custom removable Custom link Custom link removable Custom label with text that overflows
Compact labels
Editable labels
Click or press either enter or space to begin editing a label. After editing, click outside the label or press enter again to complete the edit. To cancel an edit, press escape.
You can also customize any Label's close button aria-label as this example shows with closeBtnAriaLabel
.
Basic label group
Use a label group when you have multiple labels to display at once.
- Label 1
- Label 2
- Label 3
Label group with overflow
An overflow label can be added to the end of a group to save space when the number of labels exceeds some threshold. Click the overflow label to expand and collapse the group.
- Label 1
- Label 2
- Label 3
Vertical label group
Labels in a group can also be stacked vertically. This example shows a verical label group with a category name and overflow.
- Label 1
- Label 2
- Label 3
Editable label group with add button
The contents of a label group can be modified by removing labels or adding new ones using the add button. For additional documentation that showcases adding a new label, see label demos.
Props
Label
Name | Type | Default | Description |
---|---|---|---|
children | React.ReactNode | Content rendered inside the label. | |
className | string | '' | Additional classes added to the label. |
closeBtn | React.ReactNode | Node for custom close button. | |
closeBtnAriaLabel | string | Aria label for close button | |
closeBtnProps | any | Additional properties for the default close button. | |
color | 'blue' | 'teal' | 'green' | 'orange' | 'purple' | 'red' | 'orangered' | 'grey' | 'yellow' | 'grey' | Color of the label. |
editableProps | any | Additional props passed to the editable label text div. Optionally passing onInput and onBlur callbacks will allow finer custom text input control. | |
href | string | Href for a label that is a link. If present, the label will change to an anchor element. This should not be passed in if the onClick prop is also passed in. | |
icon | React.ReactNode | Icon added to the left of the label text. Overrides the icon set by the status property. | |
isCompact | boolean | false | Flag indicating the label is compact. |
isDisabled | boolean | false | Flag indicating the label is disabled. Works only on clickable labels, so either href or onClick props must be passed in. |
isEditable | boolean | false | Flag indicating the label is editable. |
onClick | (event: React.MouseEvent) => void | Callback for when the label is clicked. This should not be passed in if the href or isEditable props are also passed in. | |
onClose | (event: React.MouseEvent) => void | Close click callback for removable labels. If present, label will have a close button. | |
onEditCancel | (event: KeyboardEvent, previousText: string) => void | Callback when an editable label cancels an edit. | |
onEditComplete | (event: MouseEvent | KeyboardEvent, newText: string) => void | Callback when an editable label completes an edit. | |
render | ({ className, content, componentRef }: { className: string; content: React.ReactNode; componentRef: any; }) => React.ReactNode | Forwards the label content and className to rendered function. Use this prop for react router support. | |
status | 'success' | 'warning' | 'danger' | 'info' | 'custom' | Status of the label with a respective icon and color. Overrides the color set by the color property. | |
textMaxWidth | string | The max width of the label before it is truncated. Can be any valid CSS unit, such as '100%', '100px', or '16ch'. | |
tooltipPosition | | TooltipPosition | 'auto' | 'top' | 'bottom' | 'left' | 'right' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'left-start' | 'left-end' | 'right-start' | 'right-end' | Position of the tooltip which is displayed if text is truncated | |
variant | 'outline' | 'filled' | 'overflow' | 'add' | 'filled' | Variant of the label. |
LabelGroup
Name | Type | Default | Description |
---|---|---|---|
addLabelControl | React.ReactNode | Control for adding new labels | |
aria-label | string | 'Label group category' | Aria label for label group that does not have a category name |
categoryName | string | '' | Category name text for the label group category. If this prop is supplied the label group with have a label and category styling applied |
children | React.ReactNode | Content rendered inside the label group. Should be <Label> elements. | |
className | string | Additional classes added to the label item | |
closeBtnAriaLabel | string | 'Close label group' | Aria label for close button |
collapsedText | string | '${remaining} more' | Customizeable template string. Use variable "${remaining}" for the overflow label count. |
defaultIsOpen | boolean | false | Flag for having the label group default to expanded |
editableTextAreaProps | any | Additional props passed to the editable textarea. | |
expandedText | string | 'Show Less' | Customizable "Show Less" text string |
hasEditableTextArea | boolean | false | Flag indicating the editable label group should be appended with a textarea. |
isClosable | boolean | false | Flag if label group can be closed |
isCompact | boolean | false | Flag indicating the labels in the group are compact |
isEditable | boolean | false | Flag indicating contained labels are editable. Allows spacing for a text input after the labels. |
isVertical | boolean | false | Flag to implement a vertical layout |
numLabels | number | 3 | Set number of labels to show before overflow |
onClick | (event: React.MouseEvent) => void | (_e: React.MouseEvent) => undefined as any | Function that is called when clicking on the label group close button |
tooltipPosition | | TooltipPosition | 'auto' | 'top' | 'bottom' | 'left' | 'right' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'left-start' | 'left-end' | 'right-start' | 'right-end' | 'top' | Position of the tooltip which is displayed if the category name text is longer |
CSS variables
Prefixed with 'pf-v5-c-label'
Expand or collapse column | Selector | Variable | Value |
---|
Prefixed with 'pf-v5-c-label-group'
Expand or collapse column | Selector | Variable | Value |
---|