feat: Improve container on:navigate

This commit is contained in:
Aleksi Lassila
2024-04-11 19:20:40 +03:00
parent 428258798c
commit 2f0f048d89
7 changed files with 68 additions and 26 deletions

View File

@@ -3,10 +3,10 @@
</script>
<Container
handleNavigateOut={{
left: () => {
on:navigate={({ detail }) => {
if (detail.direction === 'left' && detail.options.willLeaveContainer) {
history.back();
return false;
detail.preventNavigation();
}
}}
focusOnMount

View File

@@ -42,10 +42,15 @@
<Container class="flex-1 flex">
<HeroShowcaseBackground {urls} {index} />
<Container
handleNavigateOut={{
right: onNext,
left: onPrevious,
up: () => Selectable.giveFocus('left', true) || true
on:navigate={({ detail }) => {
if (detail.options.direction === 'right') {
if (onNext()) detail.preventNavigation();
} else if (detail.options.direction === 'left') {
if (onPrevious()) detail.preventNavigation();
} else if (detail.options.direction === 'up') {
Selectable.giveFocus('left', true);
detail.preventNavigation();
}
}}
/>
<div class="flex flex-1 z-10">

View File

@@ -8,10 +8,10 @@
</script>
<Container
handleNavigateOut={{
left: () => {
on:navigate={({ detail }) => {
if (detail.direction === 'left' && detail.options.willLeaveContainer) {
modalStack.close(modalId);
return true;
detail.preventNavigation();
}
}}
focusOnMount

View File

@@ -54,8 +54,10 @@
<Container
class="h-screen flex flex-col py-12 px-20 relative"
on:enter={scrollIntoView({ top: 0 })}
handleNavigateOut={{
down: () => episodesSelectable?.focusChild(1)
on:navigate={({ detail }) => {
if (detail.direction === 'down') {
if (episodesSelectable?.focusChild(1)) detail.preventNavigation();
}
}}
>
<HeroCarousel

View File

@@ -92,7 +92,6 @@
</script>
<Container
handleNavigateOut={{}}
focusOnMount
trapFocus
class={classNames('fixed inset-0 bg-black overflow-auto', {