feat(dashboard): keyboard navigation between list items
This commit is contained in:
parent
07936ec561
commit
b70f8d27e7
@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Card, CardHeader, CardBody, CardTitle, Alert, Accordion, AccordionItem, InputGroupText, InputGroup, Input, Row, Col, Spinner, Button, Tooltip, Label } from 'sveltestrap';
|
import { Card, CardHeader, CardBody, Alert, Collapse, Row, Col, Spinner, Button, Tooltip } from 'sveltestrap';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { Link, useParams } from 'svelte-navigator';
|
import { link, useParams } from 'svelte-navigator';
|
||||||
|
|
||||||
import FaLock from 'svelte-icons/fa/FaLock.svelte';
|
import FaLock from 'svelte-icons/fa/FaLock.svelte';
|
||||||
import FaUserCircle from 'svelte-icons/fa/FaUserCircle.svelte';
|
import FaUserCircle from 'svelte-icons/fa/FaUserCircle.svelte';
|
||||||
@ -124,6 +124,38 @@
|
|||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let cardIndexArray = [];
|
||||||
|
|
||||||
|
function skipToNextItem(event, index: number) {
|
||||||
|
let el;
|
||||||
|
|
||||||
|
if (event.key === "ArrowDown") {
|
||||||
|
if (cardIndexArray[index + 1]) el = cardIndexArray[index + 1];
|
||||||
|
else el = cardIndexArray[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.key === "ArrowUp") {
|
||||||
|
if (cardIndexArray[index - 1]) el = cardIndexArray[index - 1];
|
||||||
|
else el = cardIndexArray[cardIndexArray.length - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (el) {
|
||||||
|
event.preventDefault();
|
||||||
|
el.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let isOpenArray = [];
|
||||||
|
|
||||||
|
function toggleCard(index: number) {
|
||||||
|
if (isOpenArray[index] === true) {
|
||||||
|
isOpenArray[index] = false;
|
||||||
|
cardIndexArray[index].classList.add("collapsed");
|
||||||
|
} else {
|
||||||
|
isOpenArray[index] = true;
|
||||||
|
cardIndexArray[index].classList.remove("collapsed");
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ListControl {itemType} {isPublic} {memberList} {groups} {groupList} {list} bind:finalList={processedList} bind:searchValue bind:searchBy bind:itemsPerPageValue bind:currentPage />
|
<ListControl {itemType} {isPublic} {memberList} {groups} {groupList} {list} bind:finalList={processedList} bind:searchValue bind:searchBy bind:itemsPerPageValue bind:currentPage />
|
||||||
@ -156,10 +188,11 @@
|
|||||||
|
|
||||||
|
|
||||||
{#if settings && settings.accessibility ? (!settings.accessibility.expandedcards && !settings.accessibility.pagelinks) : true}
|
{#if settings && settings.accessibility ? (!settings.accessibility.expandedcards && !settings.accessibility.pagelinks) : true}
|
||||||
<Accordion class="my-3" stayOpen>
|
|
||||||
{#each slicedList as item, index (item.id + index)}
|
{#each slicedList as item, index (item.id + index)}
|
||||||
<AccordionItem>
|
<Card>
|
||||||
<CardsHeader {item} slot="header">
|
<h2 class="accordion-header">
|
||||||
|
<button class="w-100 accordion-button collapsed" bind:this={cardIndexArray[index]} on:click={() => toggleCard(index)} on:keydown={(e) => skipToNextItem(e, index)}>
|
||||||
|
<CardsHeader {item}>
|
||||||
<div slot="icon">
|
<div slot="icon">
|
||||||
{#if isPublic || item.privacy.visibility === "public"}
|
{#if isPublic || item.privacy.visibility === "public"}
|
||||||
{#if itemType === "member"}
|
{#if itemType === "member"}
|
||||||
@ -172,17 +205,23 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</CardsHeader>
|
</CardsHeader>
|
||||||
|
</button>
|
||||||
|
</h2>
|
||||||
|
<Collapse isOpen={isOpenArray[index]}>
|
||||||
|
<CardBody>
|
||||||
{#if itemType === "member"}
|
{#if itemType === "member"}
|
||||||
<MemberBody on:deletion={updateDelete} bind:isPublic bind:groups bind:member={item} />
|
<MemberBody on:deletion={updateDelete} bind:isPublic bind:groups bind:member={item} />
|
||||||
{:else if itemType === "group"}
|
{:else if itemType === "group"}
|
||||||
<GroupBody on:deletion={updateDelete} {isPublic} {members} bind:group={item} />
|
<GroupBody on:deletion={updateDelete} {isPublic} {members} bind:group={item} />
|
||||||
{/if}
|
{/if}
|
||||||
</AccordionItem>
|
</CardBody>
|
||||||
|
</Collapse>
|
||||||
|
</Card>
|
||||||
{/each}
|
{/each}
|
||||||
</Accordion>
|
|
||||||
{:else if settings.accessibility.expandedcards}
|
{:else if settings.accessibility.expandedcards}
|
||||||
{#each slicedList as item, index (item.id + index)}
|
{#each slicedList as item, index (item.id + index)}
|
||||||
<Card class="mb-3">
|
<Card class="mb-3">
|
||||||
|
<div bind:this={cardIndexArray[index]} on:keydown={(e) => skipToNextItem(e, index)} tabindex={0}>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardsHeader {item}>
|
<CardsHeader {item}>
|
||||||
<div slot="icon">
|
<div slot="icon">
|
||||||
@ -198,6 +237,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</CardsHeader>
|
</CardsHeader>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
</div>
|
||||||
<CardBody>
|
<CardBody>
|
||||||
{#if itemType === "member"}
|
{#if itemType === "member"}
|
||||||
<MemberBody on:deletion={updateDelete} bind:isPublic bind:groups bind:member={item} />
|
<MemberBody on:deletion={updateDelete} bind:isPublic bind:groups bind:member={item} />
|
||||||
@ -211,7 +251,7 @@
|
|||||||
<div class="my-3">
|
<div class="my-3">
|
||||||
{#each slicedList as item, index (item.id + index)}
|
{#each slicedList as item, index (item.id + index)}
|
||||||
<Card>
|
<Card>
|
||||||
<Link class="accordion-button collapsed" style="text-decoration: none;" to={getItemLink(item)}>
|
<a class="accordion-button collapsed" style="text-decoration: none;" href={getItemLink(item)} bind:this={cardIndexArray[index]} on:keydown={(e) => skipToNextItem(e, index)} use:link >
|
||||||
<CardsHeader {item}>
|
<CardsHeader {item}>
|
||||||
<div slot="icon">
|
<div slot="icon">
|
||||||
{#if isPublic || item.privacy.visibility === "public"}
|
{#if isPublic || item.privacy.visibility === "public"}
|
||||||
@ -225,7 +265,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</CardsHeader>
|
</CardsHeader>
|
||||||
</Link>
|
</a>
|
||||||
</Card>
|
</Card>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user