Matrix field
Rows rated against the same columns: one radio (or box) per cell, named by its row and column.
import { MatrixField } from "@forgeron/ui";| Poor | Fair | Good | Great | |
|---|---|---|---|---|
| Speed | ||||
| Documentation | ||||
| Support |
import { MatrixField, type FormMatrixAnswer } from "@forgeron/ui";
import { useState } from "react";
const rows = [
{ id: "speed", label: "Speed" },
{ id: "docs", label: "Documentation" },
{ id: "support", label: "Support" },
];
const columns = [
{ id: "1", label: "Poor" },
{ id: "2", label: "Fair" },
{ id: "3", label: "Good" },
{ id: "4", label: "Great" },
];
export default function Default() {
const [value, setValue] = useState<FormMatrixAnswer>({ speed: "3" });
return (
<div style={{ width: 520, maxWidth: "100%" }}>
<MatrixField
label="How satisfied are you with each part?"
rows={rows}
columns={columns}
value={value}
onChange={setValue}
/>
</div>
);
}| Mon | Tue | Wed | Thu | Fri | |
|---|---|---|---|---|---|
| Early | |||||
| Late |
import { MatrixField } from "@forgeron/ui";
export default function Multiple() {
return (
<div style={{ width: 520, maxWidth: "100%" }}>
<MatrixField
label="Which days can you work each shift?"
multiple
rows={[
{ id: "early", label: "Early" },
{ id: "late", label: "Late" },
]}
columns={[
{ id: "mon", label: "Mon" },
{ id: "tue", label: "Tue" },
{ id: "wed", label: "Wed" },
{ id: "thu", label: "Thu" },
{ id: "fri", label: "Fri" },
]}
defaultValue={{ early: ["mon", "wed"] }}
/>
</div>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | Names the matrix for assistive technology: the question. |
rows / columns | { id, label }[] | — | What is rated, and the scale it is rated on. |
value / defaultValue | Record<rowId, columnId | columnId[]> | — | The chosen column of each row. Controlled or not. |
onChange | (value) => void | — | After every choice. |
multiple | boolean | false | Several columns may be chosen on a row. |
invalid / describedBy | boolean / string | — | Ties the matrix to its error. |
disabled | boolean | — | Locks the matrix. |
className | string | — | Extra classes. |