ChoiceCards
A visual card picker for choosing one or multiple options from a compact set.
import { ChoiceCards } from "@schukai/monster/source/components/form/choice-cards.mjs";Introduction
The Monster ChoiceCards component is a single-choice control that presents options as compact cards instead of a dropdown. Use it when the choices are few, visible at once and important enough to compare before selecting.
When to use ChoiceCards
- Use it for visible single-choice decisions: Shipping method, billing cadence, account type or plan tier choices are good fits.
- Use it when labels need more context: The
contentSlotitem field lets each card show richer content while keeping the submitted value explicit. - Do not use it for large option sets: For long lists, filtering, remote lookup or multi-select, use Select instead.
Item model
Each item is normalized into an object with a stable value and label. Strings and numbers are accepted as shortcuts, but object items are clearer for production code.
choiceCards.setItems([
{value: "standard", label: "Standard"},
{value: "express", label: "Express", contentSlot: "express-card"},
{value: "pickup", label: "Pickup", disabled: true}
]);Events
User selection emits the native change event followed by monster-selected, monster-change and monster-changed. The custom event detail contains the selected value and the normalized item.
Typical mistakes
Do not treat card text as the submitted value by accident. Keep value stable and use label or slotted content for human-readable copy. If the component is configured from JavaScript, wait for customElements.whenDefined("monster-choice-cards") before calling public methods.
Simple Card Choices
This example configures monster-choice-cards with object items, custom card slots and a stable submitted value. The status text is updated from the documented monster-change event detail.
Selected value: pickup
Selected value: pickup
Javascript
import "@schukai/monster/source/components/form/choice-cards.mjs";
await customElements.whenDefined("monster-choice-cards");
const choiceCards = document.getElementById("fulfillment-choice");
const status = document.getElementById("fulfillment-choice-status");
choiceCards.setItems([
{
value: "delivery",
label: "Delivery",
contentSlot: "delivery-card",
},
{
value: "pickup",
label: "Pickup",
contentSlot: "pickup-card",
},
{
value: "hold",
label: "Hold",
contentSlot: "hold-card",
},
]);
choiceCards.addEventListener("monster-change", (event) => {
status.textContent = "Selected value: " + event.detail.value;
});HTML
<section class="choice-cards-example">
<monster-choice-cards id="fulfillment-choice" value="pickup">
<span class="choice-card-content" slot="delivery-card">
<strong>Delivery</strong>
<small>Send the order to the customer address.</small>
</span>
<span class="choice-card-content" slot="pickup-card">
<strong>Pickup</strong>
<small>Reserve the order for collection today.</small>
</span>
<span class="choice-card-content" slot="hold-card">
<strong>Hold</strong>
<small>Keep the order in review until stock is confirmed.</small>
</span>
</monster-choice-cards>
<p id="fulfillment-choice-status" class="choice-cards-status">
Selected value: pickup
</p>
</section>Stylesheet
.choice-cards-example {
display: grid;
gap: var(--monster-space-4);
}
.choice-cards-example monster-choice-cards {
--monster-choice-cards-card-width: 12rem;
--monster-choice-cards-gap: var(--monster-space-3);
}
.choice-card-content {
display: grid;
gap: var(--monster-space-2);
}
.choice-card-content small {
color: var(--monster-color-primary-1);
line-height: 1.35;
}
.choice-cards-status {
color: var(--monster-color-primary-1);
margin: 0;
}Component Design
ChoiceCards renders a form-associated radio-card group in Shadow DOM. The host owns focus handling, keyboard selection and form value synchronization while the page supplies options through documented item data.
Public styling surface
Style the component through Monster tokens, component custom properties and documented parts. Do not depend on internal button or indicator nodes.
Available Part Attributes
control: The radiogroup container.items: The flex container that receives the generated choice buttons.
Useful custom properties
--monster-choice-cards-gap: Space between cards.--monster-choice-cards-card-width: Preferred card width.--monster-choice-cards-min-height: Minimum card height.
monster-choice-cards {
--monster-choice-cards-card-width: 12rem;
--monster-choice-cards-gap: var(--monster-space-4);
}
monster-choice-cards::part(items) {
align-items: stretch;
}Accessibility
The component exposes a radio group, keeps the current value synchronized and supports keyboard selection. Use labels.group when the surrounding page does not already provide enough context for the choice group.
HTML Structure
<monster-choice-cards></monster-choice-cards>JavaScript Initialization
const element = document.createElement('monster-choice-cards');
document.body.appendChild(element);Exported
ChoiceCardsDerived from
CustomControlOptions
The Options listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class. Therefore, it inherits Options from these parent classes. If you cannot find a specific Options in this list, we recommend consulting the documentation of the CustomControl.
- since
- deprecated
Properties and Attributes
The Properties and Attributes listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits Properties and Attributes from these parent classes. If you cannot find a specific Properties and Attributes in this list, we recommend consulting the documentation of the CustomControl.
data-monster-options: Sets the configuration options for the collapse component when used as an HTML attribute.data-monster-option-[name]: Sets the value of the configuration option[name]for the collapse component when used as an HTML attribute.
Methods
The methods listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits methods from these parent classes. If you cannot find a specific method in this list, we recommend consulting the documentation of the CustomControl.
State query methods
value()- {string|null|Array
}
value(value)value{string|array<string>|null|undefined}: value
Structural methods
getItems()- {Array}
setItems(items)items{array}: items
- {ChoiceCards}
Static methods
[instanceSymbol]()- {symbol}
instanceof operator.getCSSStyleSheet()- {CSSStyleSheet[]}
getTag()- {string}
Lifecycle methods
Lifecycle methods are called by the environment and are usually not intended to be called directly.
[assembleMethodSymbol]()- {void}
Other methods
select(value)value{string|null|undefined}: value
- {ChoiceCards}
Events
The component emits the following events:
monster-selectedmonster-changemonster-changed
For more information on how to handle events, see the mdn documentation.