Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions packages/react-core/src/components/FileUpload/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,6 @@ export interface FileUploadProps
isReadOnly?: boolean;
/** Flag to show if the field is required. */
isRequired?: boolean;
/** @deprecated A callback for when the file contents changes. Please instead use
* onFileInputChange, onTextChange, onDataChange, and onClearClick individually.
*/
onChange?: (
value: string | File,
filename: string,
event:
| React.MouseEvent<HTMLButtonElement, MouseEvent> // Clear button was clicked
| React.DragEvent<HTMLElement> // User dragged/dropped a file
| React.ChangeEvent<HTMLElement> // User typed in the TextArea
) => void;
/** Callback for clicking on the file upload field text area. By default, prevents a click
* in the text area from opening file dialog.
*/
Expand All @@ -66,7 +55,7 @@ export interface FileUploadProps
onFileInputChange?: (event: React.ChangeEvent<HTMLInputElement> | React.DragEvent<HTMLElement>, file: File) => void;
/** Aria-valuetext for the loading spinner. */
spinnerAriaValueText?: string;
/** What type of file. Determines what is passed to the onChange property and what is
/** What type of file. Determines whether 'onDataChange` is called and what is
* expected by the value property (a string for 'text' and 'dataURL', or a File object otherwise.
*/
type?: 'text' | 'dataURL';
Expand Down Expand Up @@ -102,7 +91,6 @@ export const FileUpload: React.FunctionComponent<FileUploadProps> = ({
value = type === fileReaderType.text || type === fileReaderType.dataURL ? '' : null,
filename = '',
children = null,
onChange = () => {},
onFileInputChange = null,
onReadStarted = () => {},
onReadFinished = () => {},
Expand All @@ -121,31 +109,23 @@ export const FileUpload: React.FunctionComponent<FileUploadProps> = ({
onFileInputChange?.(event, fileHandle);
}
if (type === fileReaderType.text || type === fileReaderType.dataURL) {
onChange('', fileHandle.name, event); // Show the filename while reading
onReadStarted(fileHandle);
readFile(fileHandle, type as fileReaderType)
.then(data => {
onReadFinished(fileHandle);
onChange(data as string, fileHandle.name, event);
onDataChange?.(data as string);
})
.catch((error: DOMException) => {
onReadFailed(error, fileHandle);
onReadFinished(fileHandle);
onChange('', '', event); // Clear the filename field on a failure
onDataChange?.('');
});
} else {
onChange(fileHandle, fileHandle.name, event);
}
}
dropzoneProps.onDropAccepted && dropzoneProps.onDropAccepted(acceptedFiles, event);
};

const onDropRejected: DropFileEventHandler = (rejectedFiles, event) => {
if (rejectedFiles.length > 0) {
onChange('', rejectedFiles[0].name, event);
}
dropzoneProps.onDropRejected && dropzoneProps.onDropRejected(rejectedFiles, event);
};

Expand All @@ -155,7 +135,6 @@ export const FileUpload: React.FunctionComponent<FileUploadProps> = ({
};

const onClearButtonClick = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
onChange('', '', event);
onClearClick?.(event);
setFileValue(null);
};
Expand Down Expand Up @@ -187,7 +166,6 @@ export const FileUpload: React.FunctionComponent<FileUploadProps> = ({
type={type}
filename={filename}
value={value}
onChange={onChange}
isDragActive={isDragActive}
onBrowseButtonClick={open}
onClearButtonClick={onClearButtonClick}
Expand Down
14 changes: 2 additions & 12 deletions packages/react-core/src/components/FileUpload/FileUploadField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { fileReaderType } from '../../helpers/fileUtils';
* functionality is not built in by default.
*/

export interface FileUploadFieldProps extends Omit<React.HTMLProps<HTMLDivElement>, 'value' | 'onChange'> {
export interface FileUploadFieldProps extends Omit<React.HTMLProps<HTMLDivElement>, 'value'> {
/** Flag to allow editing of a text file's contents after it is selected from disk. */
allowEditingUploadedText?: boolean;
/** Aria-label for the text area. */
Expand Down Expand Up @@ -47,14 +47,6 @@ export interface FileUploadFieldProps extends Omit<React.HTMLProps<HTMLDivElemen
isReadOnly?: boolean;
/** Flag to show if the field is required. */
isRequired?: boolean;
/** A callback for when the text area value changes. */
onChange?: (
value: string,
filename: string,
event:
| React.ChangeEvent<HTMLTextAreaElement> // User typed in the TextArea
| React.MouseEvent<HTMLButtonElement, MouseEvent> // User clicked Clear button
) => void;
/** Aria-valuetext for the loading spinner. */
spinnerAriaValueText?: string;
/** What type of file. Determines what is is expected by the value property (a string for
Expand Down Expand Up @@ -95,7 +87,6 @@ export const FileUploadField: React.FunctionComponent<FileUploadFieldProps> = ({
type,
value = '',
filename = '',
onChange = () => {},
onBrowseButtonClick = () => {},
onClearButtonClick = () => {},
onTextAreaClick,
Expand Down Expand Up @@ -123,8 +114,7 @@ export const FileUploadField: React.FunctionComponent<FileUploadFieldProps> = ({

...props
}: FileUploadFieldProps) => {
const onTextAreaChange = (newValue: string, event: React.ChangeEvent<HTMLTextAreaElement>) => {
onChange(newValue, filename, event);
const onTextAreaChange = (newValue: string) => {
onTextChange?.(newValue);
};
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as React from 'react';
import { render } from '@testing-library/react';

test('simple fileupload', () => {
const changeHandler = jest.fn();
const readStartedHandler = jest.fn();
const readFinishedHandler = jest.fn();

Expand All @@ -13,7 +12,6 @@ test('simple fileupload', () => {
type="text"
value={''}
filename={''}
onChange={changeHandler}
onReadStarted={readStartedHandler}
onReadFinished={readFinishedHandler}
isLoading={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as React from 'react';
import { render } from '@testing-library/react';

test('simple fileuploadfield', () => {
const changeHandler = jest.fn();
const browserBtnClickHandler = jest.fn();
const clearBtnClickHandler = jest.fn();

Expand All @@ -13,7 +12,6 @@ test('simple fileuploadfield', () => {
type="text"
value={''}
filename={''}
onChange={changeHandler}
filenamePlaceholder="Do something custom with this!"
onBrowseButtonClick={browserBtnClickHandler}
onClearButtonClick={clearBtnClickHandler}
Expand Down