mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
feat(multi-select): add itemToProp
to customize name, title, labelText values passed to input (#1074)
Currently, the input `name` for each item uses the same value as `itemToString(item)`. This adds an `itemToInput` prop to allow the consumer to customize the name/title/labelText values passed to the `Checkbox` input. The name attribute now defaults to use the `item.id` instead of `item.text`.
This commit is contained in:
parent
4a197fdb7f
commit
2148e1c7b6
4 changed files with 32 additions and 3 deletions
|
@ -2429,6 +2429,7 @@ export interface MultiSelectItem {
|
||||||
| selectedIds | <code>let</code> | Yes | <code>MultiSelectItemId[]</code> | <code>[]</code> | Set the selected ids |
|
| selectedIds | <code>let</code> | Yes | <code>MultiSelectItemId[]</code> | <code>[]</code> | Set the selected ids |
|
||||||
| items | <code>let</code> | Yes | <code>MultiSelectItem[]</code> | <code>[]</code> | Set the multiselect items |
|
| items | <code>let</code> | Yes | <code>MultiSelectItem[]</code> | <code>[]</code> | Set the multiselect items |
|
||||||
| itemToString | <code>let</code> | No | <code>(item: MultiSelectItem) => any</code> | <code>(item) => item.text || item.id</code> | Override the display of a multiselect item |
|
| itemToString | <code>let</code> | No | <code>(item: MultiSelectItem) => any</code> | <code>(item) => item.text || item.id</code> | Override the display of a multiselect item |
|
||||||
|
| itemToInput | <code>let</code> | No | <code>(item: MultiSelectItem) => { name?: string; labelText?: any; title?: string; }</code> | <code>(item) => {}</code> | Override the item name, title, labelText passed to the checkbox input |
|
||||||
| size | <code>let</code> | No | <code>"sm" | "lg" | "xl"</code> | <code>undefined</code> | Set the size of the combobox |
|
| size | <code>let</code> | No | <code>"sm" | "lg" | "xl"</code> | <code>undefined</code> | Set the size of the combobox |
|
||||||
| type | <code>let</code> | No | <code>"default" | "inline"</code> | <code>"default"</code> | Specify the type of multiselect |
|
| type | <code>let</code> | No | <code>"default" | "inline"</code> | <code>"default"</code> | Specify the type of multiselect |
|
||||||
| direction | <code>let</code> | No | <code>"bottom" | "top"</code> | <code>"bottom"</code> | Specify the direction of the multiselect dropdown menu |
|
| direction | <code>let</code> | No | <code>"bottom" | "top"</code> | <code>"bottom"</code> | Specify the direction of the multiselect dropdown menu |
|
||||||
|
|
|
@ -6446,6 +6446,17 @@
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"reactive": false
|
"reactive": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "itemToInput",
|
||||||
|
"kind": "let",
|
||||||
|
"description": "Override the item name, title, labelText passed to the checkbox input",
|
||||||
|
"type": "(item: MultiSelectItem) => { name?: string; labelText?: any; title?: string; }",
|
||||||
|
"value": "(item) => {}",
|
||||||
|
"isFunction": true,
|
||||||
|
"isFunctionDeclaration": false,
|
||||||
|
"constant": false,
|
||||||
|
"reactive": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "selectedIds",
|
"name": "selectedIds",
|
||||||
"kind": "let",
|
"kind": "let",
|
||||||
|
|
|
@ -23,6 +23,12 @@
|
||||||
*/
|
*/
|
||||||
export let itemToString = (item) => item.text || item.id;
|
export let itemToString = (item) => item.text || item.id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override the item name, title, labelText passed to the checkbox input
|
||||||
|
* @type {(item: MultiSelectItem) => { name?: string; labelText?: any; title?: string; }}
|
||||||
|
*/
|
||||||
|
export let itemToInput = (item) => {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the selected ids
|
* Set the selected ids
|
||||||
* @type {MultiSelectItemId[]}
|
* @type {MultiSelectItemId[]}
|
||||||
|
@ -478,12 +484,13 @@
|
||||||
}}"
|
}}"
|
||||||
>
|
>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
|
name="{item.id}"
|
||||||
|
labelText="{itemToString(item)}"
|
||||||
|
title="{useTitleInItem ? itemToString(item) : undefined}"
|
||||||
|
{...itemToInput(item)}
|
||||||
readonly
|
readonly
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
id="checkbox-{item.id}"
|
id="checkbox-{item.id}"
|
||||||
title="{useTitleInItem ? itemToString(item) : undefined}"
|
|
||||||
name="{itemToString(item)}"
|
|
||||||
labelText="{itemToString(item)}"
|
|
||||||
checked="{item.checked}"
|
checked="{item.checked}"
|
||||||
disabled="{disabled}"
|
disabled="{disabled}"
|
||||||
on:blur="{() => {
|
on:blur="{() => {
|
||||||
|
|
10
types/MultiSelect/MultiSelect.svelte.d.ts
vendored
10
types/MultiSelect/MultiSelect.svelte.d.ts
vendored
|
@ -24,6 +24,16 @@ export interface MultiSelectProps
|
||||||
*/
|
*/
|
||||||
itemToString?: (item: MultiSelectItem) => any;
|
itemToString?: (item: MultiSelectItem) => any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override the item name, title, labelText passed to the checkbox input
|
||||||
|
* @default (item) => {}
|
||||||
|
*/
|
||||||
|
itemToInput?: (item: MultiSelectItem) => {
|
||||||
|
name?: string;
|
||||||
|
labelText?: any;
|
||||||
|
title?: string;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the selected ids
|
* Set the selected ids
|
||||||
* @default []
|
* @default []
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue