Setting focus using element ids

This commit is contained in:
Alabhya Jindal 2024-02-28 00:16:15 +05:30
parent 060ccbb40a
commit cf448848d0

View File

@ -44,7 +44,9 @@
}} }}
on:keydown={(e) => { on:keydown={(e) => {
e.preventDefault(); e.preventDefault();
if ($selectedFiles.length > 1) return; if ($selectedFiles.length !== 1) return;
if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown') return;
const selectedFileIndex = sortedFiles.findIndex((sf) => sf.id === $selectedFiles[0].id); const selectedFileIndex = sortedFiles.findIndex((sf) => sf.id === $selectedFiles[0].id);
if (e.key === 'ArrowUp') { if (e.key === 'ArrowUp') {
@ -54,6 +56,9 @@
if (selectedFileIndex + 1 > sortedFiles.length - 1) return; if (selectedFileIndex + 1 > sortedFiles.length - 1) return;
$selectedFiles = [sortedFiles[selectedFileIndex + 1]]; $selectedFiles = [sortedFiles[selectedFileIndex + 1]];
} }
const fileElement = document.getElementById('file-' + $selectedFiles[0].id);
fileElement?.focus();
}} }}
/> />
{/each} {/each}