-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need to introduce an event before drag start, i.e. "onClick" #24
Comments
I'm looking at chess.com and they record the piece that was clicked and allow you to move the piece by clicking the target square. This is a very nice feature(I use it all of the time on my ipad playing on chess.com)and wasn't implemented in chessboard.js but I definitely want it for Chessboard.jsx.
So have some sort of unique hover styling over a desired target. This seems like a useful feature
Ok, so as of now draggable prop is for the entire board, that is not going to work for your use case. |
@willb335 Yes, I expect that Here though, I need to make the decision on a piece-by-piece basis at the moment dragging begins on a piece. Some pieces are valid to drag (white's move) and some pieces have valid moves (king has no adjacent empty squares) and so I want to prevent the drag operation from even starting. |
Ok, got it. I'll use your suggested signature. Not sure when I'll start on this. I have some time this coming weekend |
perhaps |
@csharptest |
I was looking for this feature for use case 2. I can't find the Demo.js being referred to here. Neither the src/Demo.js in this repository nor the one at https://codesandbox.io/s/lp32ojqzqm?from-embed seems to have anything relevant. Does it provide a way to reject picking up the piece? I'm thinking the handler should return true if the piece is allowed to be picked up and false if not. |
@furrykef see #28 I used: Signature: function( { piece: string, sourceSquare: string } ) => bool Please check out Demo.js again with the 'Conditionally Disable Drag' demo Please let me know if this is a solution for you |
As I said before, I don't know where the Demo.js you refer to is. |
Ok, if you fetch the If you want to see the implementation code for |
That looks fine to me. Thanks. One quibble: I notice the mouse cursor changes to a hand icon when you mouseover a piece, whether that piece is draggable or not. I don't think it should do that when you mouseover a non-draggable piece. It's not remotely an urgent matter for me, though. |
Ok, I'll look into fixing that |
|
Use case 1:
Developing an analysis/play board, I need to be able to record the piece that was clicked (aka select the piece for move). I would then need to use hover for styling the desired target, and again handle the event to move the piece.
Use case 2:
While developing a play board, I want to prevent the user from dragging a piece that is not allowed to be moved. This might be the wrong color, or may be a piece of the correct color with no valid moves.
Suggested signature:
Note:
allowDrag would default to
true
and if the function changes the value tofalse
the drag operation would be cancelled. The event would also need to be fired when no piece was clicked to allow click-to-move behavior defined in use case 1 above.The text was updated successfully, but these errors were encountered: