Skip to content

Commit 926d230

Browse files
authored
fix(graphics context setting): opacity = 1 when args.opacity is zero (falsy value) (#134)
* opacity is no longer 1 when explicitly set to 0
1 parent 669c262 commit 926d230

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

models/GraphicsContextSettings/GraphicsContextSettings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class GraphicsContextSettings {
4040
} else {
4141
Object.assign(this, GraphicsContextSettings.Model, args, {
4242
blendMode: blendModeMap[args.blendMode || 'normal'],
43-
opacity: args.opacity || 1,
43+
opacity: Number.isFinite(args.opacity) ? args.opacity : 1,
4444
});
4545
}
4646
return this;

models/GraphicsContextSettings/GraphicsContextSettings.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,12 @@ describe('GraphicsContextSettings', () => {
1919
const graphicsContextSettings = new GraphicsContextSettings(null, json);
2020
expect(JSON.stringify(json, null, 2)).toEqual(JSON.stringify(graphicsContextSettings, null, 2));
2121
});
22+
23+
it('should correctly handle opacity = 0', () => {
24+
const graphicsContextSettings = new GraphicsContextSettings({
25+
opacity: 0,
26+
});
27+
28+
expect(graphicsContextSettings.opacity).toBe(0);
29+
});
2230
});

0 commit comments

Comments
 (0)