chore(a11y): pass a11y descriptions in svelte

This commit is contained in:
Abbey Yacoe
2025-05-19 15:16:19 +02:00
parent 9e4a9ae65d
commit 36f1d94ca7
4 changed files with 33 additions and 10 deletions
@@ -1,21 +1,32 @@
<script lang="ts" generics="NodeType extends Node = Node, EdgeType extends Edge = Edge">
import type { SvelteFlowStore } from '$lib/store/types';
import type { a11yMessages } from '@xyflow/system';
import type { Node, Edge } from '$lib/types';
import { ARIA_EDGE_DESC_KEY, ARIA_LIVE_MESSAGE, ARIA_NODE_DESC_KEY } from '.';
let { store }: { store: SvelteFlowStore<NodeType, EdgeType> } = $props();
const { store, a11yMessages = {} }: {
store: SvelteFlowStore<NodeType, EdgeType>;
a11yMessages?: Partial<a11yMessages>;
} = $props();
const defaultA11yMessages = {
'a11yDescription.node.default':
'Press enter or space to select a node. Press delete to remove it and escape to cancel.',
'a11yDescription.node.keyboardDisabled':
'Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.',
'a11yDescription.edge.default':
'Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.',
};
</script>
<div id={`${ARIA_NODE_DESC_KEY}-${store.flowId}`} style="display: none;">
Press enter or space to select a node.
{#if !store.disableKeyboardA11y}
You can then use the arrow keys to move the node around.
{/if}
Press delete to remove it and escape to cancel.
{store.disableKeyboardA11y
? a11yMessages['a11yDescription.node.default'] || defaultA11yMessages['a11yDescription.node.default']
: a11yMessages['a11yDescription.node.keyboardDisabled'] || defaultA11yMessages['a11yDescription.node.keyboardDisabled']}
</div>
<div id={`${ARIA_EDGE_DESC_KEY}-${store.flowId}`} style="display: none;">
Press enter or space to select an edge. You can then press delete to remove it or escape to
cancel.
{a11yMessages['a11yDescription.edge.default'] || defaultA11yMessages['a11yDescription.edge.default']}
</div>
{#if !store.disableKeyboardA11y}