Skip to content

Commit b408197

Browse files
feat: ignore nav history on tab change so that back buttons go straight to the list page with scroll in tact, add back button to mobile view
1 parent 37082a9 commit b408197

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

src/lib/client/ui/navigation/tabs/Tabs.svelte

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
1717
interface BackButton {
1818
label: string;
19+
href?: string;
1920
}
2021
2122
interface Breadcrumb {
@@ -64,7 +65,7 @@
6465
6566
function handleTabSelect(href: string) {
6667
dropdownOpen = false;
67-
goto(href);
68+
goto(href, { replaceState: true });
6869
}
6970
</script>
7071

@@ -73,12 +74,13 @@
7374
{:else if useMobileMode}
7475
<!-- Mobile: Custom dropdown with icons -->
7576
<div class="border-b border-neutral-200 py-3 dark:border-neutral-800">
76-
<div class="relative" bind:this={triggerEl} use:clickOutside={() => (dropdownOpen = false)}>
77-
<button
78-
type="button"
79-
on:click={() => (dropdownOpen = !dropdownOpen)}
80-
class="flex w-full items-center justify-between gap-2 rounded-xl border border-neutral-300 bg-white px-3 py-2 text-sm font-medium text-neutral-900 transition-colors hover:bg-neutral-50 dark:border-neutral-700/60 dark:bg-neutral-800/50 dark:text-neutral-100 dark:hover:bg-neutral-700"
81-
>
77+
<div class="flex items-center gap-2">
78+
<div class="relative flex-1" bind:this={triggerEl} use:clickOutside={() => (dropdownOpen = false)}>
79+
<button
80+
type="button"
81+
on:click={() => (dropdownOpen = !dropdownOpen)}
82+
class="flex w-full items-center justify-between gap-2 rounded-xl border border-neutral-300 bg-white px-3 py-2 text-sm font-medium text-neutral-900 transition-colors hover:bg-neutral-50 dark:border-neutral-700/60 dark:bg-neutral-800/50 dark:text-neutral-100 dark:hover:bg-neutral-700"
83+
>
8284
<span class="flex items-center gap-2">
8385
{#if activeTab?.icon}
8486
<svelte:component this={activeTab.icon} size={16} class="text-accent-500" />
@@ -104,25 +106,36 @@
104106
</Dropdown>
105107
{/if}
106108
</div>
109+
{#if backButton}
110+
<button
111+
type="button"
112+
on:click={() => history.back()}
113+
class="flex cursor-pointer items-center gap-1.5 rounded-xl border border-neutral-300 bg-white px-3 py-2 text-sm font-medium text-neutral-600 transition-colors hover:bg-neutral-50 hover:text-neutral-900 dark:border-neutral-700/60 dark:bg-neutral-800/50 dark:text-neutral-400 dark:hover:bg-neutral-700 dark:hover:text-neutral-100"
114+
>
115+
<ArrowLeft size={14} />
116+
{backButton.label}
117+
</button>
118+
{/if}
119+
</div>
107120
</div>
108121
{:else}
109122
<!-- Desktop: Tab bar -->
110123
<div class="border-b border-neutral-200 dark:border-neutral-800">
111124
<nav class="-mb-px flex items-center justify-between gap-2" aria-label="Tabs">
112125
<div class="flex gap-2">
113126
{#each tabs as tab (tab.href)}
114-
<a
115-
href={tab.href}
116-
data-sveltekit-preload-data="tap"
117-
class="flex items-center gap-2 border-b-2 px-4 py-3 text-sm font-medium transition-colors {tab.active
127+
<button
128+
type="button"
129+
on:click={() => handleTabSelect(tab.href)}
130+
class="flex cursor-pointer items-center gap-2 border-b-2 px-4 py-3 text-sm font-medium transition-colors {tab.active
118131
? 'border-accent-600 text-accent-600 dark:border-accent-500 dark:text-accent-500'
119132
: 'border-transparent text-neutral-600 hover:border-neutral-300 hover:text-neutral-900 dark:text-neutral-400 dark:hover:border-neutral-700 dark:hover:text-neutral-50'}"
120133
>
121134
{#if tab.icon}
122135
<svelte:component this={tab.icon} size={16} />
123136
{/if}
124137
{tab.label}
125-
</a>
138+
</button>
126139
{/each}
127140

128141
<!-- Actions slot for custom action tabs (like Add Instance) -->
@@ -144,7 +157,7 @@
144157
<button
145158
type="button"
146159
on:click={() => history.back()}
147-
class="flex items-center gap-2 px-3 py-1.5 text-sm font-medium text-neutral-600 transition-colors hover:text-neutral-900 dark:text-neutral-400 dark:hover:text-neutral-100"
160+
class="flex cursor-pointer items-center gap-2 px-3 py-1.5 text-sm font-medium text-neutral-600 transition-colors hover:text-neutral-900 dark:text-neutral-400 dark:hover:text-neutral-100"
148161
>
149162
<ArrowLeft size={14} />
150163
{backButton.label}

0 commit comments

Comments
 (0)