Permission matrix

Slant / Data

A readable or editable table of permissions, with native checkboxes.

Demo

Usage

@tuttn/slant
import { PermissionMatrix } from '@tuttn/slant'

<PermissionMatrix label="Contributor permissions"
  columns={[{ id: 'read', label: 'Read' }, { id: 'edit', label: 'Edit' }]}
  rows={rows}
  onPermissionChange={(rowId, columnId, allowed) => {
    setRows(current => current.map(row => row.id === rowId
      ? { ...row, grants: allowed ? [...row.grants, columnId]
        : row.grants.filter(id => id !== columnId) }
      : row))
  }}
/>

Props

PropTypeDefaultDescription
labelstring—A visible table caption.
columnsreadonly PermissionColumn[]—Permission actions, in display order.
rowsreadonly PermissionRow[]—Resources and the action ids allowed on each.
onPermissionChange(rowId: string, columnId: string, allowed: boolean) => void—Makes the matrix editable. Update rows yourself when a checkbox changes.
disabledbooleanfalseDisables editing without changing the displayed grants.

Accessibility

  • Checkbox names combine resource and action, and native Space toggles them.
  • Read-only cells announce Allowed or Not allowed. The table has a visible caption and scoped row/column headings.
  • The scroll region takes a tab stop only when its content overflows.

A native table keeps the resource and action headings connected. Supply onPermissionChange for controlled checkboxes; omit it for a readable permission summary. Each row can be locked with disabled.

This component displays the permissions you supply. Persist changes and enforce access in your application. On narrow screens the table scrolls inside its own keyboard-focusable area.