feat(dropdown): make Dropdown slottable (#1182)

This commit is contained in:
metonym 2022-03-19 09:15:52 -07:00 committed by GitHub
commit f5594daba6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 57 additions and 5 deletions

View file

@ -19,6 +19,12 @@ components: ["Dropdown", "DropdownSkeleton"]
{id: "1", text: "Email"},
{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/Dropdown/DropdownSlot" />
### Hidden label
<Dropdown hideLabel titleText="Contact" selectedId="0" items="{[{id: "0", text: "Slack"},

View file

@ -0,0 +1,29 @@
<script>
import { Dropdown } from "carbon-components-svelte";
</script>
<Dropdown
titleText="Contact"
selectedId="0"
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>
</Dropdown>
<style>
:global(.bx--list-box__menu-item, .bx--list-box__menu-item__option) {
height: auto;
}
</style>