mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
parent
ceb7abf2e9
commit
2858776367
7 changed files with 57 additions and 5 deletions
|
@ -686,7 +686,9 @@ export interface ComboBoxItem {
|
||||||
|
|
||||||
### Slots
|
### Slots
|
||||||
|
|
||||||
None.
|
| Slot name | Default | Props | Fallback |
|
||||||
|
| :-------- | :------ | :-------------------------------------------------- | :-------------------------------- |
|
||||||
|
| -- | Yes | <code>{ item: ComboBoxItem; index: number } </code> | <code>{itemToString(item)}</code> |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
|
|
|
@ -1639,7 +1639,14 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"moduleExports": [],
|
"moduleExports": [],
|
||||||
"slots": [],
|
"slots": [
|
||||||
|
{
|
||||||
|
"name": "__default__",
|
||||||
|
"default": true,
|
||||||
|
"fallback": "{itemToString(item)}",
|
||||||
|
"slot_props": "{ item: ComboBoxItem; index: number }"
|
||||||
|
}
|
||||||
|
],
|
||||||
"events": [
|
"events": [
|
||||||
{
|
{
|
||||||
"type": "dispatched",
|
"type": "dispatched",
|
||||||
|
|
|
@ -18,6 +18,12 @@ items={[
|
||||||
{id: "2", text: "Fax"}
|
{id: "2", text: "Fax"}
|
||||||
]} />
|
]} />
|
||||||
|
|
||||||
|
### Custom slot
|
||||||
|
|
||||||
|
Override the default slot to customize the display of each item. Access the item and index through the `let:` directive.
|
||||||
|
|
||||||
|
<FileSource src="/framed/ComboBox/ComboBoxSlot" />
|
||||||
|
|
||||||
### Selected id
|
### Selected id
|
||||||
|
|
||||||
<ComboBox titleText="Contact" placeholder="Select contact method"
|
<ComboBox titleText="Contact" placeholder="Select contact method"
|
||||||
|
|
29
docs/src/pages/framed/ComboBox/ComboBoxSlot.svelte
Normal file
29
docs/src/pages/framed/ComboBox/ComboBoxSlot.svelte
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<script>
|
||||||
|
import { ComboBox } from "carbon-components-svelte";
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<ComboBox
|
||||||
|
titleText="Contact"
|
||||||
|
placeholder="Select contact method"
|
||||||
|
items="{[
|
||||||
|
{ id: '0', text: 'Slack' },
|
||||||
|
{ id: '1', text: 'Email' },
|
||||||
|
{ id: '2', text: 'Fax' },
|
||||||
|
]}"
|
||||||
|
let:item
|
||||||
|
let:index
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<strong>{item.text}</strong>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
id: {item.id} - index:
|
||||||
|
{index}
|
||||||
|
</div>
|
||||||
|
</ComboBox>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
:global(.bx--list-box__menu-item, .bx--list-box__menu-item__option) {
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -3,6 +3,7 @@
|
||||||
* @typedef {any} ComboBoxItemId
|
* @typedef {any} ComboBoxItemId
|
||||||
* @typedef {{ id: ComboBoxItemId; text: string; }} ComboBoxItem
|
* @typedef {{ id: ComboBoxItemId; text: string; }} ComboBoxItem
|
||||||
* @event {{ selectedId: ComboBoxItemId; selectedItem: ComboBoxItem }} select
|
* @event {{ selectedId: ComboBoxItemId; selectedItem: ComboBoxItem }} select
|
||||||
|
* @slot {{ item: ComboBoxItem; index: number }}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -363,7 +364,9 @@
|
||||||
highlightedIndex = i;
|
highlightedIndex = i;
|
||||||
}}"
|
}}"
|
||||||
>
|
>
|
||||||
|
<slot item="{item}" index="{i}">
|
||||||
{itemToString(item)}
|
{itemToString(item)}
|
||||||
|
</slot>
|
||||||
{#if selectedItem && selectedItem.id === item.id}
|
{#if selectedItem && selectedItem.id === item.id}
|
||||||
<Checkmark16 class="bx--list-box__menu-item__selected-icon" />
|
<Checkmark16 class="bx--list-box__menu-item__selected-icon" />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -23,7 +23,12 @@
|
||||||
on:select="{(e) => {
|
on:select="{(e) => {
|
||||||
console.log(e.detail.selectedId);
|
console.log(e.detail.selectedId);
|
||||||
}}"
|
}}"
|
||||||
/>
|
let:item
|
||||||
|
let:index
|
||||||
|
>
|
||||||
|
{item.id}
|
||||||
|
{index}
|
||||||
|
</ComboBox>
|
||||||
|
|
||||||
<ComboBox
|
<ComboBox
|
||||||
titleText="Contact"
|
titleText="Contact"
|
||||||
|
|
2
types/ComboBox/ComboBox.svelte.d.ts
vendored
2
types/ComboBox/ComboBox.svelte.d.ts
vendored
|
@ -157,7 +157,7 @@ export default class ComboBox extends SvelteComponentTyped<
|
||||||
clear: WindowEventMap["clear"];
|
clear: WindowEventMap["clear"];
|
||||||
scroll: WindowEventMap["scroll"];
|
scroll: WindowEventMap["scroll"];
|
||||||
},
|
},
|
||||||
{}
|
{ default: { item: ComboBoxItem; index: number } }
|
||||||
> {
|
> {
|
||||||
/**
|
/**
|
||||||
* Clear the combo box programmatically
|
* Clear the combo box programmatically
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue