FormLayout
Stacks form fields with the correct spacing, and groups related fields side by side with FormLayout.Group.
Preview
Code
Example.jsx
import { useState } from 'react';
import { Card, BlockStack, FormLayout, TextField, Select, Checkbox, Text, Button, InlineStack } from '@shopify/polaris';
const DISCOUNT_TYPES = [
{ label: 'Percentage', value: 'percentage' },
{ label: 'Fixed amount', value: 'fixed' },
];
const CHANNELS = [
{ label: 'Online store', value: 'online' },
{ label: 'Point of sale', value: 'pos' },
];
export const Example = () => {
const [title, setTitle] = useState('Summer sale');
const [code, setCode] = useState('SUMMER20');
const [type, setType] = useState('percentage');
const [value, setValue] = useState('20');
const [startDate, setStartDate] = useState('2025-06-01');
const [endDate, setEndDate] = useState('2025-08-31');
const [channel, setChannel] = useState('online');
const [oncePerCustomer, setOncePerCustomer] = useState(true);
return (
<Card>
<BlockStack gap="400">
<Text as="h2" variant="headingMd">
Create discount
</Text>
<FormLayout>
<TextField label="Title" value={title} onChange={setTitle} autoComplete="off" helpText="Customers will not see this." />
<FormLayout.Group>
<Select label="Discount type" options={DISCOUNT_TYPES} value={type} onChange={setType} />
<TextField
label="Value"
value={value}
onChange={setValue}
autoComplete="off"
type="number"
suffix={type === 'percentage' ? '%' : undefined}
prefix={type === 'fixed' ? '$' : undefined}
/>
</FormLayout.Group>
<FormLayout.Group condensed>
<TextField label="Discount code" value={code} onChange={setCode} autoComplete="off" />
<TextField label="Start date" value={startDate} onChange={setStartDate} autoComplete="off" type="date" />
<TextField label="End date" value={endDate} onChange={setEndDate} autoComplete="off" type="date" />
</FormLayout.Group>
<Select label="Sales channel" options={CHANNELS} value={channel} onChange={setChannel} />
<Checkbox
label="Limit to one use per customer"
checked={oncePerCustomer}
onChange={setOncePerCustomer}
/>
<InlineStack align="end" gap="200">
<Button onClick={() => {}}>Discard</Button>
<Button variant="primary" onClick={() => {}}>
Save discount
</Button>
</InlineStack>
</FormLayout>
</BlockStack>
</Card>
);
};