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

Sidebar Fixes #10483

Merged
merged 8 commits into from
Feb 3, 2025
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
6 changes: 6 additions & 0 deletions .changeset/wild-candles-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@gradio/sidebar": patch
"gradio": patch
---

feat:Sidebar Fixes
6 changes: 4 additions & 2 deletions js/sidebar/Index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import Sidebar from "./shared/Sidebar.svelte";
import { StatusTracker } from "@gradio/statustracker";
import type { LoadingStatus } from "@gradio/statustracker";

import type { Gradio } from "@gradio/utils";
import Column from "@gradio/column";
export let open = true;
export let loading_status: LoadingStatus;
export let gradio: Gradio<{
Expand All @@ -25,5 +25,7 @@
on:expand={() => gradio.dispatch("expand")}
on:collapse={() => gradio.dispatch("collapse")}
>
<slot />
<Column>
<slot />
</Column>
</Sidebar>
25 changes: 15 additions & 10 deletions js/sidebar/shared/Sidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
export let width: number | string;

// Using a temporary variable to animate the sidebar opening at the start
let mounted = false;
let _open = false;
let sidebar_div: HTMLElement;
let overlap_amount = 0;
Expand All @@ -17,30 +18,33 @@

// Check if the sidebar overlaps with the main content
function check_overlap(): void {
if (!sidebar_div?.parentElement) return;
const parent_rect = sidebar_div.parentElement.getBoundingClientRect();
if (!sidebar_div.closest(".wrap")) return;
const parent_rect = sidebar_div.closest(".wrap")?.getBoundingClientRect();
if (!parent_rect) return;
const sidebar_rect = sidebar_div.getBoundingClientRect();
const available_space = parent_rect.left;
overlap_amount = Math.max(0, sidebar_rect.width - available_space + 30);
}

onMount(() => {
sidebar_div.parentElement?.classList.add("sidebar-parent");
sidebar_div.closest(".wrap")?.classList.add("sidebar-parent");
check_overlap();
window.addEventListener("resize", check_overlap);

const update_parent_overlap = (): void => {
if (sidebar_div?.parentElement) {
sidebar_div.parentElement.style.setProperty(
"--overlap-amount",
`${overlap_amount}px`
);
}
document.documentElement.style.setProperty(
"--overlap-amount",
`${overlap_amount}px`
);
};
update_parent_overlap();
_open = open;
mounted = true;
return () => window.removeEventListener("resize", check_overlap);
});

// We need to wait for the component to be mounted before we can set the open state
// so that it animates correctly.
$: if (mounted) _open = open;
</script>

<div
Expand Down Expand Up @@ -140,6 +144,7 @@

.sidebar-content {
padding: var(--size-5);
padding-right: var(--size-8);
overflow-y: auto;
}
</style>
Loading