Skip to content

Commit 7cd4efa

Browse files
committed
(lint/types/fix): only resize width/height if not set
- previously falsey values like 0, '', null, etc would have been resized, even though something like 0 _did_ set a fixed width/height - this could be considered breaking, so might leave out or revert this commit - and setting it to falsey may have intended it to be resized, bc setting it to 0 etc doesn't really make sense... but idk people can set whatever
1 parent e19871f commit 7cd4efa

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/index.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,11 @@ export class SignatureCanvas extends Component<SignatureCanvasProps> {
9090
this._resizeCanvas()
9191
}
9292

93-
// a few eslint disables of strict-boolean-expressions here because changing
94-
// these lines would be breaking -- 0s, '', null etc are falsey
9593
_resizeCanvas = (): void => {
9694
const canvasProps = this.props.canvasProps ?? {}
9795
const { width, height } = canvasProps
9896
// don't resize if the canvas has fixed width and height
99-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
100-
if (width && height) {
97+
if (typeof width !== 'undefined' && typeof height !== 'undefined') {
10198
return
10299
}
103100

@@ -107,12 +104,10 @@ export class SignatureCanvas extends Component<SignatureCanvasProps> {
107104
and only part of the canvas is cleared then. */
108105
const ratio = Math.max(window.devicePixelRatio ?? 1, 1)
109106

110-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
111-
if (!width) {
107+
if (typeof width === 'undefined') {
112108
canvas.width = canvas.offsetWidth * ratio
113109
}
114-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
115-
if (!height) {
110+
if (typeof height === 'undefined') {
116111
canvas.height = canvas.offsetHeight * ratio
117112
}
118113
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion

0 commit comments

Comments
 (0)