Sorry, but you either have no stories or none are selected somehow.
If the problem persists, check the browser console, or the terminal you've run Storybook from.
The component failed to render properly, likely due to a configuration issue in Storybook. Here are some common causes and how you can address them:
For a more specialized visualization of checkbox and radio elements.
There are various methods to integrate this component into your project.
We advise opting for the "Standard HTML" approach for when you need full access to the input field and using the "Web Component" method in every other case.
The card-control standard HTML will be renamed in a future version.
<div class="checkbox-button-card"> <input id="CardControl_1" name="checkbox-button-card-control_1" class="form-check-input" type="checkbox" /> <label class="form-check-label" for="CardControl_1"> <span>Label</span> </label> </div>
Checkbox cards can be grouped together. Use a fieldset/legend combination to label the group. If there is an error, link the legend with the error message through the aria-describedby attribute on the legend, pointing to the id of the error message.
Firefox currently does not support
the new CSS :has pseudo-selector
. As a fallback, the following states have to be mirrored on the top level element in the form of classes (see below for a snippet):
checkeddisabledis-invalidCheck caniuse :has() to check if you still need the fallback.
This snippet adds a global event listener to mirror the focused and checked states to the parent of the input. This fallback has to be applied as long as Firefox does not support the :has selector.
document.addEventListener('input', e => { if (!(e.target instanceof Element) || e.target.nodeName !== 'input') return; const parent = e.target.parentElement; if ( parent?.classList.contains('checkbox-button-card') || parent?.classList.contains('radio-button-card') ) { parent.classList.toggle('checked', (e.target as HTMLInputElement).checked); } });
Make sure the @swisspost/design-system-styles package is already present in your project
or follow the installation guidelines.
To import all Design System styles:
@use '@swisspost/design-system-styles/index.scss';
To import only the styles required for this component:
@use '@swisspost/design-system-styles/basics.scss'; @use '@swisspost/design-system-styles/components/choice-control-card.scss';
The card-control webcomponent is deprecated and will be removed in the next major version.
<post-card-control label="Label" type="checkbox"> </post-card-control>
| Name | Description | Default | Control |
|---|---|---|---|
| props | |||
| label* | Defines the text in the control-label. string | ||
| description | Defines the description in the control-label. string | null | |
| type* | Defines the type attribute of the control."checkbox""radio" | ||
| name | Defines the string | null | |
| value | Defines the value attribute of the control. This is a required property, when the control is used with type radio.string | null | |
| checked | Defines the checked attribute of the control. If true, the control is selected at its value will be included in the forms' data.boolean | false | |
| disabled | Defines the disabled attribute of the control. If true, the user can not interact with the control and the controls value will not be included in the forms' data.boolean | false | |
| validity | Defines the validation nullboolean | null | |
| icon | Defines the icon string | null | |
| slots | |||
| default | Content to place into the default slot.Markup accepted: block content.Even if it is generally possible, we do not recommend using interactive elements in this slot because the background of the card control is clickable. other | - | |
| icon | To insert a custom icon into the named icon slot.Markup accepted: inline content.It is only meant for other | - | |
| events | |||
| postInput | An event emitted whenever the components checked state is toggled.
The event payload (emitted under { state: boolean; value: string; } | - | - |
| postChange | An event emitted whenever the components checked state is toggled.
The event payload (emitted under { state: boolean; value: string; } | - | - |
| methods | |||
| reset | A public method to reset the controls reset() => Promise<void> | - | - |
The <post-card-control> element is part of the @swisspost/design-system-components package. For more information, read the
getting started with components guide.
You can use our built-in icons by just adding the icon property with the name of the desired icon.
If this is not enough, you can also use the named icon slot and add your very own custom icon.
width and height attributes from the img or svg tag. Otherwise we can not ensure, our styles will work properly.If you need to add other content to the component, you can use the default slot to do so.
Even if it is generally possible, we do not recommend using interactive elements in this slot because the background of the card control is clickable.
This can lead to confusion when the hit box of nested interactive controls is not clearly separated from the background, is invalid HTML and click events bubbling up to the card control will unexpectedly toggle it if they're not captured. More info: https://accessibilityinsights.io/info-examples/web/nested-interactive/
You can use the component directly in your forms, the control value will be available in the FormData of the surrounding <form> element, just as you are used to from native input elements.
Update the control and submit or reset the form to see how its FormData value changes.
Submit or reset the form to see how the FormData will look like.
{}
Change the width of a <card-control> component, by putting it (for example) in a grid.
If you like to stretch all <card-control> components within a row to the same height, simply add the class .h-100 to them.
As you can create radio button groups with native <radio> elements, you can do the same with our <post-card-control> component as well.
Just add the same name attribute value to multiple <post-card-control type="radio"> components.
The <post-card-control> offers a reset method to reset it to the initial state (validity and checked state).
The method can be called directly on the element itself.
const cardControl = document.querySelector('post-card-control') as HTMLPostCardControlElement; cardControl.reset();