Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export const Board = forwardRef<BoardRef, BoardProps>(function Board(
if (result.applied && result.fen) {
setInternalFen(result.fen);
}
onMove?.({ from, to });
onMove?.({ from, to, promotion: autoPromoteTo });
return;
}

Expand All @@ -339,7 +339,7 @@ export const Board = forwardRef<BoardRef, BoardProps>(function Board(
if (result.applied && result.fen) {
setInternalFen(result.fen);
}
onMove?.({ from, to });
onMove?.({ from, to, promotion: choice });
} catch {
// Promotion cancelled by consumer — piece stays at origin
}
Expand Down Expand Up @@ -379,7 +379,7 @@ export const Board = forwardRef<BoardRef, BoardProps>(function Board(
if (result.applied && result.fen) {
setInternalFen(result.fen);
}
onMove?.({ from, to });
onMove?.({ from, to, promotion: piece });
},
[promotionState, onMove, boardState],
);
Expand Down Expand Up @@ -417,7 +417,7 @@ export const Board = forwardRef<BoardRef, BoardProps>(function Board(
const result = boardState.applyMove(consumed.from, consumed.to, consumed.promotion);
if (result.applied && result.fen) {
setInternalFen(result.fen);
onMove?.({ from: consumed.from, to: consumed.to });
onMove?.({ from: consumed.from, to: consumed.to, promotion: consumed.promotion });
onHaptic?.('move');
} else {
// Premove was illegal — discard silently
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ export type BoardProps = {

// --- Callbacks ---

/** Called after a visual move is applied */
onMove?: (info: { from: string; to: string }) => void;
/** Called after a visual move is applied. Includes `promotion` when a pawn promotes. */
onMove?: (info: { from: string; to: string; promotion?: PromotionPiece }) => void;
/** Called when a piece is tapped */
onPieceClick?: (square: string, piece: PieceCode) => void;
/** Called when an empty square or opponent piece is tapped */
Expand Down
Loading