Permission Matrix

Pro

Roles × capabilities, each cell Allow, Deny or Inherit. A role can extend another, and a grant on a capability group covers what is inside it, so an Inherit cell shows the value it ends up with and where from ("via Viewer", "via Billing") — dashed rather than solid, and said in words. Group rows roll up All / None / "2 of 4" through the kit's tri-state ancestry and toggle everything inside them, never a locked cell; locks on a role, a capability or one cell carry their reason. It is a WAI-ARIA treegrid (a grid when no capability nests) with one tab stop, a sticky header row and first column in a named scroll region, row and column bulk actions, search, and a draft: changed cells are marked, a summary lists each change with Revert, and Save / Discard hand the decision to the host, which owns persistence.

</>sv-permission-matrix permissionsrolesrbacaccess controlmatrixgridinheritancetri-stateadminsecuritysettings

Complexity tier: Application The interactive bar, plus a stated data-volume ceiling, a persistence contract, a bundle budget and an accessible parity surface.

Dataset size: up to 300 visible capability rows recommended, 2,000 maximum. Every visible row is rendered for every role, so 300 rows × a handful of roles stays light; up to the shared ceiling (`SV_UNVIRTUALIZED_ROW_CEILING`, 2,000 rows) still works with groups collapsed through `collapsedIds` or narrowed by `query`, and a dev-mode warning fires past it — split a larger catalogue by product area.

import { SvPermissionMatrixComponent } from '@styloviz-pro/display/permission-matrix';

Demo & usage

Basic usage

Pro

Usage example — open the gallery for the full interactive demo.

Pro

An interactive demo for this component lives in the gallery.

Open live demo

More examples

Roles that extend roles

Pro

An Inherit cell takes, in order: a grant on an enclosing group on the same role, then the role it `inherits`, all the way up, then `defaultEffect` (deny). A cycle stops at the first repeat.

Saving the draft

Pro

`save` carries the `changes` (role, capability, before → after, the effect each way) and the `grants` they produce. Persist either, then pass the saved grants back: the draft clears itself. A refused save keeps it — show the reason with `saveError`.

Locks with reasons

Pro

A role lock covers its column, a capability lock (on the row or in `locks`) covers the row and everything inside it, and a lock naming both covers one cell. `readonly` locks everything.

The rules without the component

Pro

The resolver, the group roll-up and the change list are exported — for a server that enforces the same rules, a test, or a digest e-mail.

When to use

  • A roles & permissions settings page: which role may do what, with roles that build on each other.
  • Reviewing access before an audit, read-only, with the reason every locked cell is locked.
  • Use the Tree View checkbox variant for one set of choices, and Data Table for a list of records with per-row actions.

Compare with

  • Tree View / Table — Tree View's checkbox variant ticks one set of nodes. Permission Matrix asks the same all / none / mixed question once per role — through the same tri-state helpers in `@styloviz/core` — and adds a third value, Inherit, with role inheritance, locks and a draft to save.
  • Data Table — Data Table lists records with sorting, paging and per-row actions. Permission Matrix is a fixed grid of roles × capabilities whose every cell is an allow / deny / inherit decision, with grouped rows and a save step.

Async states

  • loading
  • error
  • retry

Item identity & owned state

Item key
itemKey — set this when your rows have no id, so selection survives a reorder.
Restorable state
  • collapsedIds

Bind these to put a saved view back — the open sections, the hidden columns, the selected rows — and read their Change events to store what the user does.

Inputs

NameTypeDefaultDescription
capabilitiesreadonly SvPermissionCapability[][]The rows: capabilities, grouped by nesting `children`. Rows without a `label` are skipped.
rolesreadonly SvPermissionRole[][]The columns, in order. A role may `inherits` another by id.
grantsSvPermissionGrants{}The saved grants, `grants[roleId][capabilityId]` = `'allow'` | `'deny'`; a missing cell inherits. A grant on a group id applies to every capability inside it that inherits. Edits are kept as a draft on top of this until the host saves and passes the new value back.
itemKeySvItemKey<SvPermissionCapability>'id'Identity of a capability, a property name or a function — the key used in `grants`.
locksreadonly SvPermissionLock[][]Read-only rules: a role, a capability (with everything inside it), or one cell, each with its reason.
readonlybooleanfalseMake every cell read-only — e.g. for a viewer without the right to change roles.
defaultEffectSvPermissionEffect'deny'What a cell comes to when nothing in its chain sets it.
loadingbooleanfalseTrue while the first request is in flight — keep it false on a background refresh.
errorSvDataError | string | nullnullThe load failed. A string or an `SvDataError`; a non-retryable error hides the retry button.
filteredbooleanfalseSomething outside this component narrowed `capabilities`, so an empty matrix says "No matching capabilities".
savingbooleanfalseThe host is persisting a `save`: the buttons wait and cells stay put.
saveErrorSvDataError | string | nullnullThe last save failed — shown as an alert above the changes, which stay so the user can try again.
querystring (two-way)''The capability search text. Two-way bindable, so a host can restore it.
collapsedIdsreadonly string[] (two-way)[]Keys of the collapsed groups. Two-way bindable. A search shows every match regardless.
headingstring''The title. `''` uses the "Permissions" label.
headingLevelSvPermissionMatrixHeadingLevel2Heading level of the title — match your page outline.
maxHeightstring'36rem'Tallest the grid grows before it scrolls under its sticky header row (any CSS length; `'none'` to grow with the rows).
showSearchbooleantrueShow the search box and the "changed only" filter.
localestringsvLocale()BCP-47 locale for counts and plurals.
labelsPartial<SvPermissionMatrixLabels>{}Per-instance text, merged over the registry's `displayPro` labels.

Outputs

EventPayload typeDescription
retryvoidThe error state's retry button was pressed — re-run the request.
saveSvPermissionSaveEventSave was pressed. Persist `changes` (or `grants`), then pass the saved grants back in.
discardvoidDiscard was pressed: the draft is gone and the saved grants show again.
draftChangereadonly SvPermissionChange[]The draft changed — every unsaved edit, e.g. for a "leave without saving?" guard.
queryChangestringEmits the new `query` whenever it changes — the output half of `[(query)]`.
collapsedIdsChangereadonly string[]Emits the new `collapsedIds` whenever it changes — the output half of `[(collapsedIds)]`.

Wire it to your API

This component is headless about transport: it renders what you give it and reports what the user asks for. Nothing below requires @styloviz/data — drive it from whatever you already use.

Template

Pro

Bound to the names this component actually exposes.

Host class

Pro

Drive the three async inputs from your own fetch.

  • `queryChange` carries `string`, not an `SvDataQuery`, so `@styloviz/data`'s controller cannot take it as it is. The handler above keeps the latest one and fetches with it — map it to whatever your endpoint expects.
  • Set `filtered` when a search or filter is active. It is the difference between "you have no orders" and "no orders match this filter" — telling a customer with 4,000 orders the first one reads as a bug.
  • Normalize failures with `toSvDataError()` from `@styloviz/core`. It derives `retryable` from the status, so a 404 does not get a "Try again" button that can only fail again.

Full walkthrough: Connecting to a backend.

Customization & theming

  • Values: `allow` / `deny` in `grants`, absent = inherit; `defaultEffect` decides what an unset chain comes to.
  • Colours: allow paints `accent`, deny `danger`, mixed groups and unsaved cells `warning` — always with a shape (check, ban, minus, dashed outline, pencil) and a word, so the theme can remap them freely.
  • `maxHeight` sets where the grid starts to scroll under its sticky header row (`'none'` grows with the rows); the first column sticks on horizontal scroll. Logical properties throughout, so it mirrors in RTL.
  • `showSearch` hides the search box and the "Changed only" filter; `headingLevel` fits the page outline.
  • Every string comes from the `displayPro` labels (`perm*` keys) in 12 language packs, or the per-instance `labels` input.
  • `svResolvePermission`, `svResolvePermissionTable`, `svPermissionGroupStates`, `svPermissionGroupToggle`, `svPermissionChanges` and `svPermissionSearch` are exported.

Best practices

  • Do: Model roles that build on each other with `inherits` instead of copying grants. A change to the base role then flows into every role above it, and each cell says where its value came from.
  • Do: Give every lock a reason a user can act on ("Managed by your payment provider"), not "Locked".
  • Do: Enforce the same rules on the server — the exported resolver is the one the grid uses. The matrix is a way to edit permissions, not the place they are checked.
  • Don't: Don't persist from `draftChange`; it fires on every edit. Persist on `save`, and use `draftChange` for a "leave without saving?" guard.
  • Don't: Don't set `loading` after a save. Pass the saved grants back instead — the draft clears and the grid stays where the user was.
  • Tip: Bind `[(query)]` and `[(collapsedIds)]` to the URL so a link opens the same rows.

Accessibility

  • A WAI-ARIA grid built on the kit's own primitives (`@angular/aria` is not a dependency in 2.0, as with the import wizard): `role="treegrid"` when capabilities nest — group rows carry `aria-level` and `aria-expanded`, which ARIA allows only on treegrid rows — and `role="grid"` when the list is flat, with `aria-rowcount` / `aria-colcount`, a `columnheader` per role and a `rowheader` per capability, so every cell is announced with both. One tab stop; arrows, Home / End, Ctrl+Home / Ctrl+End and PageUp / PageDown (through the shared `svCollectionTarget`) move it, mirrored in RTL.
  • Space or Enter cycles a cell (Inherit → Allow → Deny); A, D and I set it and Delete resets it. On a group row Space allows or denies everything reachable inside it; on a row header it expands or collapses the group (`aria-expanded` on the row). The keys are described to the grid with `aria-describedby`.
  • Each cell says what it is in words — "Editor, View projects: allowed. Inherited from Viewer." — and the strip under the grid repeats it for the active cell, visibly. Inherited cells are dashed and carry "via …" text; locked cells are `aria-readonly` with a lock glyph and their reason; unsaved cells have a pencil. Never colour alone.
  • The grid scrolls inside a named, focusable region; sticky headers are marked `data-sv-sticky` and the region uses `svRevealFocus`, so a focused cell is never hidden under them (WCAG 2.4.11). Targets are at least 32px tall.
  • Bulk actions are buttons whose names say exactly what they do ("Allow Delete projects for every role"); a bulk change is announced in a polite status. A failed save is a `role="alert"`. Loading, error and both empties use the kit's shells.
  • Prints the whole grid without its controls: the scroll region grows, the sticky headers become static, and the cells keep their words.

Feedback on Permission Matrix

Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.

Loads giscus.app and GitHub — nothing is fetched until you click.