# Matrix question

A React block (a whole screen) in [Beamline](https://beamline.io/)'s [Research & design](https://beamline.io/components/apps/research-design) app. Live demo: https://beamline.io/components/matrix-question

A matrix question and the participant's side of it, side by side. Rows (up to ten) share one set of choices (two to seven); Enter adds a row, several pasted lines add several choices and lines that don't fit are counted; one or several answers per row, rows and choices shuffled apart (each participant keeps their own order), an opt-out with its own label, every row required or not, and a phone layout of a grid or one row at a time. Empty rows, too few choices and duplicate labels are said; published locks the structure while labels still edit. The preview answers it as a participant on a desktop grid or a phone: opt-out clears the row's other answers, answers are kept when the layout changes, progress fills as rows are answered and Continue waits for required rows.

## Use it for

- Writing a grid question where several statements share one scale, and seeing the participant's side as you write.
- Any survey builder that needs rows against shared choices on desktop and phone.

## Not for

- A single rating ([rating](https://beamline.io/components/rating)).
- Reading answers back ([data-grid](https://beamline.io/components/data-grid), [bar-chart](https://beamline.io/components/bar-chart)).

## Anatomy

- header: the product's mark and title; a lock note when published
- editor: the question, rows with their count, choices with their count and an add field, answers per row, phone layout, shuffling, required, opt-out and its label; problems
- preview: desktop or phone; the question, a progress bar per row, a grid with a column per choice (opt-out set apart) or one row at a time with Back and Next; Continue

## States

- rows: empty row said; ten at most (add off)
- choices: fewer than two said; seven at most (add off), pasted overflow counted (amber)
- duplicate labels said
- shuffled: said
- published: structure locked (blue note), labels open
- participant: unanswered, partial (progress), answered (Continue on), opt-out exclusive, several answers, recorded (green)
- phone: a grid that scrolls sideways or one row at a time
- right to left: the page mirrors

## Keyboard

- Enter in a row adds the next row; Enter in the add field adds a choice; Tab through fields and grid cells; Space picks a cell; arrows move between a row's radio cells

## Motion

Nothing moves; changes appear on input.

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `defaultValue` (required) | `MatrixDefinition` | — | Initial selection when uncontrolled; omitted by default. |
| `defaultAnswers` | `Record<string, string[]>` | — | Answers already given in the preview, by row id. |
| `defaultPreview` | `"desktop" \| "mobile"` | — |  |
| `published` | `boolean` | — | The study is published: structure is locked, labels aren't. |
| `seed` | `number` | — | Seeds the participant's shuffled order. |
| `onChange` | `((value: MatrixDefinition) => void)` | — |  |
| `product` | `string` | — | Your product's name, shown as its mark. |
| `className` | `string` | — | Classes on the documented visual root; no override by default. |
| `ref` | `Ref<HTMLDivElement>` | — | Receives the documented native target or imperative handle; omitted by default. |

## Built from

- [Avatar](https://beamline.io/components/avatar.md)
- [Button](https://beamline.io/components/button.md)
- [Checkbox](https://beamline.io/components/checkbox.md)
- [Input](https://beamline.io/components/input.md)
- [Label](https://beamline.io/components/label.md)
- [Radio group](https://beamline.io/components/radio-group.md)
- [Segmented control](https://beamline.io/components/segmented-control.md)
- [Select](https://beamline.io/components/select.md)
- [Spinner](https://beamline.io/components/spinner.md)
- [Switch](https://beamline.io/components/switch.md)
- [Text morph](https://beamline.io/components/text-morph.md)
- [Tooltip](https://beamline.io/components/tooltip.md)

## Import

```tsx
import { MatrixQuestion } from "@beamline/matrix-question";
```

## Get it

Matrix question is part of Beamline UI. Install the parts you need in your React app as compiled packages or editable source. [Get Beamline](https://beamline.io/checkout?pack=complete) · [Connect your agent](https://beamline.io/connect)

## More in Research & design

- [Research synthesis](https://beamline.io/components/research-synthesis): A research study turned into evidence in one place. Transcripts: passages marked as accepted highlights or as the assistant's suggestions (dashed)…
- [Study setup](https://beamline.io/components/study-setup): Set up an unmoderated test and its screener. Test: what's tested (a website, a prototype by its share link, an app by its store page), who takes it…
- [Study flow](https://beamline.io/components/study-flow): A study's blocks in order, each with where people go next. A block that routes by its answer (multiple choice, scale, open question, prototype task) has…
- [Participant review](https://beamline.io/components/participant-review): One participant's session, answer by answer, beside the list of everyone who took the study. The list filters (finished, left early, with a recording)…
- [Click heatmap](https://beamline.io/components/click-heatmap): One screen of a usability task as it looked (your prototype's frame or a page built from your parts, scaled into a phone) with where people clicked over…
- [Tree test](https://beamline.io/components/tree-test): A tree test: build a navigation tree and read where people went. Build: pages added at the top or under any page, indented under the page above or moved…
- [Prototype task](https://beamline.io/components/prototype-task): A prototype task in a study. The linked prototype refreshes from the design keeping the task and paths (a start screen gone from the new version said, a…
- [Task results](https://beamline.io/components/task-results): A usability task's results, from headline outcomes down to paths and screens. Outcomes (direct success, indirect success, gave up) say their share and…
- [Prototype review](https://beamline.io/components/prototype-review): Reviewing a design file's clickable prototype. Present: the board on a stage with its wireframe, the flow chosen (an unavailable one can't be), Back…
- [Report builder](https://beamline.io/components/report-builder): Build a chart from your metrics without code: choose metrics, how to group them over time, an optional breakdown, filters, the range and the chart, see…
- [Report library](https://beamline.io/components/report-library): A business's reports in one place. The directory: reports by topic and group with search, each with what it answers; one this person can't open says why…
- [Review page builder](https://beamline.io/components/review-page-builder): Building the page reviewers use to go through records one by one. The queue of records (one with no title shows its id instead of a blank); the record as…
- [Database builder](https://beamline.io/components/database-builder): What a database does for the people who use it, built in one place. Templates: starting values per property (a relation default points at an existing…
- [Workflow builder](https://beamline.io/components/workflow-builder): Automation rules for a SaaS without code: a trigger, conditions built with the query builder that branch into Yes and No, actions and waits, drawn as a…
- [Workflow library](https://beamline.io/components/workflow-library): The automation library: every automation as a row (what starts it, whether it's live, a draft or paused, who owns it, when it last ran, and its runs this…
- [Drawing board](https://beamline.io/components/drawing-board): A whiteboard a team already knows how to use, like FigJam: tools in a floating bar at the bottom (Select V, Hand H, Sticky note S, Shape R/O/D, Connector…
- [Model workbench](https://beamline.io/components/model-workbench): A CAD model's workbench around a large isometric scene of its bodies, each shaded from its material's appearance with a soft ground shadow and an axis…
- [Component properties](https://beamline.io/components/component-properties): A design system component from three sides. Its variants as a matrix on two chosen properties, the others filtering it, each cell drawing the variant; a…
- [Slot editor](https://beamline.io/components/slot-editor): Slots in a design system component, from making to filling. The main component's layer tree with a checkbox per layer: a nested frame converts to a slot…

Part of [Beamline UI: polished, editable React components and complete screens for custom applications](https://beamline.io/). [Build your own style from any look; tokens, fonts, radii, motion; not only colours](https://beamline.io/docs/customize).
