-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.handleInputChange()
- use .currentTarget
; clear the input using ''
#5381
Open
lakesare
wants to merge
2
commits into
main
Choose a base branch
from
lakesare/event-target-value
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,7 +2,7 @@ import { UIPlugin, type Uppy } from '@uppy/core' | |||||
import type { DefinePluginOpts } from '@uppy/core/lib/BasePlugin.js' | ||||||
import type { UIPluginOptions } from '@uppy/core/lib/UIPlugin.js' | ||||||
import type { Body, Meta } from '@uppy/utils/lib/UppyFile' | ||||||
import type { ChangeEvent } from 'preact/compat' | ||||||
import type { TargetedEvent } from 'preact/compat' | ||||||
import toArray from '@uppy/utils/lib/toArray' | ||||||
import isDragDropSupported from '@uppy/utils/lib/isDragDropSupported' | ||||||
import getDroppedFiles from '@uppy/utils/lib/getDroppedFiles' | ||||||
|
@@ -80,22 +80,17 @@ export default class DragDrop<M extends Meta, B extends Body> extends UIPlugin< | |||||
} | ||||||
} | ||||||
|
||||||
private onInputChange = (event: ChangeEvent) => { | ||||||
const files = toArray((event.target as HTMLInputElement).files!) | ||||||
private onInputChange = (event: TargetedEvent<HTMLInputElement, Event>) => { | ||||||
const files = toArray(event.currentTarget.files || []) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if (files.length > 0) { | ||||||
this.uppy.log('[DragDrop] Files selected through input') | ||||||
this.addFiles(files) | ||||||
} | ||||||
|
||||||
// We clear the input after a file is selected, because otherwise | ||||||
// change event is not fired in Chrome and Safari when a file | ||||||
// with the same name is selected. | ||||||
// ___Why not use value="" on <input/> instead? | ||||||
// Because if we use that method of clearing the input, | ||||||
// Chrome will not trigger change if we drop the same file twice (Issue #768). | ||||||
// @ts-expect-error TS freaks out, but this is fine | ||||||
// Clear the input so that Chrome can detect file section when the same file is repeatedly selected | ||||||
// (see https://github.com/transloadit/uppy/issues/768#issuecomment-2264902758) | ||||||
// eslint-disable-next-line no-param-reassign | ||||||
event.target.value = null | ||||||
event.currentTarget.value = '' | ||||||
} | ||||||
|
||||||
private handleDragOver = (event: DragEvent) => { | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,7 +4,7 @@ import { UIPlugin, Uppy, type UIPluginOptions } from '@uppy/core' | |||||
import toArray from '@uppy/utils/lib/toArray' | ||||||
import type { Body, Meta } from '@uppy/utils/lib/UppyFile' | ||||||
import type { DefinePluginOpts } from '@uppy/core/lib/BasePlugin.js' | ||||||
|
||||||
import type { TargetedEvent } from 'preact/compat' | ||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||||||
// @ts-ignore We don't want TS to generate types for the package.json | ||||||
import packageJson from '../package.json' | ||||||
|
@@ -65,19 +65,15 @@ export default class FileInput<M extends Meta, B extends Body> extends UIPlugin< | |||||
} | ||||||
} | ||||||
|
||||||
private handleInputChange(event: Event) { | ||||||
private handleInputChange(event: TargetedEvent<HTMLInputElement, Event>) { | ||||||
this.uppy.log('[FileInput] Something selected through input...') | ||||||
const files = toArray((event.target as HTMLFileInputElement).files) | ||||||
const files = toArray(event.currentTarget.files || []) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
this.addFiles(files) | ||||||
|
||||||
// We clear the input after a file is selected, because otherwise | ||||||
// change event is not fired in Chrome and Safari when a file | ||||||
// with the same name is selected. | ||||||
// ___Why not use value="" on <input/> instead? | ||||||
// Because if we use that method of clearing the input, | ||||||
// Chrome will not trigger change if we drop the same file twice (Issue #768). | ||||||
// @ts-expect-error yes | ||||||
event.target.value = null // eslint-disable-line no-param-reassign | ||||||
// Clear the input so that Chrome can detect file section when the same file is repeatedly selected | ||||||
// (see https://github.com/transloadit/uppy/issues/768#issuecomment-2264902758) | ||||||
// eslint-disable-next-line no-param-reassign | ||||||
event.currentTarget.value = '' | ||||||
} | ||||||
|
||||||
private handleClick() { | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.