mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-09-06 07:57:12 +08:00
fix: 移动端 sidebar 在点按后自动收起 (#389)
This commit is contained in:
@@ -11,7 +11,10 @@
|
|||||||
import * as Sidebar from '$lib/components/ui/sidebar/index.js';
|
import * as Sidebar from '$lib/components/ui/sidebar/index.js';
|
||||||
import type { ComponentProps } from 'svelte';
|
import type { ComponentProps } from 'svelte';
|
||||||
|
|
||||||
|
let sidebar = Sidebar.useSidebar();
|
||||||
|
|
||||||
let { ref = $bindable(null), ...restProps }: ComponentProps<typeof Sidebar.Root> = $props();
|
let { ref = $bindable(null), ...restProps }: ComponentProps<typeof Sidebar.Root> = $props();
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
header: {
|
header: {
|
||||||
title: 'Bili Sync',
|
title: 'Bili Sync',
|
||||||
@@ -79,6 +82,12 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const closeMobileSidebar = () => {
|
||||||
|
if (sidebar.isMobile) {
|
||||||
|
sidebar.setOpenMobile(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Sidebar.Root bind:ref variant="inset" {...restProps}>
|
<Sidebar.Root bind:ref variant="inset" {...restProps}>
|
||||||
@@ -87,7 +96,7 @@
|
|||||||
<Sidebar.MenuItem>
|
<Sidebar.MenuItem>
|
||||||
<Sidebar.MenuButton size="lg">
|
<Sidebar.MenuButton size="lg">
|
||||||
{#snippet child({ props })}
|
{#snippet child({ props })}
|
||||||
<a href={data.header.href} {...props}>
|
<a href={data.header.href} {...props} onclick={closeMobileSidebar}>
|
||||||
<div
|
<div
|
||||||
class="bg-sidebar-primary text-sidebar-primary-foreground flex aspect-square size-8 items-center justify-center rounded-lg"
|
class="bg-sidebar-primary text-sidebar-primary-foreground flex aspect-square size-8 items-center justify-center rounded-lg"
|
||||||
>
|
>
|
||||||
@@ -112,7 +121,7 @@
|
|||||||
<Sidebar.MenuItem>
|
<Sidebar.MenuItem>
|
||||||
<Sidebar.MenuButton class="h-8">
|
<Sidebar.MenuButton class="h-8">
|
||||||
{#snippet child({ props })}
|
{#snippet child({ props })}
|
||||||
<a href={item.href} {...props}>
|
<a href={item.href} {...props} onclick={closeMobileSidebar}>
|
||||||
<item.icon class="size-4" />
|
<item.icon class="size-4" />
|
||||||
<span class="text-sm">{item.title}</span>
|
<span class="text-sm">{item.title}</span>
|
||||||
</a>
|
</a>
|
||||||
@@ -131,7 +140,7 @@
|
|||||||
<Sidebar.MenuItem>
|
<Sidebar.MenuItem>
|
||||||
<Sidebar.MenuButton class="h-8">
|
<Sidebar.MenuButton class="h-8">
|
||||||
{#snippet child({ props })}
|
{#snippet child({ props })}
|
||||||
<a href={item.href} {...props}>
|
<a href={item.href} {...props} onclick={closeMobileSidebar}>
|
||||||
<item.icon class="size-4" />
|
<item.icon class="size-4" />
|
||||||
<span class="text-sm">{item.title}</span>
|
<span class="text-sm">{item.title}</span>
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
Reference in New Issue
Block a user