A checkbox list is used to give a user a way to select any number of a set of choices.
<tk-multi-select
options='["Salamander blood","Lionfish spines","Flobberworm mucus","Honey water"]'
selected='["Flobberworm mucus"]'
columns="4">
<div slot="legend" class="mb-2x">Potions</div>
</tk-multi-select>
<hr>
<tk-multi-select
options='[{ "label": "Salamander blood", "value": "sb" }, { "label": "Lionfish spines", "value": "ls" }, { "label": "Flobberworm mucus", "value": "fm" }, { "label": "Honey water", "value": "hw" }]'
selected='["fm"]'
show-toggles="false"
columns="4"
sm-columns="1"
md-columns="2"
lg-columns="3">
<div slot="legend" class="mb-2x">Potions</div>
</tk-multi-select>
The multi-select list renders a list of checkboxes based on a set of input options. The options can be a string array, or an array of objects with label
, value
, and hint
(optional) keys. The checkboxes are rendered as a grid, with the number of columns controlled by the columns
input property.
Scaling based on screen size can be optionally specified by the sm-columns
, md-columns
, and lg-columns
props.
<tk-multi-select
columns="4"
size="small"
options='["Salamander blood","Lionfish spines","Flobberworm mucus","Honey water"]'
selected='["Flobberworm mucus"]'>
<div slot="legend" class="mb-2x">Potions</div>
</tk-multi-select>
<hr>
<tk-multi-select
columns="4"
size="medium"
options='["Salamander blood","Lionfish spines","Flobberworm mucus","Honey water"]'
selected='["Flobberworm mucus"]'>
<div slot="legend" class="mb-2x">Potions</div>
</tk-multi-select>
<hr>
<tk-multi-select
columns="4"
size="large"
options='["Salamander blood","Lionfish spines","Flobberworm mucus","Honey water"]'
selected='["Flobberworm mucus"]'>
<div slot="legend" class="mb-2x">Potions</div>
</tk-multi-select>
The default size is medium. Small and large options are available.
<tk-multi-select
options='["Salamander blood","Lionfish spines","Flobberworm mucus","Honey water"]'
selected='["Flobberworm mucus"]'
columns="1">
<div slot="legend" class="mb-2x">Potions</div>
</tk-multi-select>
<tk-multi-select
options='["Salamander blood","Lionfish spines","Flobberworm mucus","Honey water"]'
selected='["Flobberworm mucus"]'
rows="2">
<div slot="legend" class="mb-2x">Potions</div>
</tk-multi-select>
<hr>
<tk-multi-select
options='["Salamander blood","Lionfish spines","Flobberworm mucus","Honey water"]'
selected='["Flobberworm mucus"]'
rows="2"
md-rows="4"
md-columns="1">
<div slot="legend" class="mb-2x">Potions</div>
</tk-multi-select>
We sometimes need to show the order of our list items vertically. By defining the number of rows, the list will flow from top to bottom and break to another column after the number of rows is filled. Scaling based on screen size can be optionally specified by the sm-rows
, md-rows
, and lg-rows
props.
<tk-multi-select
block
columns="1"
options='["Salamander blood","Lionfish spines","Flobberworm mucus","Honey water"]'
selected='["Flobberworm mucus"]'
>
<div slot="legend" class="mb-2x">Potions</div>
</tk-multi-select>
<hr>
<tk-multi-select
block
columns="3"
options='["Salamander blood","Lionfish spines","Flobberworm mucus","Honey water"]'
selected='["Flobberworm mucus"]'
>
<div slot="legend" class="mb-2x">Potions</div>
</tk-multi-select>
<hr>
<tk-multi-select
block
columns="1"
options='["Salamander blood","Lionfish spines","Flobberworm mucus","Honey water"]'
selected='["Flobberworm mucus"]'
>
<div slot="legend" class="mb-2x">Potions</div>
<div slot="error" class="l-inline-flex l-v-baseline t-base">
<tk-icon aria-label="error" class="mr-2x mv-auto" name="alert" role="img" size="medium"></tk-icon>Example error message
</div>
</tk-multi-select>
<tk-multi-select
columns="4"
options='["Salamander blood","Lionfish spines","Flobberworm mucus","Honey water"]'
selected='["Flobberworm mucus"]'
>
<div slot="legend" class="mb-2x">Potions</div>
<div slot="error" class="l-inline-flex l-v-baseline t-base">
<tk-icon aria-label="error" class="mr-2x mv-auto" name="alert" role="img" size="medium"></tk-icon>Example error message
</div>
</tk-multi-select>
The multi-select list generates checkboxes corresponding to a provided array of input options. The otherOption
parameter allows for the inclusion of additional choices specified as an object, each containing label
, value
, text
, placeholder
, optionally hint
keys. When selected, the ‘other’ option is presented with a textarea field. An onUpdated
function is provided to capture and return any changes made including the other option textarea.
<tk-multi-select
columns="1"
options='["Salamander blood","Lionfish spines","Flobberworm mucus","Honey water"]'
otherOption='{"value": "other", "label": "Other", "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", "placeholder": "Write other option", "ariaLabelText": "Other question", "textareaLabel": "Other textarea question", "preventPaste": "true"}'
block
selected='["other"]'
>
</tk-multi-select>
The multi-select list renders a list of checkboxes based on a set of input options. The options can be a string array, or an array of objects with label
, value
, and hint
(optional) keys. The checkboxes are rendered as a grid, with the number of columns controlled by the columns
input property.
Scaling based on screen size can be optionally specified by the sm-columns
, md-columns
, and lg-columns
props.
Property | Attribute | Description | Type | Default |
---|---|---|---|---|
block |
block |
[BETA] Controls whether the options are rendered in block format | boolean |
false |
columns |
columns |
The number of columns that the list of checkboxes should be rendered to. | number |
2 |
disabled |
disabled |
Displays the multi-select in a disabled style. | boolean |
false |
lgColumns |
lg-columns |
Same as columns prop for large and smaller screen sizes. |
number |
undefined |
lgRows |
lg-rows |
Same as columns prop for large and smaller screen sizes. |
number |
undefined |
mdColumns |
md-columns |
Same as columns prop for medium and smaller screen sizes. |
number |
undefined |
mdRows |
md-rows |
Same as rows prop for medium and smaller screen sizes. |
number |
undefined |
options |
– | An array of choices to render. This can be either an array of strings, or an array of objects with label and value properties. A ariaLabelText can be added and will be the aria-label value of the option. |
any[] | string[] |
[] |
otherOption |
– | An object to render the other option choice. This can be a object, or an with label , value , text and placeholder properties. A ariaLabelText can be added and will be the aria-label value of the option. |
basicOption & { hint?: string; icon?: string; iconSize?: SizeSML; renderedHTMLHint?: string; ariaLabel?: string; } & { text: string; placeholder?: string; textareaLabel?: string; preventPaste?: boolean; } |
null |
rows |
rows |
The number of rows that the list of checkboxes should be rendered to. | number |
undefined |
selected |
– | An array of choices to be pre-selected. If the input options are a string array, then the elements of the array should match a string. If the input was an object array, then the elements of the selected array will match the value key of the input objects. Setting this value to undefined or null will not change the state of the checkboxes, or emit the check event. | string[] |
[] |
showToggles |
show-toggles |
Controls the visibility of the “Select All | Unselect All” toggle. | boolean |
true |
size |
size |
Sets the text and checkbox size. | "large" | "medium" | "small" |
undefined |
smColumns |
sm-columns |
Same as columns prop for small screen sizes. |
number |
undefined |
smRows |
sm-rows |
Same as rows prop for small screen sizes. |
number |
undefined |
Event | Description | Type |
---|---|---|
allChecked |
[DEPRECATED] Returns true if all options have been checked, false if not every option has been checked. |
CustomEvent<boolean> |
check |
A string array of the currently selected choices whenever a checkbox is checked or unchecked. If no choices are selected, an empty array will be emitted. If the input was a string array, then the values of the array are what will be emitted. If the input was an object, then the value key of that object will be emitted. |
CustomEvent<string[]> |
updated |
The value and checked status of the currently clicked checkbox will be emitted. Nothing will be emitted if Select/Unselect All is clicked. Additionaly, will be emitted on other option question text change. |
CustomEvent<{ value: string; checked: boolean; other?: string; }> |