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

Allow control of max size for menu's. Allow external control for comb… #2453

Merged
merged 2 commits into from
Dec 4, 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
19 changes: 11 additions & 8 deletions src/lib/components/bottom-nav.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { writable } from 'svelte/store';
import { slide } from 'svelte/transition';

import { twMerge as merge } from 'tailwind-merge';
Expand All @@ -18,12 +19,12 @@
import BottomNavNamespaces from './bottom-nav-namespaces.svelte';
import BottomNavSettings from './bottom-nav-settings.svelte';

export let namespaceList: NamespaceListItem[] = [];
export let namespaceList: NamespaceListItem[] | undefined = [];
export let linkList: NavLinkListItem[];
export let isCloud = false;

let viewLinks = false;
let viewNamespaces = false;
let viewNamespaces = writable(false);
let viewSettings = false;

$: namespace = $page.params.namespace || $lastUsedNamespace;
Expand All @@ -33,29 +34,29 @@

const onLinksClick = () => {
viewSettings = false;
viewNamespaces = false;
$viewNamespaces = false;
viewLinks = !viewLinks;
};

const onNamespaceClick = () => {
viewLinks = false;
viewNamespaces = !viewNamespaces;
$viewNamespaces = !$viewNamespaces;
viewSettings = false;
};

const onSettingsClick = () => {
viewLinks = false;
viewNamespaces = false;
$viewNamespaces = false;
viewSettings = !viewSettings;
};

beforeNavigate(() => {
viewLinks = false;
viewSettings = false;
viewNamespaces = false;
$viewNamespaces = false;
});

$: menuIsOpen = viewLinks || viewNamespaces || viewSettings;
$: menuIsOpen = viewLinks || $viewNamespaces || viewSettings;

const truncateNamespace = (namespace: string) => {
if (namespace.length > 16) {
Expand All @@ -73,7 +74,9 @@
out:slide={{ duration: 200, delay: 0 }}
>
<BottomNavLinks open={viewLinks} {linkList} />
<BottomNavNamespaces open={viewNamespaces} {namespaceList} />
<slot name="nsPicker" open={viewNamespaces}>
<BottomNavNamespaces open={$viewNamespaces} {namespaceList} />
</slot>
<BottomNavSettings open={viewSettings}>
<slot />
</BottomNavSettings>
Expand Down
22 changes: 19 additions & 3 deletions src/lib/holocene/combobox/combobox.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import type { HTMLInputAttributes } from 'svelte/elements';
import { writable } from 'svelte/store';
import { writable, type Writable } from 'svelte/store';

import { createEventDispatcher } from 'svelte';
import { twMerge as merge } from 'tailwind-merge';
Expand Down Expand Up @@ -51,6 +51,8 @@
hrefDisabled?: boolean;
loading?: boolean;
loadingText?: string;
open?: Writable<boolean>;
maxMenuHeight?: string;
}

type MultiSelectProps = {
Expand Down Expand Up @@ -131,7 +133,20 @@
let selectedOption: string | T;
let menuElement: HTMLUListElement;
let inputElement: HTMLInputElement;
const open = writable<boolean>(false);

export let open = writable<boolean>(false);
export let maxMenuHeight: string = 'max-h-[20rem]';

// We need this piece of code to focus the element when externally modifying the
// open store. Specifically we use this behaviour in bottom nav to focus the combobox
// after the bottom nav is clicked
$: {
if ($open && inputElement && document.activeElement !== inputElement) {
inputElement.focus();
inputElement.select();
}
}

// We want this to react to external changes to the options prop to support async use cases
$: list = filterOptions(filterValue, options);

Expand Down Expand Up @@ -456,11 +471,12 @@
</div>

<Menu
keepOpen={multiselect}
keepOpen={multiselect || true}
bind:menuElement
id="{id}-listbox"
role="listbox"
class="w-full"
maxHeight={maxMenuHeight}
>
{#if multiselect && isArrayValue(value)}
<ComboboxOption
Expand Down
4 changes: 3 additions & 1 deletion src/lib/holocene/menu/menu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
keepOpen?: boolean;
position?: 'left' | 'right' | 'top-left' | 'top-right';
menuElement?: HTMLUListElement;
maxHeight?: string;
}

let className = '';
Expand All @@ -23,6 +24,7 @@
export let keepOpen = false;
export let position: 'left' | 'right' | 'top-left' | 'top-right' = 'left';
export let menuElement: HTMLUListElement = null;
export let maxHeight: string = 'max-h-[20rem]';

const {
keepOpen: keepOpenCtx,
Expand All @@ -44,7 +46,7 @@
<ul
in:fly={{ duration: 100 }}
role="menu"
class={merge('menu', 'max-h-[20rem]', position, className)}
class={merge('menu', maxHeight, position, className)}
class:hidden={!$open}
aria-labelledby={id}
tabindex={-1}
Expand Down
Loading