Form Actions
FreeLine up the buttons at the end of a form: the main action, the way out and, when there is one, the destructive action.
npx wunderui-cli add form-actionsPlayground
Installation
npx wunderui-cli add form-actionsWrites the source into your project with its dependencies and, on first use, the styles - see Installation.
Then import what you need:
import { FormActions } from "@/components/blocks/form"Then use it:
import { Button } from "@/components/ui/button"
import { FormActions } from "@/components/ui/form-actions"
export function Actions() {
return (
<FormActions>
<Button type="button" variant="plain">
Cancel
</Button>
<Button type="submit" variant="gradient">
Save changes
</Button>
</FormActions>
)
}Expected result: You see two buttons at the right end of the row, 8 px apart: a white Cancel and an indigo Save changes. Put the row at the end of a form and Save sends it.
When to use
Use Form Actions for
- The buttons at the end of a form: Cancel and Save
- The footer of a card, a dialog or a sheet that holds a form
- A bar that sticks to the bottom of a long form, or Back and Continue in a flow of steps
Use something else for
- Button Group for buttons that belong to one control, such as a split or a segmented set
- Dialog for the footer of a dialog, which lays out its own buttons with DialogFooter
- Toolbar for commands that act on the page or a selection, not on one form
Arrangement
The main action is the gradient button, at the end by the way out. A destructive action goes to the opposite edge, never next to Save, and a row that will not fit stacks with the main action first.
Sizes
The buttons take the size of the fields above them: 32, 36 or 40 px. Pick one size for the whole row.
Placement
Below the last field is the default. A long form keeps its actions in view with a sticky bar, and a card or panel puts them in its footer.
Keyboard interactions
Form Actions adds no keys. Its buttons are ordinary buttons, in the order you write them.
- TaborShift+Tab
- Moves through the buttons from left to right as they are written. A disabled button is skipped; a pending button stays in the order and is announced as busy.
- SpaceorEnter
- Presses the focused button. A button with sends the form.
- Enter
- In a text field of the same form, presses the first enabled submit button, so the main action does not need a click.
Behavior and motion
What the row does itself, and what it leaves to the page.
- A plain row
- A plain flex row with an 8 px gap and centred items. It has no role and no state; the buttons carry both.
- Alignment
- End pushes the buttons to the end, start keeps them at the start, between splits first and last to opposite edges. With between, wrap the two end buttons in one div.
- Wrapping
- On a narrow screen the buttons wrap onto a second line instead of overflowing. For a deliberate column, stack them and put the main action first in the DOM.
- Order
- The row never reorders anything. Tab follows what you write, so write the buttons in the order they should appear.
- Pending
- A pending Button keeps its width and colour, shows a spinner and ignores presses, but stays focusable so the person doesn't lose their place. Disable the way out meanwhile.
- Disabled
- Disable Save only when there is nothing to send, and add a status line that says why. A dimmed button can't explain itself.
- Sticky and footers
- Make the row sticky with a border and background to keep it in view in a scrolling form, or give it a top border and subtle fill as a card footer. Round the container, not the row.
- Motion
- The row doesn't move. Buttons change colour quickly and the spinner turns.
- Reduced motion
- With reduced motion the spinner stops turning. The pending label still says the send is running.
Anatomy
Form Actions is one row that lines its children up and wraps when space runs out. The buttons in it (main action, way out, destructive action) are Buttons you choose.
- 1data-slot="form-actions"
The row. It lays its children out 8 px apart and wraps them onto a second line on a narrow screen; align sets where it sits: end (default), start or between.
- 2Optional
The way out of the form: Cancel, Discard or Back. A plain Button that doesn't compete with the main action, and it is disabled while the main action is pending.
- 3
The gradient Button that submits the form, one per row. It shows pending, success or error, with a label that says what is happening.
- 4Optional
An action that loses something, such as Delete draft. It sits at the other edge so a quick tap on the main action can't land on it; an irreversible step still needs its own confirmation.
Best practices
- Do
Put the main action last, next to the way out: Cancel, then Save changes. Write both as verbs that say what happens: Create project, not OK.
- Do
Keep the DOM order equal to the screen order, so Tab follows what the eye sees. The main action comes last at the end, first when aligned to the start.
- Do
While saving, show a pending main action with its own label (Saving…) and disable the way out. Afterwards show Saved for a moment.
- Do
Put a destructive action at the opposite edge and group the other two together. Ask in an Alert Dialog before an irreversible delete.
- Do
Match the size of the fields above the row (32, 36 or 40 px) and use one size for every button in it.
- Don’t
Don't put two gradient buttons in a row. One main action per row; the second is a plain Button.
- Don’t
Don't hide the main action under a menu, and don't disable it without saying why. If there is nothing to save, say so in a status line.
- Don’t
Don't reorder the buttons with CSS to move the main action. Tab order stays the same and stops matching the screen.
API reference
FormActions renders a div and takes the props below. It doesn't forward other attributes, so pass classes with className.
The row. It lays its children out 8 px apart and wraps them onto a second line on a narrow screen; align sets where it sits: end (default), start or between.
| Prop | Type | Default | Description |
|---|---|---|---|
| align | "start" | "end" | "between" | "end" | Where the buttons sit in the row. (the default) puts them at the end, at the start and puts the first child at the start and the last at the end, with the space between. |
| children required | ReactNode | — | The buttons of the row, in the order they should be tabbed. With , give it two children and wrap several buttons of the end in one . |
| className | string | — | Extra classes for the row. Use them to stack the buttons (), to stick the row to the bottom of a scrolling form or to turn it into a card footer. |
Notes for AI
Give your coding assistant the Markdown reference instead of screenshots.
get_component("form-actions")npx wunderui-cli add form-actionsThe full library index for assistants is at /llms.txt.