diff --git a/web/src/lib/components/assets/thumbnail/__test__/thumbnail.spec.ts b/web/src/lib/components/assets/thumbnail/__test__/thumbnail.spec.ts index f763e1d094..8d71b826af 100644 --- a/web/src/lib/components/assets/thumbnail/__test__/thumbnail.spec.ts +++ b/web/src/lib/components/assets/thumbnail/__test__/thumbnail.spec.ts @@ -2,7 +2,7 @@ import { getIntersectionObserverMock } from '$lib/__mocks__/intersection-observe import Thumbnail from '$lib/components/assets/thumbnail/thumbnail.svelte'; import { getTabbable } from '$lib/utils/focus-util'; import { assetFactory } from '@test-data/factories/asset-factory'; -import { fireEvent, render, screen } from '@testing-library/svelte'; +import { fireEvent, render } from '@testing-library/svelte'; vi.hoisted(() => { Object.defineProperty(globalThis, 'matchMedia', { diff --git a/web/src/lib/components/shared-components/gallery-viewer/gallery-viewer.svelte b/web/src/lib/components/shared-components/gallery-viewer/gallery-viewer.svelte index d879dae8ab..09c126e0df 100644 --- a/web/src/lib/components/shared-components/gallery-viewer/gallery-viewer.svelte +++ b/web/src/lib/components/shared-components/gallery-viewer/gallery-viewer.svelte @@ -22,6 +22,7 @@ import type { AssetInteraction } from '$lib/stores/asset-interaction.svelte'; import { debounce } from 'lodash-es'; import { getJustifiedLayoutFromAssets, type CommonJustifiedLayout } from '$lib/utils/layout-utils'; + import { focusNext } from '$lib/utils/focus-util'; interface Props { assets: AssetResponseDto[]; @@ -259,25 +260,8 @@ } }; - const focusNextAsset = () => { - if (assetInteraction.focussedAssetId === null && assets.length > 0) { - assetInteraction.focussedAssetId = assets[0].id; - } else if (assetInteraction.focussedAssetId !== null && assets.length > 0) { - const currentIndex = assets.findIndex((a) => a.id === assetInteraction.focussedAssetId); - if (currentIndex !== -1 && currentIndex + 1 < assets.length) { - assetInteraction.focussedAssetId = assets[currentIndex + 1].id; - } - } - }; - - const focusPreviousAsset = () => { - if (assetInteraction.focussedAssetId !== null && assets.length > 0) { - const currentIndex = assets.findIndex((a) => a.id === assetInteraction.focussedAssetId); - if (currentIndex >= 1) { - assetInteraction.focussedAssetId = assets[currentIndex - 1].id; - } - } - }; + const focusNextAsset = () => focusNext((element) => element.dataset.thumbnailFocusContainer !== undefined, true); + const focusPreviousAsset = () => focusNext((element) => element.dataset.thumbnailFocusContainer !== undefined, false); let shortcutList = $derived( (() => {