Choice Matrix
Rows × columns of checkboxes or radio buttons in one form control: permissions, notification settings, agreement scales.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
rows | ChoiceMatrixRow[] | [] | The rows. As an attribute, a JSON array of { value, label, description, group, disabled }. |
columns | ChoiceMatrixColumn[] | [] | The columns. As an attribute, a JSON array of { value, label, disabled }. |
value | ChoiceMatrixValue | {} | The choices, by row value. As an attribute, JSON: {"issues":["read","write"]}, or {"q1":"agree"} for radio rows. |
type | 'checkbox' | 'radio' | checkbox | Any number of columns per row, or exactly one. |
toggles | 'none' | 'rows' | 'columns' | 'both' | none | Tri-state checkboxes that check or clear a whole row, a whole column (and a column within each group), or both. Checkbox matrices only. |
name | string | — | Form field name: the form receives name[row]=column for each choice. |
required | boolean | false | Asks for at least one choice, or for every row to be answered with type="radio". |
disabled | boolean | false | Turns every choice and toggle off; the value is kept and, as for a disabled form control, not submitted. |
row-header | string | — | The title above the row labels. |
label | string | — | The accessible name of the matrix. Inside a c2-form-field, the field's label names it. |
Events
| Name | Type | Description |
|---|---|---|
input | Event | Fired when the user changes a choice, before change. Read value. |
change | CustomEvent<{ value: ChoiceMatrixValue }> | Fired after the user changes a choice. detail.value is the new value. Not fired for programmatic changes. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
table | The table. |
column-header | A column's title cell. |
row-header | A row's title cell, holding its label and description. |
description | A row's description. |
group-header | The header row of a group. |
cell | The cell of one choice. |
control | A checkbox or radio button, the toggles included. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-choice-matrix--background-color | color | #ffffff | Behind the table, and behind the first column while it is held during a sideways scroll. |
--c2-choice-matrix__cell--padding | padding | 10px 12px | |
--c2-choice-matrix__row--border-bottom | border | 1px solid #e4e4e7 | |
--c2-choice-matrix__row__hover--background-color | color | #fafafa | |
--c2-choice-matrix__column-header--color | color | #71717a | |
--c2-choice-matrix__column-header--font-size | font-size | 12px | |
--c2-choice-matrix__column-header--font-weight | font-weight | 500 | |
--c2-choice-matrix__row-header--color | color | #18181b | |
--c2-choice-matrix__row-header--font-size | font-size | 14px | |
--c2-choice-matrix__row-header--font-weight | font-weight | 400 | |
--c2-choice-matrix__description--color | color | #71717a | |
--c2-choice-matrix__description--font-size | font-size | 12px | |
--c2-choice-matrix__group-header--background-color | color | #f4f4f5 | |
--c2-choice-matrix__group-header--color | color | #18181b | |
--c2-choice-matrix__group-header--font-weight | font-weight | 600 | |
--c2-choice-matrix__control--size | pixel | 18px | |
--c2-choice-matrix__control--border | border | 1px solid #bcbcc6 | |
--c2-choice-matrix__control--border-radius | border-radius | 4px | A checkbox's corners; radio buttons are round. |
--c2-choice-matrix__control--background-color | color | #ffffff | |
--c2-choice-matrix__control__hover--border-color | color | #a1a1aa | |
--c2-choice-matrix__control__selected--background-color | color | #476ef9 | A checked checkbox or a chosen radio button. |
--c2-choice-matrix__control__selected--mark-color | color | #ffffff | The check, the dash and the dot drawn on a selected control. |
--c2-choice-matrix__control__error--border-color | color | #dc2626 | |
--c2-choice-matrix__control__focus--outline | outline | 2px solid rgba(71, 110, 249, 0.4) | |
--c2-choice-matrix__control__disabled--opacity | opacity | 0.38 | |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under choice-matrix, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
label | Choices | — |
toggleRow | All of {0} | {0} row |
toggleColumn | {0} for all | {0} column |
toggleGroup | {0} for {1} | {0} column {1} group |
rowsMissing | Please answer every row. | — |
valueMissing | Please select at least one option. | — |