Skip to content

Commit

Permalink
Add getDOMWidth #Fix Sidebar width default to minimum
Browse files Browse the repository at this point in the history
  • Loading branch information
fatih-erikli committed Sep 18, 2023
1 parent 4f270af commit 8326519
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/fontra/views/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ export class EditorController {

const resizeObserver = new ResizeObserver(([element]) => {
const totalWidth = this.sidebars.reduce(
(total, sidebar) => total + sidebar.getStoredWidth(),
(total, sidebar) => total + sidebar.getDOMWidth(),
0
);
if (element.contentRect.width < totalWidth + MIN_CANVAS_SPACE) {
Expand Down
19 changes: 14 additions & 5 deletions src/fontra/views/editor/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,20 @@ export class Sidebar {
const sidebarWidth = localStorage.getItem(
`fontra-sidebar-width-${this.identifier}`
);
let width = clamp(parseInt(sidebarWidth), MIN_SIDEBAR_WIDTH, MAX_SIDEBAR_WIDTH);
if (isNaN(width)) {
width = MIN_SIDEBAR_WIDTH;

if (!sidebarWidth) {
return;
}
return width;

return clamp(parseInt(sidebarWidth), MIN_SIDEBAR_WIDTH, MAX_SIDEBAR_WIDTH);
}

getDOMWidth() {
return parseInt(
getComputedStyle(document.documentElement)
.getPropertyValue(`--sidebar-content-width-${this.identifier}`)
.replace("px", "")
);
}

initResizeGutter() {
Expand Down Expand Up @@ -157,7 +166,7 @@ export class Sidebar {
document.addEventListener("pointerup", onPointerUp, { once: true });
});
const sidebarWidth = this.getStoredWidth();
if (sidebarWidth) {
if (sidebarWidth !== undefined) {
this.applyWidth(sidebarWidth);
}
}
Expand Down

0 comments on commit 8326519

Please sign in to comment.