Props
Usage guidelines
- When selecting and/or comparing categories with an accompanying chart or graph view that displays at-a-glance data for a user to quickly view key metrics
Best practices
Choose the right background to help it stand out in dense data interfaces. For example, set baseColor=secondary
when using TagData against a gray background.
Match TagData fill with the surrounding background color. Using the same color can make it unclear that TagData is selectable.
Use the same variants of TagData in a group, depending on the type of behavior TagData should have.
Mix TagData variants in the same group. This creates an unclear pattern for the user to understand which TagDatas are removable or not.
Use short and clear labels for easier comprehension — ideally one or two words.
Use long sentences in the text
prop, since the text in TagData truncates as needed to preserve the max width.
Accessibility
Users should be able to navigate or activate TagData using a keyboard or other input modalities. Be sure to include an accessibilityRemoveIconLabel
and tooltip.accessibilityLabel
for the screen reader with the onRemove
prop and tooltip
prop.
Localization
Be sure to localize all text strings. Note that localization can lengthen text by 20 to 30 percent.
When the text
of TagData reaches its max width, either intentionally or through localization, the text will be truncated with ellipses as needed to preserve the max-width.
Note that accessibilityRemoveIconLabel
is optional as DefaultLabelProvider provides default strings. Use custom labels if they need to be more specific.
import { useState } from 'react'; import { DefaultLabelProvider, Flex, TagData } from 'gestalt'; export default function Example() { const [isSelected, setSelected] = useState(false); return ( <DefaultLabelProvider labels={{ TagData: { accessibilityRemoveIconLabel: 'Tag entfernen', }, }} > <Flex alignItems="center" height="100%" justifyContent="center" width="100%" > <TagData onRemove={() => {}} onTap={() => { setSelected((selected) => !selected); }} selected={isSelected} size="lg" text="Eindrücke" /> </Flex> </DefaultLabelProvider> ); }
Variants
Size
TagData is available in 3 fixed sizes.
- lg has height of 48px. Text has a fixed size of 16px.
- md has height of 40px. Text has a fixed size of 14px.
- sm has height of 32px. Text has a fixed size of 14px.
import { Flex, TagData } from 'gestalt'; export default function Example() { return ( <Flex alignItems="center" direction="column" gap={2} height="100%" justifyContent="center" width="100%" > <TagData showCheckbox size="sm" text="Small TagData" /> <TagData showCheckbox size="md" text="Medium TagData" /> <TagData showCheckbox size="lg" text="Large Tagdata" /> </Flex> ); }
Base Color
By default, TagData uses a light gray fill, which is suitable for placement on a white background. When used on a gray background, use baseColor="secondary"
for a white fill.
import { Box, Flex, TagData } from 'gestalt'; export default function Example() { return ( <Flex alignItems="center" height="100%" justifyContent="center" width="100%" > <Box alignItems="center" display="flex" height="100%" justifyContent="center" width="50%" > <TagData baseColor="primary" size="sm" text="Small TagData" /> </Box> <Box alignItems="center" color="secondary" display="flex" height="100%" justifyContent="center" width="50%" > <TagData baseColor="secondary" size="sm" text="Small TagData" /> </Box> </Flex> ); }
Colors
TagData is available in the colors from our
data visualization color palette. Match each TagData's color
to its respective data line, which will be visible when TagData is selected.
import { useState } from 'react'; import { Box, Flex, TagData } from 'gestalt'; export default function Example() { const allColors = [ '01', '02', '03', '04', '05', '06', '08', '09', '10', '11', '12', ]; const [selectedColors, setSelectedColors] = useState(allColors); return ( <Box height="90%" overflow="scrollY" padding={2}> <Flex gap={4} justifyContent="center" wrap> {allColors.map((color) => ( <TagData key={color} color={color} id={color} onTap={({ id: selectedId, selected }) => { if (!selectedId) { return; } setSelectedColors((currSelectedColors) => !selected ? currSelectedColors.filter((tileId) => tileId !== color) : currSelectedColors.concat([color]) ); }} selected={selectedColors.includes(color)} showCheckbox text={`Color ${color}`} /> ))} </Flex> </Box> ); }
Group
Use TagData's showCheckbox
prop to display a checkbox. This is useful when presenting the user with a multi-select experience.
import { useState } from 'react'; import { Flex, TagData } from 'gestalt'; export default function Example() { const dataSources = [ { id: 'data-1', name: 'Monthly Active', color: '01', tooltip: 'Monthly active users', }, { id: 'data-2', name: 'Weekly Active', color: '02', tooltip: 'Weekly active users', }, { id: 'data-3', name: 'Daily Active', color: '03', tooltip: 'Daily active users', }, ]; const allIds = dataSources.map(({ id }) => id); const [selectedItems, setSelectedItems] = useState(allIds); return ( <Flex alignItems="center" gap={2} height="100%" justifyContent="center" width="100%" > {dataSources.map(({ id, color, tooltip, name }) => ( <TagData key={id} color={color} id={id} onTap={({ id: selectedId, selected }) => { if (!selectedId) { return; } setSelectedItems((currSelectedIds) => !selected ? currSelectedIds.filter((tileId) => tileId !== selectedId) : currSelectedIds.concat([selectedId]) ); }} selected={selectedItems.includes(id)} showCheckbox text={name} tooltip={{ text: tooltip }} /> ))} </Flex> ); }
Dismissible
Provide an onRemove
callback to make TagData dismissible. Tags are dismissible by the "X" affordance, which triggers the onRemove
callback. onRemove
should be used to update the external state that is keeping track of TagDatas. If your app uses
DefaultLabelProvider, a default accessibility label for the remove icon will be used. This can be overridden with a more specific label if desired.
import { useState } from 'react'; import { Flex, TagData } from 'gestalt'; export default function Example() { const dataSources = [ { id: 'data-1', name: 'Monthly Active', color: '01', tooltip: 'Monthly active users', }, { id: 'data-2', name: 'Weekly Active', color: '02', tooltip: 'Weekly active users', }, { id: 'data-3', name: 'Daily Active', color: '03', tooltip: 'Daily active users', }, ]; const allIds = dataSources.map(({ id }) => id); const [data, setData] = useState(dataSources); const [selectedItems, setSelectedItems] = useState(allIds); return ( <Flex alignItems="center" gap={2} height="100%" justifyContent="center" width="100%" > {data.map(({ id, color, tooltip, name }) => ( <TagData key={id} color={color} id={id} onRemove={({ id: selectedId }) => { if (!selectedId) { return; } setData((currData) => currData.filter((tile) => tile.id !== selectedId) ); }} onTap={({ id: selectedId, selected }) => { if (!selectedId) { return; } setSelectedItems((currSelectedIds) => !selected ? currSelectedIds.filter((tileId) => tileId !== selectedId) : currSelectedIds.concat([selectedId]) ); }} selected={selectedItems.includes(id)} showCheckbox text={name} tooltip={{ text: tooltip }} /> ))} </Flex> ); }
Tooltip
Use tooltip
to display clarifying information on hover or focus. We recommend using tooltips to provide the user additional context/details. You can also pass in a list of strings to create multi-line tooltips for TagData.
import { Flex, TagData } from 'gestalt'; export default function Example() { return ( <Flex alignItems="center" gap={2} height="100%" justifyContent="center" width="100%" > <TagData onRemove={() => {}} showCheckbox size="lg" text="CPM" tooltip={{ text: 'Average cost per 1K paid impressions' }} /> <TagData onRemove={() => {}} selected showCheckbox size="lg" text="MAU" tooltip={{ text: [ 'Monthly Active Users', 'The total monthly users over the last 30 days', ], }} /> </Flex> ); }
Disabled
Disabled TagData cannot be interacted with using the mouse or keyboard. This is commonly used to disable interaction when there are pending permissions or data prerequisites have not been met.
import { useState } from 'react'; import { Flex, TagData } from 'gestalt'; export default function Example() { const [isSelected, setSelected] = useState(true); return ( <Flex alignItems="center" height="100%" justifyContent="center" width="100%" > <TagData disabled onRemove={() => {}} onTap={() => { setSelected((selected) => !selected); }} selected={isSelected} showCheckbox size="lg" text="CPM" tooltip={{ text: 'Average cost per 1K paid impressions' }} /> </Flex> ); }
Component quality checklist
Quality item | Status | Status description |
---|---|---|
Figma Library | Ready | Component is available in Figma for web and mobile web. |
Responsive Web | Ready | Component responds to changing viewport sizes in web and mobile web. |
Related
Tag
Tags are objects that hold text and have a delete icon to remove them. They can appear within
TextFields,
TextAreas,
ComboBox or as standalone components.
TileData
TileData is a flexible, visually rich component that can be used as single or multiple selections on should be only used with data visualizations.