Skip to content

Commit a31812b

Browse files
authored
feat(core): add dom attributes option for nodes (#1861)
feat: Possibility to customize nodes HTML attributes
1 parent eec568c commit a31812b

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const NodeWrapper = defineComponent({
6161
elementsSelectable,
6262
nodesConnectable,
6363
nodesFocusable,
64+
nodesAttrs,
6465
hooks,
6566
} = useVueFlow()
6667

@@ -286,6 +287,8 @@ const NodeWrapper = defineComponent({
286287
'role': isFocusable.value ? 'button' : undefined,
287288
'aria-describedby': disableKeyboardA11y.value ? undefined : `${ARIA_NODE_DESC_KEY}-${vueFlowId}`,
288289
'aria-label': node.ariaLabel,
290+
...nodesAttrs?.value,
291+
...node.attrs,
289292
'onMouseenter': onMouseEnter,
290293
'onMousemove': onMouseMove,
291294
'onMouseleave': onMouseLeave,

packages/core/src/store/state.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ export function useState(): State {
114114

115115
disableKeyboardA11y: false,
116116
ariaLiveMessage: '',
117+
118+
nodesAttrs: {},
117119
}
118120
}
119121

packages/core/src/types/flow.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ export interface FlowProps {
229229
autoPanOnConnect?: boolean
230230
autoPanOnNodeDrag?: boolean
231231
autoPanSpeed?: number
232+
233+
nodesAttrs?: Record<string, any>
232234
}
233235

234236
/**

packages/core/src/types/node.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export interface Node<Data = ElementData, CustomEvents extends Record<string, Cu
109109
events?: Partial<NodeEventsHandler<CustomEvents>>
110110
zIndex?: number
111111
ariaLabel?: string
112+
attrs?: Record<string, any>
112113
}
113114

114115
export interface GraphNode<

0 commit comments

Comments
 (0)