frame bg: normalize false flag to transparent
This commit is contained in:
@@ -509,17 +509,16 @@ export const restoreElement = (
|
||||
name: element.name ?? null,
|
||||
});
|
||||
case "frame":
|
||||
const hasBackgroundEnabled =
|
||||
typeof (element as any).backgroundEnabled === "boolean";
|
||||
const backgroundEnabled = hasBackgroundEnabled
|
||||
? (element as any).backgroundEnabled
|
||||
: false;
|
||||
const backgroundEnabled =
|
||||
typeof (element as any).backgroundEnabled === "boolean"
|
||||
? (element as any).backgroundEnabled
|
||||
: false;
|
||||
return restoreElementWithProperties(element, {
|
||||
name: element.name ?? null,
|
||||
backgroundEnabled,
|
||||
...(hasBackgroundEnabled
|
||||
? {}
|
||||
: { backgroundColor: DEFAULT_ELEMENT_PROPS.backgroundColor }),
|
||||
...(!backgroundEnabled
|
||||
? { backgroundColor: DEFAULT_ELEMENT_PROPS.backgroundColor }
|
||||
: {}),
|
||||
});
|
||||
|
||||
// Don't use default case so as to catch a missing an element type case.
|
||||
|
||||
@@ -118,6 +118,22 @@ describe("restoreElements", () => {
|
||||
expect(restoredFrame.backgroundEnabled).toBe(false);
|
||||
});
|
||||
|
||||
it("should normalize frame background color when backgroundEnabled is false", () => {
|
||||
const frame = API.createElement({
|
||||
type: "frame",
|
||||
backgroundColor: "#ffc9c9",
|
||||
});
|
||||
frame.backgroundEnabled = false;
|
||||
|
||||
const restoredFrame = restore.restoreElements(
|
||||
[frame],
|
||||
null,
|
||||
)[0] as ExcalidrawFrameElement;
|
||||
|
||||
expect(restoredFrame.backgroundColor).toBe("transparent");
|
||||
expect(restoredFrame.backgroundEnabled).toBe(false);
|
||||
});
|
||||
|
||||
it("should preserve frame backgroundEnabled when present", () => {
|
||||
const frame = API.createElement({
|
||||
type: "frame",
|
||||
@@ -130,6 +146,7 @@ describe("restoreElements", () => {
|
||||
null,
|
||||
)[0] as ExcalidrawFrameElement;
|
||||
|
||||
expect(restoredFrame.backgroundColor).toBe("#ffc9c9");
|
||||
expect(restoredFrame.backgroundEnabled).toBe(true);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user