Skip to content

Commit

Permalink
(lint/types/fix): only resize width/height if not set
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
agilgur5 committed Apr 20, 2022
1 parent e19871f commit 7cd4efa
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,11 @@ export class SignatureCanvas extends Component<SignatureCanvasProps> {
this._resizeCanvas()
}

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

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

// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (!width) {
if (typeof width === 'undefined') {
canvas.width = canvas.offsetWidth * ratio
}
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (!height) {
if (typeof height === 'undefined') {
canvas.height = canvas.offsetHeight * ratio
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand Down

0 comments on commit 7cd4efa

Please sign in to comment.