Ga naar hoofdinhoud

CnChoiceCards

Pick one option, or several, from a grid of cards instead of a dropdown. Use it where the choice needs explaining: a setup wizard asking which example dataset to load, an onboarding template picker, a plan chooser. Use NcSelect where the label already says enough.

Each card is a <label> around a real <input type="radio">, or a checkbox when multiple is set. Keyboard navigation, the checked state and Windows high-contrast rendering are the browser's own, not a reimplementation, and the selection stays visible without relying on the highlight colour (WCAG 1.4.1).

The cards themselves are CnCard, so a card can carry a description, a few stats and an icon.

Usage​

<!-- One choice -->
<CnChoiceCards
v-model="picked"
label="Which kind of organisation is this for?"
:options="[
{ value: 'municipality', label: 'Municipality',
description: 'A council, its committees and a decision list.',
stats: [{ label: 'Objects', value: 170 }] },
{ value: 'association', label: 'Association or VvE',
description: 'A members meeting, motions and minutes.' },
{ value: 'none', label: 'None, I will set this up myself' },
]" />

<!-- Several, with a live list still loading -->
<CnChoiceCards
v-model="pickedSets"
:multiple="true"
:loading="loading"
:options="sets"
label="Load which example sets?" />

Options are tolerant about shape, so a list can be handed straight from a server: id is accepted for value and name for label.

Props​

PropTypeDefaultDescription
optionsArray[]The options to offer: { value, label, description?, stats?, tags?, icon? }. icon is a PascalCase MDI name resolved by CnIcon.
modelValueString | Number | Boolean | Array | ObjectnullThe selection. An array when multiple.
multipleBooleanfalseAllow several cards. Inputs become checkboxes and the model becomes an array.
labelString''Group label, rendered as the fieldset legend.
disabledBooleanfalseDisable every card, for example while a dependent choice has no parent value yet.
loadingBooleanfalseShow a spinner instead of the grid while the options are being fetched.
emptyTextString'Nothing to choose from here.'Shown when there are no options.
descriptionLinesNumber4Lines of description before clamping.

Events​

EventPayloadWhen
update:modelValuevalue, or an array of valuesA card is picked, or unpicked when multiple.

Slots​

SlotScopeDescription
option-actions{ option, selected }Content below one card, such as a Load button. It renders outside the card's <label>, so a click on a button there never toggles the card. The setup wizard uses it for loadAction.

Accessibility​

  • The grid is a <fieldset> with a <legend>, so a screen reader announces what the group is for before the first option.
  • Values are compared as strings, so a value that came back from a server as "1" still matches the 1 it was sent as.
  • Card titles render as <span>, not headings. Six choices are six choices, not six headings in the document outline.
  • CnCard renders each option.
  • CnSetupWizard uses this for a choice step that declares display: "cards".