Skip to content

Commit d2ed9fa

Browse files
cmath10bcakmakoglu
authored andcommitted
feat(core): add dom attributes option for nodes and edges (#1861)
Signed-off-by: braks <[email protected]>
1 parent eec568c commit d2ed9fa

File tree

4 files changed

+51
-10
lines changed

4 files changed

+51
-10
lines changed

packages/core/src/components/Edges/EdgeWrapper.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,20 +192,22 @@ const EdgeWrapper = defineComponent({
192192
inactive: !isSelectable.value && !hooks.value.edgeClick.hasListeners(),
193193
},
194194
],
195+
'tabIndex': isFocusable.value ? 0 : undefined,
196+
'aria-label':
197+
edge.value.ariaLabel === null
198+
? undefined
199+
: edge.value.ariaLabel ?? `Edge from ${edge.value.source} to ${edge.value.target}`,
200+
'aria-describedby': isFocusable.value ? `${ARIA_EDGE_DESC_KEY}-${vueFlowId}` : undefined,
201+
'aria-roledescription': 'edge',
202+
'role': isFocusable.value ? 'group' : 'img',
203+
...edge.value.domAttributes,
195204
'onClick': onEdgeClick,
196205
'onContextmenu': onEdgeContextMenu,
197206
'onDblclick': onDoubleClick,
198207
'onMouseenter': onEdgeMouseEnter,
199208
'onMousemove': onEdgeMouseMove,
200209
'onMouseleave': onEdgeMouseLeave,
201210
'onKeyDown': isFocusable.value ? onKeyDown : undefined,
202-
'tabIndex': isFocusable.value ? 0 : undefined,
203-
'aria-label':
204-
edge.value.ariaLabel === null
205-
? undefined
206-
: edge.value.ariaLabel || `Edge from ${edge.value.source} to ${edge.value.target}`,
207-
'aria-describedby': isFocusable.value ? `${ARIA_EDGE_DESC_KEY}-${vueFlowId}` : undefined,
208-
'role': isFocusable.value ? 'button' : 'img',
209211
},
210212
[
211213
updating.value

packages/core/src/components/Nodes/NodeWrapper.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,11 @@ const NodeWrapper = defineComponent({
283283
...getStyle.value,
284284
},
285285
'tabIndex': isFocusable.value ? 0 : undefined,
286-
'role': isFocusable.value ? 'button' : undefined,
286+
'role': isFocusable.value ? 'group' : undefined,
287287
'aria-describedby': disableKeyboardA11y.value ? undefined : `${ARIA_NODE_DESC_KEY}-${vueFlowId}`,
288288
'aria-label': node.ariaLabel,
289+
'aria-roledescription': 'node',
290+
...node.domAttributes,
289291
'onMouseenter': onMouseEnter,
290292
'onMousemove': onMouseMove,
291293
'onMouseleave': onMouseLeave,

packages/core/src/types/edge.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CSSProperties, Component, VNode } from 'vue'
1+
import type { CSSProperties, Component, SVGAttributes, VNode } from 'vue'
22
import type { ClassFunc, ElementData, Position, StyleFunc, Styles } from './flow'
33
import type { GraphNode } from './node'
44
import type { EdgeComponent, EdgeTextProps } from './components'
@@ -108,6 +108,24 @@ export interface DefaultEdge<
108108
/** Aria label for edge (a11y) */
109109
zIndex?: number
110110
ariaLabel?: string | null
111+
/**
112+
* General escape hatch for adding custom attributes to the edge's DOM element.
113+
*/
114+
domAttributes?: Omit<
115+
SVGAttributes,
116+
| 'id'
117+
| 'style'
118+
| 'className'
119+
| 'role'
120+
| 'aria-label'
121+
| 'onClick'
122+
| 'onMouseenter'
123+
| 'onMousemove'
124+
| 'onMouseleave'
125+
| 'onContextmenu'
126+
| 'onDblclick'
127+
| 'onKeyDown'
128+
>
111129
}
112130

113131
export interface SmoothStepPathOptions {

packages/core/src/types/node.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Component, VNode } from 'vue'
1+
import type { Component, HTMLAttributes, VNode } from 'vue'
22
import type { ClassFunc, Dimensions, ElementData, Position, StyleFunc, Styles, XYPosition, XYZPosition } from './flow'
33
import type { NodeComponent } from './components'
44
import type { HandleConnectable, HandleElement, ValidConnectionFunc } from './handle'
@@ -109,6 +109,25 @@ export interface Node<Data = ElementData, CustomEvents extends Record<string, Cu
109109
events?: Partial<NodeEventsHandler<CustomEvents>>
110110
zIndex?: number
111111
ariaLabel?: string
112+
113+
/**
114+
* General escape hatch for adding custom attributes to the node's DOM element.
115+
*/
116+
domAttributes?: Omit<
117+
HTMLAttributes,
118+
| 'id'
119+
| 'style'
120+
| 'className'
121+
| 'draggable'
122+
| 'aria-label'
123+
| 'onMouseenter'
124+
| 'onMousemove'
125+
| 'onMouseleave'
126+
| 'onContextmenu'
127+
| 'onClick'
128+
| 'onDblclick'
129+
| 'onKeydown'
130+
>
112131
}
113132

114133
export interface GraphNode<

0 commit comments

Comments
 (0)