Tag
A small label for a category or filter applied to an item, optionally removable with an X or clickable to drill into it.
Preview
Code
Example.jsx
import { useState, useCallback } from 'react';
import { Card, BlockStack, InlineStack, Tag, TextField, Button, Text, Divider } from '@shopify/polaris';
const INITIAL_TAGS = ['Ceramics', 'Kitchen', 'Handmade', 'Summer essentials'];
export const Example = () => {
const [tags, setTags] = useState(INITIAL_TAGS);
const [draft, setDraft] = useState('');
const removeTag = useCallback((value) => {
setTags((prev) => prev.filter((tag) => tag !== value));
}, []);
const addTag = useCallback(() => {
const value = draft.trim();
if (!value) return;
setTags((prev) => (prev.includes(value) ? prev : [...prev, value]));
setDraft('');
}, [draft]);
return (
<Card>
<BlockStack gap="400">
<Text as="h2" variant="headingMd">
Product tags
</Text>
<TextField
label="Add a tag"
value={draft}
onChange={setDraft}
autoComplete="off"
placeholder="Stoneware"
connectedRight={<Button onClick={addTag}>Add</Button>}
/>
<InlineStack gap="200">
{tags.length === 0 ? (
<Text as="p" tone="subdued">
No tags yet. Tags help customers filter your collections.
</Text>
) : (
tags.map((tag) => (
<Tag key={tag} onRemove={() => removeTag(tag)}>
{tag}
</Tag>
))
)}
</InlineStack>
<Divider />
<BlockStack gap="200">
<Text as="h3" variant="headingSm">
Other variations
</Text>
<InlineStack gap="200" blockAlign="center">
<Tag>Read only</Tag>
<Tag disabled onRemove={() => {}}>
Locked by app
</Tag>
<Tag url="https://admin.shopify.com/collections">Clickable</Tag>
<Tag onClick={() => setDraft('Best seller')}>Best seller</Tag>
</InlineStack>
<Text as="p" tone="subdued">
{tags.length} tag{tags.length === 1 ? '' : 's'} on this product.
</Text>
</BlockStack>
</BlockStack>
</Card>
);
};