Skip to content

How to prevent a button from being dragged by using a custom Keyboard Sensor? #1493

Closed Answered by mattbal
mattbal asked this question in Q&A
Discussion options

You must be logged in to vote

So far the only solution I've come up with is to do this:

// Container.tsx
return (
  <div // this node is sent to active.node
    ref={ref}
    tabIndex={0}
    {...handleProps} // handleProps={{...attributes, ...listeners }}
  >
    <div>
      <p>{label}</p>
      <button
        onClick={() => console.log('test')}
        onKeyDown={(e) => {
          if (e.key === 'Enter' || e.key === 'Space') {
            console.log('test)
            e.stopPropagation(); // prevent the event from bubbling (and therefore triggering listeners on parent div)
          }
          }}
        data-no-dnd='true'
      >
        Delete
      </button>
    </div>
    <ul>{children}</ul>
  </div>
)

Is the…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mattbal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant