Skip to content

Commit

Permalink
@uppy/dashboard: fix handling of null for doneButtonHandler (#5283)
Browse files Browse the repository at this point in the history
As documented, `null` should not be treated the same as `undefined`.
  • Loading branch information
aduh95 authored Jun 27, 2024
1 parent 8af27e2 commit 7cf5c5d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/@uppy/dashboard/src/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ interface DashboardMiscOptions<M extends Meta, B extends Body>
disableLocalFiles?: boolean
disableStatusBar?: boolean
disableThumbnailGenerator?: boolean
doneButtonHandler?: () => void
doneButtonHandler?: null | (() => void)
fileManagerSelectionType?: 'files' | 'folders' | 'both'
hideCancelButton?: boolean
hidePauseResumeButton?: boolean
Expand Down Expand Up @@ -219,7 +219,7 @@ const defaultOptions = {
// Dynamic default options, they have to be defined in the constructor (because
// they require access to the `this` keyword), but we still want them to
// appear in the default options so TS knows they'll be defined.
doneButtonHandler: null as any,
doneButtonHandler: undefined as any,
onRequestCloseModal: null as any,
} satisfies Partial<DashboardOptions<any, any>>

Expand Down Expand Up @@ -284,9 +284,13 @@ export default class Dashboard<M extends Meta, B extends Body> extends UIPlugin<
this.defaultLocale = locale

// Dynamic default options:
this.opts.doneButtonHandler ??= () => {
this.uppy.clearUploadedFiles()
this.requestCloseModal()
if (this.opts.doneButtonHandler === undefined) {
// `null` means "do not display a Done button", while `undefined` means
// "I want the default behavior". For this reason, we need to differentiate `null` and `undefined`.
this.opts.doneButtonHandler = () => {
this.uppy.clearUploadedFiles()
this.requestCloseModal()
}
}
this.opts.onRequestCloseModal ??= () => this.closeModal()

Expand Down

0 comments on commit 7cf5c5d

Please sign in to comment.