fix(chess): lift dragged piece above all other pieces
The piece`s own z-index could only stack within its grid cell`s context, so when translated over neighbouring cells it rendered underneath their pieces. Promote the hosting cell to z-50 while it holds the dragged piece so the whole cell (and piece inside) float above the board.
This commit is contained in:
parent
d4622b2cb4
commit
8b8a5179ec
1 changed files with 8 additions and 2 deletions
|
|
@ -125,14 +125,20 @@ export function Board({ facts, legalMoves, onMove, turn, lastMove, checkedKingSq
|
|||
const isCheckedKing = checkedKingSquare === sq;
|
||||
|
||||
const piece = pieces.get(sq);
|
||||
|
||||
// While this cell hosts the actively-dragged piece, lift the whole
|
||||
// cell above all siblings in the grid. Z-index inside the <Piece>
|
||||
// component can only stack within its own cell's stacking context,
|
||||
// so the piece would render *under* neighbouring cells' pieces when
|
||||
// translated over them. Promoting the cell itself fixes that.
|
||||
const isHostingDragged = draggedPiece?.square === sq;
|
||||
|
||||
squares.push(
|
||||
<div
|
||||
key={sq}
|
||||
data-square={algebraic}
|
||||
className={`relative aspect-square flex items-center justify-center ${
|
||||
isDark ? 'bg-[#B58863]' : 'bg-[#F0D9B5]'
|
||||
} shadow-[inset_0_0_8px_rgba(0,0,0,0.15)]`}
|
||||
} shadow-[inset_0_0_8px_rgba(0,0,0,0.15)] ${isHostingDragged ? 'z-50' : ''}`}
|
||||
onDragOver={(e) => handleDragOver(e, sq)}
|
||||
onDrop={(e) => handleDrop(e, sq)}
|
||||
>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue