Matrix
A matrix choice with rows as sub-questions and columns as options: mode="radio" (default) selects one option per row, mode="checkbox" allows multiple. The value is a JSON object — { rowKey: columnKey } for radio and { rowKey: [columnKey] } for checkbox.
Basic usage (radio)
Click any cell to select. Both row headers and column headers are part of each control's accessible name.
Satisfaction matrix
Checkbox mode
Each row accepts multiple options. required-scope="table" means at least one row must be answered.
mode="checkbox"
Required validation (survey scenario)
required defaults to row-level validation (every row must be answered). Clicking "Submit survey" calls validate(): failures show an error and dispatch oas-invalid; answering later re-checks silently and clears the error once complete.
Row-level required + validate()
Disabled and readonly
disabled blocks all interaction; readonly keeps the normal appearance and selections but ignores interaction and keeps the value unchanged.
disabled / readonly
Inside oas-form (generic form scenario)
A matrix is registered in the oas-form collection chain (the value channel; the form value is a JSON string), so a named matrix submits with the form and participates in initial-values / reset. The example below validates the matrix itself and merges its value — per-row required errors only show after validate().
Matrix inside a form
Keyboard and accessibility
- Each row is a
fieldsetwith alegendrow header; options are nativeinput[type=radio|checkbox]whose accessible name combines the row header and column header - Radio rows use roving tabindex (one tab stop per row); arrow keys move and select within a row, Home / End jump to the first / last column, and left/right mirror under RTL
- Required hints and error text are linked with
aria-describedby; invalid options carryaria-invalid
Validation semantics
requiredmakes the question required;required-scope="row"(default) requires every row,required-scope="table"requires at least one answered rowvalidate()returns whether it passed; failures show the error and dispatchoas-invalid(detail: { reason, scope, missingRows, value })- Disabled rows and rows where every column is disabled are excluded from required checks
API
oas-matrix
Attributes
| Attribute | Description | Type | Default |
|---|---|---|---|
columns | Options (columns) as a JSON array, same shape as rows | MatrixColumn[] | string | — |
disabled | Disable every row and column (per-row / per-column disabled still applies) | boolean | — |
label | Question text (rendered as a caption and used as the group accessible name) | string | — |
mode | In-row selection mode: radio (default) or checkbox; invalid values fall back to radio with a warning | string | radio |
readonly | Readonly: keeps the appearance and selections but ignores interaction | boolean | — |
required | Required: combined with required-scope for row-level or table-level semantics | boolean | — |
required-scope | Required scope: row every row (default) / table at least one answered row | string | row |
rows | Sub-questions (rows) as a JSON array [{ key, label?, disabled? }]; string items collapse to key=label | MatrixRow[] | string | — |
value | Value JSON object: radio { rowKey: columnKey } / checkbox { rowKey: [columnKey] } (written back on user interaction) | MatrixValue | string | — |
Property (JS property; see each row for attribute reflection)
| Property | Description | Type | Default |
|---|---|---|---|
columns | Option (column) list: get+set channel (array or JSON string); assignment applies immediately without events | MatrixColumn[] | string | — |
rows | Row (sub-question) list: get+set channel (array or JSON string); assignment applies immediately without events | MatrixRow[] | string | — |
value | Current value: get+set channel (object or JSON string); assignment applies immediately without events | MatrixValue | string | — |
Methods
| Method | Signature | Description |
|---|---|---|
validate | validate(): boolean | Validate the required semantics and sync the visible error; returns whether it passed (dispatches oas-invalid on failure) |
clear | clear(): void | Clear all selections (dispatches oas-change) |
Events
| Event | Description |
|---|---|
oas-change | Dispatched when the user changes a selection, detail: { value, rowKey, columnKey, checked } |
oas-invalid | Dispatched when validate() fails, detail: { reason, scope, missingRows, value } |
CSS Variables
| CSS Variable | Description | Default |
|---|---|---|
--oas-matrix-label-width | Row label column width (default 34%) | 34% |