Skip to content

How to restrict dragging nodes by an axis? #904

Answered by bcakmakoglu
ayZagen asked this question in Q&A
Discussion options

You must be logged in to vote

There's no option to restrict axis of movement.
You could do this by handling node changes yourself something like this

onNodesChange((changes) => {
  const positionChanges = changes.filter((change) => change.type === 'position') as NodePositionChange[]

  if (positionChanges.length) {
    applyNodeChanges(
      positionChanges.map((change) => {
        return {
          ...change,
          position: {
            y: change.from.y,
            x: change.position.x,
          },
        }
      }),
    )
  } else {
    applyNodeChanges(changes)
  }
})
<VueFlow v-model="elements" :apply-default="false" />

Here's an example

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ayZagen
Comment options

@bcakmakoglu
Comment options

Answer selected by bcakmakoglu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants