---
title: Scenarios
description: Define named sets of mock attributes, variables, URL parameters, API responses, and contexts to preview different states directly on the canvas.
---

# Scenarios

Scenarios let you define named sets of mock data and state overrides for a component or page so you can preview and test different states directly on the [canvas](/the-editor/canvas). Instead of manually changing test values or triggering live API requests every time you want to check a different state, you can switch between saved scenarios from the canvas top bar.

## Why use scenarios

Components and pages often behave differently depending on their inputs, internal state, fetched data, or surrounding context. With scenarios, you can preview each state on demand without changing your component's logic or initial values:

- **Component variants**: Preview a button as primary, secondary, or disabled, or view a card with short versus long text
- **API states**: Test loading skeletons, empty lists, populated data, and error messages without calling a live back end
- **Page routes**: Switch between different dynamic path parameters and query parameters on a page
- **Context states**: Preview how a component renders for a logged-out visitor, a signed-in member, or an admin user

::: info
Scenarios only apply while previewing in the Nordcraft editor. They are excluded from production builds and do not affect your published website or exported web components.
:::

## Switching scenarios

The scenario selector appears on the left side of the canvas top bar, displaying the name of the active scenario or **No scenario** when none is active.

![The Nordcraft editor with the scenario dropdown open in the canvas top bar, showing available scenarios and the Edit scenarios action.|16/9](scenarios-menu.webp 'Scenario dropdown'){https://editor.nordcraft.com/projects/docs_examples/branches/main/components/screenshot-card-container?mode=design&canvas-tool=select&canvas-width=800&canvas-height=800}

1. Click the scenario dropdown in the canvas top bar
2. Select a scenario from the list to apply it immediately to the canvas

Scenarios are listed alphabetically, and the default scenario is marked with a **Default** badge. When you select a scenario, Nordcraft adds a `test-scenario` query parameter to the editor URL so reloading the page or sharing the link opens the same scenario.

## Creating and managing scenarios

### Creating your first scenario

1. Open the scenario dropdown in the canvas top bar
2. Click [kbd]New scenario[kbd]

Nordcraft creates **Scenario 1**, marks it as the **Default** scenario, fills it with the current live values from the canvas (attributes, variables, and for pages, path and query parameters), applies it, and opens the **Edit scenarios** dialog.

### Opening the scenario editor

When a component or page already has at least one scenario, open the scenario dropdown in the canvas top bar and click [kbd]Edit scenarios[kbd] to open the draggable **Edit scenarios** dialog.

![The Edit scenarios dialog open in the Nordcraft editor, showing the scenario list on the left and override sections on the right.|16/9](scenario-editor.webp 'Edit scenarios dialog'){https://editor.nordcraft.com/projects/docs_examples/branches/main/components/screenshot-card-container?mode=design&canvas-tool=select&selection=testScenarios&canvas-width=800&canvas-height=800}

The dialog has two areas:

- **Left panel (Scenarios)**: Lists every scenario on the component or page and lets you add, switch, rename, duplicate, or delete scenarios
- **Main panel**: Displays the toolbar and override sections for the currently selected scenario

Changes you make in the **Edit scenarios** dialog save directly to the component or page and update the canvas immediately.

### Managing scenarios in the list

- **Add a scenario**: Click the [kbd]+[kbd] button in the **Scenarios** header to create a new empty scenario and apply it to the canvas
- **Select a scenario**: Click any scenario in the list to switch to it on the canvas
- **Rename a scenario**: Click an already-selected scenario, press [kbd]Enter[kbd], or right-click and choose **Rename**. Press [kbd]Enter[kbd] to confirm or [kbd]Escape[kbd] to cancel. Scenario names must be unique within the component or page.
- **Make default**: Right-click a scenario and select **Make default** to apply it automatically whenever you open the component or page
- **Duplicate a scenario**: Right-click a scenario and select **Duplicate** to copy its overrides into a new scenario
- **Delete a scenario**: Right-click a scenario and select **Delete**, or press [kbd]Backspace[kbd] or [kbd]Delete[kbd] while the scenario row is focused. If you delete the default scenario while other scenarios exist, the first remaining scenario alphabetically becomes the new default.

### Quick toolbar actions

At the top of the main panel, two actions let you populate or reset the selected scenario quickly:

- [kbd]Use current values[kbd]: Captures the current live values from the canvas for attributes, variables, and (for pages) path and query parameters, while keeping existing API and context overrides unchanged
- [kbd]Delete all[kbd]: Removes all custom overrides from the selected scenario while keeping its default status

## Overriding data in a scenario

Scenarios use partial overrides. You only need to add overrides for the specific items that matter for a scenario - any attribute, variable, or URL parameter you leave out keeps its regular test value or initial value.

Each override section appears only when the component or page defines items of that type. Click the [kbd]+[kbd] button in a section header to add an override, or click the [kbd]-[kbd] button next to an item to remove its override and return to the default value.

For attributes, URL parameters, variables, and API fields, you can enter strings, numbers, booleans, `null`, or JSON objects and arrays (starting with `{` or `[`), or use the type selector next to the input (`String`, `Number`, `Boolean`, `Null`).

### Attributes

Available on **components only**. Override any [component attribute](/components/interface-and-lifecycle#defining-attributes) to preview different inputs without editing the attribute's base test value.

### Path and query parameters

Available on **pages only**. Override dynamic **Path parameters** and **Query parameters** defined in the page's [route configuration](/pages/static-and-dynamic) to test how the page renders for different URLs.

### Variables

Available on **components and pages**. Override the initial value of any [variable](/variables/overview) to jump straight into a specific UI state, such as an open modal, an active tab, or a validation error.

### APIs

Available on **components and pages**. Override the state of any [API](/connecting-data/working-with-apis) without making a live network request:

- **Loading**: Toggle the [kbd]Loading[kbd] switch to simulate an in-flight request (`isLoading`)
- **Data / Error**: Choose between [kbd]Data[kbd] and [kbd]Error[kbd] to provide a mock response payload or a mock error payload
- **Response details**: Click the [kbd]+[kbd] button next to **Response details** to override HTTP response metadata:
  - `status`: Mock HTTP status code (such as `200`, `404`, or `500`)
  - `headers`: Mock HTTP response headers as a JSON object
  - `performance`: Mock request timing values (`requestStart`, `responseStart`, `responseEnd`)
  - `debug`: Optional debug payload for the API response

::: warning
Do not store sensitive data, such as access tokens, API keys, passwords, or real user data, in API response overrides. Scenario data is saved in your project files and is visible to everyone with access to the project (and publicly in public projects). Always use mock or anonymized placeholder data instead.
:::

### Contexts

Available on **components and pages** that subscribe to one or more [context providers](/contexts/overview). A context override replaces the data received from a provider with one of the scenarios defined on that provider component.

Only subscribed context providers that define at least one scenario appear in the [kbd]+[kbd] menu. After adding a provider, choose which of its scenarios to apply from the dropdown.

::: tip
If a context provider has a **Default** scenario, consumer components automatically use that provider scenario in the editor unless you select a different scenario in the consumer's **Contexts** section.
:::

## Default scenarios

Each component or page can have one **Default** scenario:

- The first scenario you create on a component or page is marked as **Default** automatically
- When you open a component or page without a `test-scenario` URL parameter, its default scenario is applied automatically on the canvas
- When another component subscribes to this component as a context provider, the default scenario provides its preview data unless overridden

## Validating scenarios

The [issues panel](/the-editor/issues-panel) automatically checks your scenarios for stale or invalid references, including:

- Overrides referencing an attribute, variable, API, path parameter, or query parameter that was renamed or deleted
- Context overrides referencing a provider the component is no longer subscribed to, or a provider scenario that no longer exists
- Multiple scenarios marked as default on the same component or page

Each scenario issue includes an auto-fix to remove the invalid reference. See [Scenarios issue rules](/references/issue-rules#scenarios) for the full list of checks.

To customize the visual backdrop around your component on the canvas, see [canvas styles](/the-editor/canvas-styles).
