Choice Matrix
Rows × columns of checkboxes or radio buttons in one form control: permissions, notification settings, agreement scales.
c2-choice-matrix is the grid of choices behind a permissions page (resources × read, write, admin, as in GitHub and Okta), notification settings (events × email, push, SMS) or a survey’s agreement scale. With checkboxes a row takes any number of columns; with radio buttons exactly one. Tri-state toggles check or clear a whole row, a whole column, or a column within a group of rows.
Import
import '@c2n/components/choice-matrix'Usage
| Resource | Read | Write | Admin | |
|---|---|---|---|---|
| Repository | ||||
| Code | ||||
| Issues | ||||
| Pull requests | ||||
| Organization | ||||
| Members Invite and remove people | ||||
| Billing Invoices and plan |
| Event | Push | SMS | |
|---|---|---|---|
| Someone mentions you | |||
| A review is requested | |||
| A deploy fails |
| Disagree | Neutral | Agree | |
|---|---|---|---|
| The docs are clear | |||
| Setup was easy |
Rows, columns and value
rows and columns are arrays (or JSON attributes) of { value, label }; a row may add a description and a group, and either may be disabled. value maps each row’s value to the checked columns’ values, {"issues":["read","write"]}, or to the one chosen column with type="radio", {"docs":"3"}. input and change fire when the user changes a choice, change with the new value in detail.value.
Toggles and groups
toggles="rows" puts a tri-state checkbox at the start of each row, "columns" one under each column title (and in each group’s header row), "both" both. A toggle is checked when all its choices are, mixed when some are; pressing it checks them all, or clears them all when all were checked. Disabled rows and columns keep their choices and are skipped. Radio matrices have no toggles.
In a form
Under a name, the form receives one name[row]=column entry per choice, as a server expects from checkboxes named permissions[issues]. required asks for at least one choice, or for every row to be answered with type="radio". Inside a c2-form-field the field’s label names the matrix and its hint and error describe it.
Accessibility
The matrix is a group named by label holding a table: each choice is named by its row and its column, so a screen reader reads both as you move. A radio row is one stop in the tab order, and the arrow keys move along it. On a narrow screen the table scrolls sideways with the row titles held in place.