Select
A dropdown that lets someone pick one option from a short, predefined list, with support for grouped options, help text, placeholders and errors.
Preview
Code
Example.jsx
import { useState } from 'react';
import { Card, BlockStack, FormLayout, Select, Text, Divider } from '@shopify/polaris';
const STATUS_OPTIONS = [
{ label: 'Active', value: 'active' },
{ label: 'Draft', value: 'draft' },
{ label: 'Archived', value: 'archived' },
];
const COLLECTION_OPTIONS = [
{
title: 'Seasonal',
options: [
{ label: 'Summer essentials', value: 'summer' },
{ label: 'Holiday gifts', value: 'holiday' },
],
},
{
title: 'Evergreen',
options: [
{ label: 'Best sellers', value: 'best-sellers' },
{ label: 'New arrivals', value: 'new-arrivals' },
{ label: 'Clearance', value: 'clearance', disabled: true },
],
},
];
const RATE_OPTIONS = [
{ label: 'Standard (5 to 7 days)', value: 'standard' },
{ label: 'Express (2 days)', value: 'express' },
{ label: 'Local pickup', value: 'pickup' },
];
const WEIGHT_UNITS = ['g', 'kg', 'lb', 'oz'];
export const Example = () => {
const [status, setStatus] = useState('active');
const [collection, setCollection] = useState('');
const [rate, setRate] = useState('standard');
const [unit, setUnit] = useState('kg');
return (
<Card>
<BlockStack gap="400">
<Text as="h2" variant="headingMd">
Publishing
</Text>
<FormLayout>
<Select
label="Product status"
options={STATUS_OPTIONS}
value={status}
onChange={setStatus}
helpText="Draft products stay hidden from your storefront."
/>
<Select
label="Collection"
options={COLLECTION_OPTIONS}
value={collection}
onChange={setCollection}
placeholder="Choose a collection"
error={collection ? undefined : 'Pick a collection before publishing.'}
/>
<FormLayout.Group>
<Select label="Shipping rate" options={RATE_OPTIONS} value={rate} onChange={setRate} />
<Select
label="Weight unit"
labelInline
options={WEIGHT_UNITS}
value={unit}
onChange={setUnit}
/>
</FormLayout.Group>
<Select
label="Tax code"
options={[{ label: 'Inherited from store', value: 'store' }]}
value="store"
onChange={() => {}}
disabled
/>
</FormLayout>
<Divider />
<Text as="p" tone="subdued">
{status === 'active' ? 'This product is visible on your Online Store.' : 'This product is hidden from customers.'}{' '}
Ships as {rate} and is measured in {unit}.
</Text>
</BlockStack>
</Card>
);
};