Skip to content

Commit 3454ffc

Browse files
committed
fix back button in mobile sheet
1 parent 494453f commit 3454ffc

2 files changed

Lines changed: 42 additions & 31 deletions

File tree

‎src/lib/components/ui/MobileSheet.svelte‎

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@
77
interface Props {
88
selectedCountry: string | null;
99
selectedArtist: Artist | null;
10+
showBackButton?: boolean;
1011
onCloseCountry: () => void;
1112
onCloseArtist: () => void;
1213
onArtistSelect: (artist: Artist) => void;
1314
}
1415
15-
let { selectedCountry, selectedArtist, onCloseCountry, onCloseArtist, onArtistSelect }: Props =
16-
$props();
16+
let {
17+
selectedCountry,
18+
selectedArtist,
19+
showBackButton = false,
20+
onCloseCountry,
21+
onCloseArtist,
22+
onArtistSelect
23+
}: Props = $props();
1724
1825
type State = 'closed' | 'country' | 'artist';
1926
type Detent = 'medium' | 'large';
@@ -389,12 +396,12 @@
389396
tabindex="-1"
390397
>
391398
<!-- Handle -->
392-
<div class="flex shrink-0 justify-center py-2.5">
399+
<div class="flex shrink-0 justify-center py-2.5 pb-0">
393400
<div class="h-1 w-10 rounded-full bg-black/15"></div>
394401
</div>
395402

396403
<!-- Header: back-to-country button on artist (only if country context exists), country name on country state -->
397-
<div class="relative flex shrink-0 items-center justify-between gap-2 px-4 pb-2">
404+
<div class="relative flex shrink-0 items-center justify-between gap-2 px-4 pt-3 pb-2">
398405
<div class="relative h-7 min-w-0 flex-1">
399406
{#if selectedCountry}
400407
<h3
@@ -406,32 +413,33 @@
406413
>
407414
{selectedCountry}
408415
</h3>
409-
<button
410-
class="absolute inset-y-0 left-0 flex cursor-pointer items-center gap-1 border-none bg-transparent px-0 text-[0.65rem] tracking-[0.15em] text-black/50 uppercase focus-ring transition-colors duration-150 hover:text-pink"
411-
style="transform: translateX({100 *
412-
(1 -
413-
navProgress)}%); opacity: {navProgress}; transition: {navTransition}; pointer-events: {isArtistView
414-
? 'auto'
415-
: 'none'};"
416-
onclick={handleBack}
417-
aria-label="Back to country list"
418-
tabindex={isArtistView ? 0 : -1}
419-
>
420-
<svg
421-
xmlns="http://www.w3.org/2000/svg"
422-
width="14"
423-
height="14"
424-
viewBox="0 0 24 24"
425-
fill="none"
426-
stroke="currentColor"
427-
stroke-width="2"
428-
stroke-linecap="round"
429-
stroke-linejoin="round"
416+
{#if showBackButton}
417+
<button
418+
class="absolute inset-y-0 left-0 flex cursor-pointer items-center gap-1 border-none bg-transparent px-0 text-[0.65rem] tracking-[0.15em] text-black/50 uppercase focus-ring transition-colors duration-150 hover:text-pink"
419+
style="transform: translateX({100 *
420+
(1 -
421+
navProgress)}%); opacity: {navProgress}; transition: {navTransition}; pointer-events: {isArtistView
422+
? 'auto'
423+
: 'none'};"
424+
onclick={handleBack}
425+
aria-label="Back to country list"
426+
tabindex={isArtistView ? 0 : -1}
430427
>
431-
<polyline points="15 18 9 12 15 6"></polyline>
432-
</svg>
433-
<span class="truncate">{selectedCountry}</span>
434-
</button>
428+
<svg
429+
xmlns="http://www.w3.org/2000/svg"
430+
width="14"
431+
height="14"
432+
viewBox="0 0 24 24"
433+
fill="none"
434+
stroke="currentColor"
435+
stroke-width="2"
436+
stroke-linecap="round"
437+
stroke-linejoin="round"
438+
>
439+
<polyline points="15 18 9 12 15 6"></polyline>
440+
</svg>
441+
</button>
442+
{/if}
435443
{/if}
436444
</div>
437445

‎src/routes/+layout.svelte‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@
6060
}
6161
6262
function handleCloseArtist() {
63-
// Shallow nav: pop URL back so / shows again. The pathname-watch $effect
64-
// closes the drawer once URL changes.
63+
// Shallow nav: close drawer synchronously so the sheet transitions
64+
// immediately, and pop URL in parallel. The pathname-watch $effect is
65+
// only a safety net for browser-back; one click here should suffice.
6566
if (page.state.shallow) {
67+
closeArtistDrawer();
6668
history.back();
6769
return;
6870
}
@@ -251,6 +253,7 @@
251253
<MobileSheet
252254
{selectedCountry}
253255
selectedArtist={drawerArtist}
256+
showBackButton={page.state.shallow ?? false}
254257
onCloseCountry={clearSelection}
255258
onCloseArtist={handleCloseArtist}
256259
onArtistSelect={(artist) => navigateToArtist(artist.id)}

0 commit comments

Comments
 (0)