chore: swap role for ariaRole, add svelte
This commit is contained in:
@@ -25,10 +25,9 @@ const initialNodes: Node[] = [
|
|||||||
{
|
{
|
||||||
id: '1',
|
id: '1',
|
||||||
type: 'input',
|
type: 'input',
|
||||||
data: { label: 'Focusable Node' },
|
data: { label: 'Node 1' },
|
||||||
position: { x: 250, y: 5 },
|
position: { x: 250, y: 5 },
|
||||||
className: 'light',
|
className: 'light',
|
||||||
role: null,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '2',
|
id: '2',
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ export function NodeWrapper<NodeType extends Node>({
|
|||||||
nodeTypes,
|
nodeTypes,
|
||||||
nodeClickDistance,
|
nodeClickDistance,
|
||||||
onError,
|
onError,
|
||||||
role,
|
|
||||||
}: NodeWrapperProps<NodeType>) {
|
}: NodeWrapperProps<NodeType>) {
|
||||||
const { node, internals, isParent } = useStore((s) => {
|
const { node, internals, isParent } = useStore((s) => {
|
||||||
const node = s.nodeLookup.get(id)! as InternalNode<NodeType>;
|
const node = s.nodeLookup.get(id)! as InternalNode<NodeType>;
|
||||||
@@ -192,7 +191,7 @@ export function NodeWrapper<NodeType extends Node>({
|
|||||||
onDoubleClick={onDoubleClickHandler}
|
onDoubleClick={onDoubleClickHandler}
|
||||||
onKeyDown={isFocusable ? onKeyDown : undefined}
|
onKeyDown={isFocusable ? onKeyDown : undefined}
|
||||||
tabIndex={isFocusable ? 0 : undefined}
|
tabIndex={isFocusable ? 0 : undefined}
|
||||||
role={node.role === null ? undefined : node.role || (isFocusable ? 'button' : undefined)}
|
role={node.ariaRole === null ? undefined : node.ariaRole || (isFocusable ? 'button' : undefined)}
|
||||||
aria-describedby={disableKeyboardA11y ? undefined : `${ARIA_NODE_DESC_KEY}-${rfId}`}
|
aria-describedby={disableKeyboardA11y ? undefined : `${ARIA_NODE_DESC_KEY}-${rfId}`}
|
||||||
aria-label={node.ariaLabel}
|
aria-label={node.ariaLabel}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -170,6 +170,7 @@ function ReactFlow<NodeType extends Node = Node, EdgeType extends Edge = Edge>(
|
|||||||
ref={ref}
|
ref={ref}
|
||||||
className={cc(['react-flow', className, colorModeClassName])}
|
className={cc(['react-flow', className, colorModeClassName])}
|
||||||
id={id}
|
id={id}
|
||||||
|
role="application"
|
||||||
>
|
>
|
||||||
<Wrapper
|
<Wrapper
|
||||||
nodes={nodes}
|
nodes={nodes}
|
||||||
|
|||||||
@@ -1,12 +1,5 @@
|
|||||||
import type { CSSProperties, MouseEvent as ReactMouseEvent } from 'react';
|
import type { CSSProperties, MouseEvent as ReactMouseEvent } from 'react';
|
||||||
import type {
|
import type { CoordinateExtent, NodeBase, OnError, NodeProps as NodePropsBase, InternalNodeBase } from '@xyflow/system';
|
||||||
CoordinateExtent,
|
|
||||||
NodeBase,
|
|
||||||
OnError,
|
|
||||||
NodeProps as NodePropsBase,
|
|
||||||
InternalNodeBase,
|
|
||||||
NodeRole,
|
|
||||||
} from '@xyflow/system';
|
|
||||||
|
|
||||||
import { NodeTypes } from './general';
|
import { NodeTypes } from './general';
|
||||||
|
|
||||||
@@ -65,7 +58,6 @@ export type NodeWrapperProps<NodeType extends Node> = {
|
|||||||
nodeExtent?: CoordinateExtent;
|
nodeExtent?: CoordinateExtent;
|
||||||
onError?: OnError;
|
onError?: OnError;
|
||||||
nodeClickDistance?: number;
|
nodeClickDistance?: number;
|
||||||
role?: NodeRole;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -252,7 +252,7 @@
|
|||||||
: undefined}
|
: undefined}
|
||||||
onkeydown={focusable ? onKeyDown : undefined}
|
onkeydown={focusable ? onKeyDown : undefined}
|
||||||
tabIndex={focusable ? 0 : undefined}
|
tabIndex={focusable ? 0 : undefined}
|
||||||
role={focusable ? 'button' : undefined}
|
role={node.ariaRole === null ? undefined : node.ariaRole || (focusable ? 'button' : undefined)}
|
||||||
aria-describedby={store.disableKeyboardA11y
|
aria-describedby={store.disableKeyboardA11y
|
||||||
? undefined
|
? undefined
|
||||||
: `${ARIA_NODE_DESC_KEY}-${store.flowId}`}
|
: `${ARIA_NODE_DESC_KEY}-${store.flowId}`}
|
||||||
|
|||||||
@@ -79,7 +79,8 @@ export type NodeBase<
|
|||||||
* When not specified, focusable nodes default to 'button' role.
|
* When not specified, focusable nodes default to 'button' role.
|
||||||
* @default "button" (for focusable nodes)
|
* @default "button" (for focusable nodes)
|
||||||
*/
|
*/
|
||||||
role?: NodeRole;
|
|
||||||
|
ariaRole?: AriaRole;
|
||||||
measured?: {
|
measured?: {
|
||||||
width?: number;
|
width?: number;
|
||||||
height?: number;
|
height?: number;
|
||||||
@@ -187,4 +188,4 @@ export type Align = 'center' | 'start' | 'end';
|
|||||||
|
|
||||||
export type NodeLookup<NodeType extends InternalNodeBase = InternalNodeBase> = Map<string, NodeType>;
|
export type NodeLookup<NodeType extends InternalNodeBase = InternalNodeBase> = Map<string, NodeType>;
|
||||||
export type ParentLookup<NodeType extends InternalNodeBase = InternalNodeBase> = Map<string, Map<string, NodeType>>;
|
export type ParentLookup<NodeType extends InternalNodeBase = InternalNodeBase> = Map<string, Map<string, NodeType>>;
|
||||||
export type NodeRole = 'button' | 'group' | 'listitem' | 'application' | 'region' | 'none' | null;
|
export type AriaRole = 'button' | 'group' | 'listitem' | 'application' | 'region' | 'none' | null;
|
||||||
|
|||||||
Reference in New Issue
Block a user