From 2feb558884c83ca5e60faa7483cdda5c4807fe25 Mon Sep 17 00:00:00 2001 From: Santiago V <santiagov@mural.ly> Date: Wed, 11 May 2016 18:30:58 -0300 Subject: [PATCH] Prevent issue in Firefox when dropping an image When dropping an image (from another tab) in Firefox, it sends `'Files'` in the `dataTransfer.types` array but `dataTransfer.files` value is `null`. This change should prevent a type from being recognized as such if there's no value returning from the `getData` function for that type. Closes #29 --- src/NativeDragSources.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/NativeDragSources.js b/src/NativeDragSources.js index d415632..9ad5549 100644 --- a/src/NativeDragSources.js +++ b/src/NativeDragSources.js @@ -16,7 +16,7 @@ const nativeTypesConfig = { exposeProperty: 'files', matchesTypes: ['Files'], getData: (dataTransfer) => - Array.prototype.slice.call(dataTransfer.files) + dataTransfer.files && Array.prototype.slice.call(dataTransfer.files) }, [NativeTypes.URL]: { exposeProperty: 'urls', @@ -76,7 +76,9 @@ export function matchNativeItemType(dataTransfer) { const dataTransferTypes = Array.prototype.slice.call(dataTransfer.types || []); return Object.keys(nativeTypesConfig).filter(nativeItemType => { - const { matchesTypes } = nativeTypesConfig[nativeItemType]; - return matchesTypes.some(t => dataTransferTypes.indexOf(t) > -1); + const nativeTypeConfig = nativeTypesConfig[nativeItemType]; + const matchesTypes = nativeTypeConfig.matchesTypes; + return matchesTypes.some(t => dataTransferTypes.indexOf(t) > -1) && + nativeItemType.getData(dataTransfer); })[0] || null; }