diff --git a/src/Container.svelte b/src/Container.svelte index 0f19825..46d116a 100644 --- a/src/Container.svelte +++ b/src/Container.svelte @@ -1,9 +1,10 @@ {#if $isTmdbSeasonsLoading} @@ -65,19 +87,21 @@ handleSelectSeason(season)} + on:click={() => focusFirstEpisodeOf(season)} handleFocus={(s, options) => { - const element = s.getHtmlElement(); - if (element) scrollElementIntoView(element, { horizontal: 64 }); - if (options.didNavigate) handleSelectSeason(season); + scrollIntoView({ horizontal: 64 })(s); + if (options.setFocusedElement) focusFirstEpisodeOf(season); }} bind:this={containers[`season-${season.season_number}`]} >
Season {season.season_number}
@@ -93,8 +117,9 @@ handleFocus={(s, options) => { scrollIntoView({ left: 64 + 16 })(s); selectedTmdbEpisode = episode; - if (options.didNavigate) handleFocusEpisode(episode); + if (options.setFocusedElement) focusSeasonOf(episode); }} + focusOnClick >
diff --git a/src/lib/components/SeriesPage/SeriesPage.svelte b/src/lib/components/SeriesPage/SeriesPage.svelte index 71dbfe3..0686709 100644 --- a/src/lib/components/SeriesPage/SeriesPage.svelte +++ b/src/lib/components/SeriesPage/SeriesPage.svelte @@ -49,7 +49,7 @@ let episodesSelectable: Selectable; let scrollTop: number; - $: showEpisodeInfo = scrollTop > 200; + $: showEpisodeInfo = scrollTop > 140; @@ -58,11 +58,7 @@ class="h-screen flex flex-col py-12 px-20 relative" handleFocus={scrollIntoView({ top: 0 })} handleNavigateOut={{ - down: () => { - console.log('Here', episodesSelectable); - episodesSelectable?.focusChildren(1); - return true; - } + down: () => episodesSelectable?.focusChildren(1) }} > - + diff --git a/src/lib/selectable.ts b/src/lib/selectable.ts index 54c3cdf..0ffc4d1 100644 --- a/src/lib/selectable.ts +++ b/src/lib/selectable.ts @@ -13,14 +13,14 @@ export type NavigationActions = { }; type FocusHandlerOptions = { - didNavigate: boolean; + setFocusedElement: boolean; propagate: boolean; stopPropagation: () => void; }; const createFocusHandlerOptions = (): FocusHandlerOptions => { const options: Partial = { - didNavigate: true, + setFocusedElement: true, propagate: true }; @@ -94,7 +94,7 @@ export class Selectable { return this; } - focus(didNavigate = true) { + focus(options: Partial = {}) { function propagateFocusUpdates( options: FocusHandlerOptions, parent: Selectable, @@ -115,12 +115,12 @@ export class Selectable { const focusIndex = get(this.focusIndex); if (this.children[focusIndex]?.isFocusable()) { - this.children[focusIndex]?.focus(didNavigate); + this.children[focusIndex]?.focus(options); } else { let i = focusIndex; while (i < this.children.length) { if (this.children[i]?.isFocusable()) { - this.children[i]?.focus(didNavigate); + this.children[i]?.focus(options); // this.onFocus?.(this); return; } @@ -129,7 +129,7 @@ export class Selectable { i = focusIndex - 1; while (i >= 0) { if (this.children[i]?.isFocusable()) { - this.children[i]?.focus(didNavigate); + this.children[i]?.focus(options); // this.onFocus?.(this); return; } @@ -137,21 +137,23 @@ export class Selectable { } } } else if (this.htmlElement) { - const options = createFocusHandlerOptions(); - options.didNavigate = didNavigate; - propagateFocusUpdates(options, this); + const _options: FocusHandlerOptions = { + ...createFocusHandlerOptions(), + ...options + }; + propagateFocusUpdates(_options, this); - if (didNavigate) { + if (_options.setFocusedElement) { this.htmlElement.focus({ preventScroll: true }); Selectable.focusedObject.set(this); } } } - focusChildren(index: number, didNavigate = true): boolean { + focusChildren(index: number, options?: Partial): boolean { const child = this.children[index]; if (child && child.isFocusable()) { - child.focus(didNavigate); + child.focus(options); return true; }