From 7cf5c5da207bc06e082785d8f8b533e9c71f028e Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 27 Jun 2024 17:18:31 +0200 Subject: [PATCH] @uppy/dashboard: fix handling of `null` for `doneButtonHandler` (#5283) As documented, `null` should not be treated the same as `undefined`. --- packages/@uppy/dashboard/src/Dashboard.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/@uppy/dashboard/src/Dashboard.tsx b/packages/@uppy/dashboard/src/Dashboard.tsx index 8aeec5ae41..2247255a69 100644 --- a/packages/@uppy/dashboard/src/Dashboard.tsx +++ b/packages/@uppy/dashboard/src/Dashboard.tsx @@ -139,7 +139,7 @@ interface DashboardMiscOptions disableLocalFiles?: boolean disableStatusBar?: boolean disableThumbnailGenerator?: boolean - doneButtonHandler?: () => void + doneButtonHandler?: null | (() => void) fileManagerSelectionType?: 'files' | 'folders' | 'both' hideCancelButton?: boolean hidePauseResumeButton?: boolean @@ -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> @@ -284,9 +284,13 @@ export default class Dashboard 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()