Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DT-2347 - support multiselect in combobox #2352

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/lib/holocene/combobox/combobox-option.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte';

import Checkbox from '$lib/holocene/checkbox.svelte';
import MenuItem from '$lib/holocene/menu/menu-item.svelte';

const dispatch = createEventDispatcher<{ click: undefined }>();

interface Props {
selected?: boolean;
disabled?: boolean;
multiselect?: boolean;
label: string;
}

interface DisabledProps {
label: string;
disabled: true;
selected?: never;
}
Expand All @@ -15,6 +23,8 @@

export let selected = false;
export let disabled = false;
export let multiselect = false;
export let label: string;
</script>

<MenuItem
Expand All @@ -23,10 +33,14 @@
class="break-all"
aria-selected={selected}
aria-disabled={disabled}
selected={!multiselect && selected}
{disabled}
{selected}
>
<slot slot="leading" name="leading" />
<slot />
<slot slot="leading" name="leading">
{#if multiselect}
<Checkbox on:change={() => dispatch('click')} checked={selected} />
{/if}
</slot>
{label}
<slot slot="trailing" name="trailing" />
</MenuItem>
17 changes: 17 additions & 0 deletions src/lib/holocene/combobox/combobox.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,20 @@
expect(noResults).toBeInTheDocument();
}}
/>

<Story
name="Multiselect"
args={{
options: [
'English',
'English (UK)',
'German',
'French',
'Japanese',
'Spanish',
'Portuguese',
],
multiselect: true,
value: [],
}}
/>
Loading
Loading