# Patterns

> Reusable solutions to recurring user problems: how patterns differ from components, and detailed guidance for forms, validation, empty states, loading, errors, search and filtering, navigation, notifications and confirmation.

Web page: https://odeocreative.me/tutorials/design-systems/patterns
Author: Hecham Gazhi (https://odeocreative.me)

Track: [Design System Tutorial](/md/tutorials/design-systems.md)

## Components vs patterns

**Components** are building blocks: a text field, a button, a checkbox. **Patterns** are proven ways of combining components to solve a recurring user problem: collecting an address, recovering from an error, filtering a long list, confirming a dangerous action.

Patterns capture knowledge that individual components can't. A perfect text field doesn't tell you when to validate, how to order fields, or where to put the error summary. Patterns do.

|  | Component | Pattern |
| --- | --- | --- |
| Is | A reusable UI element | A reusable solution to a user task |
| Example | Text field | Address form |
| Lives in | Figma library + code package | Documentation with examples (sometimes templates) |
| Answers | "What does it look like and how does it behave?" | "How do we solve this problem well, every time?" |

## Form pattern

- Single column, with fields grouped under clear headings.
- Labels above fields, always visible; placeholders only for format examples.
- Ask only what's needed; mark optional fields as "(optional)".
- Use the right input type and `autocomplete` attributes so browsers can fill data.
- Break long forms into steps with a progress indicator, and allow going back without losing data.
- One primary submit button, labelled with what it does ("Create account").

## Validation pattern

1. Explain requirements **before** input with help text ("At least 8 characters").
2. Validate a field when the user **leaves it** (on blur), not on every keystroke of the first attempt.
3. Once a field has an error, re-validate **as they type** so the error disappears as soon as it's fixed.
4. On submit, show an **error summary** at the top listing all errors as links to each field, and move focus to it.
5. Show each error **next to its field** with an icon, colour and a message that explains how to fix it.
6. Keep everything the user typed.

## Empty states

An empty state appears when there's no content to show. It's a chance to help, not a dead end. There are several kinds:

| Type | Example | What to show |
| --- | --- | --- |
| First use | No projects yet | What this area is for + the action to get started |
| User cleared | Inbox zero, all tasks done | Positive confirmation, maybe a small celebration |
| No results | Search or filter found nothing | What was searched, suggestions, "Clear filters" |
| Error / unavailable | Couldn't load data | What happened + retry |
| No permission | You don't have access | Why + how to request access |

```
[ illustration ]
No invoices yet
Create your first invoice to get paid faster.
[ Create invoice ]   Import from spreadsheet
```

## Loading pattern

| Wait time | Pattern |
| --- | --- |
| < 0.1s | No indicator needed |
| 0.1–1s | Subtle indicator or none; avoid flicker by delaying spinners briefly |
| 1–10s | Skeleton screens for content; spinner in buttons for actions |
| > 10s | Determinate progress with an estimate; let users do something else |

> Tip: These thresholds come from long-standing research on response times (popularised by Jakob Nielsen): about 0.1s feels instant, about 1s keeps the flow of thought, about 10s is the limit of attention.

## Error handling pattern

- **Prevent** first: constraints, good defaults, confirmations for destructive actions.
- **Explain** in plain language: what happened, why, and how to fix it.
- **Place** the message where the problem is: inline for fields, banners for page-level issues, toasts only for minor, temporary messages.
- **Preserve** work: never lose input because of an error; autosave drafts.
- **Offer a way out**: retry, contact support, go back.
- **Don't blame** the user: "We couldn't find that page" rather than "You entered an invalid URL".

## Search and filtering pattern

- Make search visible where people expect it (top of the page or list).
- Show suggestions and recent searches as people type.
- Tolerate typos and synonyms where possible.
- Show the number of results and what's being searched.
- Show active filters as removable chips with a "Clear all" option.
- On mobile, put filters in a full-screen sheet with an "Show 24 results" button.
- Keep filter and search state in the URL so it can be shared and survives refresh.

## Notifications and feedback

| Pattern | Use for | Behaviour |
| --- | --- | --- |
| Inline message | Feedback tied to one element | Stays until resolved |
| Banner / alert | Page or system-level information | Stays; dismissible if not critical |
| Toast / snackbar | Brief confirmation of an action ("Message sent") | Disappears after a few seconds; may offer Undo |
| Modal dialog | Critical decision that must be answered now | Blocks the page; use sparingly |
| Badge | Counts or status (3 unread) | Updates in place |

> Common mistake: Putting important errors or information in toasts that disappear before people can read them — especially users of screen readers or magnification. Toasts are for non-critical confirmations.

## Destructive action pattern

1. Style the action as destructive (red) and keep it away from frequent actions.
2. Prefer **Undo** over confirmation for reversible actions (archive, move to trash) — it's faster and safer.
3. For irreversible actions, use a confirmation dialog that names the object and the consequence: "Delete project 'Website redesign'? This permanently deletes 34 files."
4. Label the buttons with the action ("Delete project" / "Cancel") — never "Yes" / "No".
5. For very high-risk actions, require typing the name of the object.

## Key takeaways

- Patterns combine components to solve recurring user problems and capture knowledge components can't.
- Forms: one column, visible labels, minimal fields, clear progress; validate on blur and summarise on submit.
- Design every empty state: first use, cleared, no results, error and no permission.
- Choose loading indicators by wait time, and handle errors by preventing, explaining, preserving and offering a way out.
- Use the right feedback pattern; prefer Undo for reversible actions and specific confirmations for irreversible ones.

## Exercise: Document a pattern

1. Choose a pattern: empty states, search with filters or destructive actions.
2. Find three examples in products you use and screenshot them.
3. Write the problem the pattern solves and when to use it.
4. List the components it uses and the rules for combining them.
5. Add do's and don'ts with your screenshots as examples.

## Quiz

1. What's the difference between a component and a pattern?
   - There is none
   - **A component is a UI element; a pattern is a reusable solution to a user task** ✓
   - Patterns are only for mobile
   - Components are only in code
   - Why: Patterns describe how to combine components to solve problems.

2. When should a field first be validated?
   - On every keystroke from the first character
   - **When the user leaves the field (on blur) or submits** ✓
   - Only after the whole form is sent to the server
   - Never
   - Why: Validating too early shows errors before people finish typing.

3. What should a 'no results' empty state include?
   - Only an illustration
   - **What was searched, suggestions, and a way to clear filters** ✓
   - An error code
   - Nothing
   - Why: Help people recover and try again.

4. Which is the best confirmation dialog button label?
   - Yes
   - OK
   - **Delete project** ✓
   - Continue
   - Why: Specific action labels prevent mistakes.

5. Why avoid putting critical errors in toasts?
   - Toasts are ugly
   - **They disappear before some people can read them** ✓
   - They're too large
   - They can't contain text
   - Why: Toasts are for brief, non-critical confirmations.
