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

Small tweaks to Holocene components for self serve signup #1866

Merged
merged 1 commit into from
Feb 14, 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
support label slot in checkbox
add close event to combobox
only dispatch close even from menucontainer if menu is open
  • Loading branch information
rossedfort committed Feb 14, 2024
commit 640b3386c050542ae6388c9ff5ca7388fafdece9
12 changes: 7 additions & 5 deletions src/lib/holocene/checkbox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

interface $$Props extends HTMLInputAttributes {
checked?: boolean;
label: string;
label?: string;
labelHidden?: boolean;
theme?: 'dark' | 'light';
indeterminate?: boolean;
Expand All @@ -22,7 +22,7 @@

export let id = '';
export let checked = false;
export let label: string;
export let label = '';
export let labelHidden = false;
export let theme: 'dark' | 'light' = 'light';
export let indeterminate = false;
Expand Down Expand Up @@ -95,9 +95,11 @@
{/if}
</span>

<span class="label" class:sr-only={labelHidden}>
{label}
</span>
<slot name="label">
<span class="label" class:sr-only={labelHidden}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could a checkbox potentially have both a label slot and a label prop? Wondering if we want to make this a conditional so that there's no potential for both.

{label}
</span>
</slot>
</label>
</div>

Expand Down
9 changes: 8 additions & 1 deletion src/lib/holocene/combobox/combobox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
const dispatch = createEventDispatcher<{
change: T | string;
filter: string;
close: T | string;
}>();

type ExtendedInputEvent = Event & {
Expand Down Expand Up @@ -131,6 +132,12 @@
const closeList = () => {
if (!$open) return;
$open = false;
dispatch('close', selectedOption);
resetValueAndOptions();
};

const handleMenuClose = () => {
dispatch('close', selectedOption);
resetValueAndOptions();
};

Expand Down Expand Up @@ -246,7 +253,7 @@
};
</script>

<MenuContainer {open} on:close={resetValueAndOptions}>
<MenuContainer {open} on:close={handleMenuClose}>
<label
class="combobox-label {theme}"
class:sr-only={labelHidden}
Expand Down
6 changes: 4 additions & 2 deletions src/lib/holocene/menu/menu-container.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
const dispatch = createEventDispatcher<{ close: undefined }>();

const closeMenu = () => {
dispatch('close');
$open = false;
if ($open) {
dispatch('close');
$open = false;
}
};

setContext<MenuContext>(MENU_CONTEXT, {
Expand Down
Loading