Skip to content

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

Not answered yet

Checkbox mode ​

Each row accepts multiple options. required-scope="table" means at least one row must be answered.

mode="checkbox"

Select at least one option

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()

Submit survey

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

Submit form

Keyboard and accessibility ​

  • Each row is a fieldset with a legend row header; options are native input[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 carry aria-invalid

Validation semantics ​

  • required makes the question required; required-scope="row" (default) requires every row, required-scope="table" requires at least one answered row
  • validate() returns whether it passed; failures show the error and dispatch oas-invalid (detail: { reason, scope, missingRows, value })
  • Disabled rows and rows where every column is disabled are excluded from required checks

API ​

oas-matrix ​

Attributes ​

AttributeDescriptionTypeDefault
columnsOptions (columns) as a JSON array, same shape as rowsMatrixColumn[] | string—
disabledDisable every row and column (per-row / per-column disabled still applies)boolean—
labelQuestion text (rendered as a caption and used as the group accessible name)string—
modeIn-row selection mode: radio (default) or checkbox; invalid values fall back to radio with a warningstringradio
readonlyReadonly: keeps the appearance and selections but ignores interactionboolean—
requiredRequired: combined with required-scope for row-level or table-level semanticsboolean—
required-scopeRequired scope: row every row (default) / table at least one answered rowstringrow
rowsSub-questions (rows) as a JSON array [{ key, label?, disabled? }]; string items collapse to key=labelMatrixRow[] | string—
valueValue JSON object: radio { rowKey: columnKey } / checkbox { rowKey: [columnKey] } (written back on user interaction)MatrixValue | string—

Property (JS property; see each row for attribute reflection) ​

PropertyDescriptionTypeDefault
columnsOption (column) list: get+set channel (array or JSON string); assignment applies immediately without eventsMatrixColumn[] | string—
rowsRow (sub-question) list: get+set channel (array or JSON string); assignment applies immediately without eventsMatrixRow[] | string—
valueCurrent value: get+set channel (object or JSON string); assignment applies immediately without eventsMatrixValue | string—

Methods ​

MethodSignatureDescription
validatevalidate(): booleanValidate the required semantics and sync the visible error; returns whether it passed (dispatches oas-invalid on failure)
clearclear(): voidClear all selections (dispatches oas-change)

Events ​

EventDescription
oas-changeDispatched when the user changes a selection, detail: { value, rowKey, columnKey, checked }
oas-invalidDispatched when validate() fails, detail: { reason, scope, missingRows, value }

CSS Variables ​

CSS VariableDescriptionDefault
--oas-matrix-label-widthRow label column width (default 34%)34%

Released under the MIT OR Apache-2.0 License.