Skip to content

Commit

Permalink
Fix misalignment of arrows when coords are outside
Browse files Browse the repository at this point in the history
The issue was caused by the SVG layer fitting to the dimensions of the
outer wrapper, not the board. When `coords` is set to `outside`, the
board is smaller than the outer wrapper.

Fixes this by adding an inner "board wrapper" that contains the board
and arrows.
  • Loading branch information
mganjoo committed Dec 22, 2023
1 parent 6c19a56 commit b705abb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Fix misalignment of arrows with board when `coords` is set to `outside`.

## [1.1.2] - 2023-11-07

- Small style fixes
Expand Down
10 changes: 8 additions & 2 deletions src/GChessBoardElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export class GChessBoardElement extends HTMLElement {
private _shadow: ShadowRoot;
private _style: HTMLStyleElement;
private _wrapper: HTMLDivElement;
private _boardArrowsWrapper: HTMLDivElement;
private _board: Board;
private _fileCoords: Coordinates;
private _rankCoords: Coordinates;
Expand All @@ -175,6 +176,11 @@ export class GChessBoardElement extends HTMLElement {
});
this._shadow.appendChild(this._wrapper);

this._boardArrowsWrapper = makeHTMLElement("div", {
classes: ["board-arrows-wrapper"],
});
this._wrapper.appendChild(this._boardArrowsWrapper);

this._board = new Board(
{
orientation: GChessBoardElement._DEFAULT_SIDE,
Expand All @@ -183,7 +189,7 @@ export class GChessBoardElement extends HTMLElement {
(e) => this.dispatchEvent(e),
this._shadow
);
this._wrapper.appendChild(this._board.element);
this._boardArrowsWrapper.appendChild(this._board.element);

this._fileCoords = new Coordinates({
direction: "file",
Expand All @@ -199,7 +205,7 @@ export class GChessBoardElement extends HTMLElement {
this._wrapper.appendChild(this._rankCoords.element);

this._arrows = new Arrows(GChessBoardElement._DEFAULT_SIDE);
this._wrapper.appendChild(this._arrows.element);
this._boardArrowsWrapper.appendChild(this._arrows.element);
}

connectedCallback() {
Expand Down
13 changes: 9 additions & 4 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,19 @@ table.dragging {
cursor: grab;
}

/***************
* Coordinates *
***************/
/***********
* Wrappes *
***********/

.wrapper {
.wrapper,
.board-arrows-wrapper {
position: relative;
}

/***************
* Coordinates *
***************/

.coords {
display: none;
position: absolute;
Expand Down

0 comments on commit b705abb

Please sign in to comment.