Skip to content
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

feat(FileUpload): added event to onTextChange #8955

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export interface FileUploadProps
/** A callback for when a selected file starts loading. */
onReadStarted?: (fileHandle: File) => void;
/** Text area text changed. */
onTextChange?: (text: string) => void;
onTextChange?: (event: React.ChangeEvent<HTMLTextAreaElement>, text: string) => void;
}

export const FileUpload: React.FunctionComponent<FileUploadProps> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export interface FileUploadFieldProps extends Omit<React.HTMLProps<HTMLDivElemen
* of the file upload component. */
onTextAreaClick?: (event: React.MouseEvent<HTMLTextAreaElement, MouseEvent>) => void;
/** Text area text changed. */
onTextChange?: (text: string) => void;
onTextChange?: (event: React.ChangeEvent<HTMLTextAreaElement>, text: string) => void;
/** Placeholder string to display in the empty text area field. */
textAreaPlaceholder?: string;
}
Expand Down Expand Up @@ -114,8 +114,8 @@ export const FileUploadField: React.FunctionComponent<FileUploadFieldProps> = ({

...props
}: FileUploadFieldProps) => {
const onTextAreaChange = (newValue: string) => {
onTextChange?.(newValue);
const onTextAreaChange = (event: React.ChangeEvent<HTMLTextAreaElement>, newValue: string) => {
onTextChange?.(event, newValue);
};
return (
<div
Expand Down Expand Up @@ -169,7 +169,7 @@ export const FileUploadField: React.FunctionComponent<FileUploadFieldProps> = ({
name={id}
aria-label={ariaLabel}
value={value as string}
onChange={onTextAreaChange}
onChange={(value, event) => onTextAreaChange(event, value)}
onClick={onTextAreaClick}
onBlur={onTextAreaBlur}
placeholder={textAreaPlaceholder}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const CustomPreviewFileUpload: React.FunctionComponent = () => {
hasPlaceholderText
]);

const handleTextAreaChange = (value: string) => {
const handleTextAreaChange = (_event: React.ChangeEvent<HTMLTextAreaElement>, value: string) => {
setValue(value);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export const SimpleTextFileUpload: React.FunctionComponent = () => {
setFilename(file.name);
};

const handleTextOrDataChange = (value: string) => {
const handleTextChange = (_event: React.ChangeEvent<HTMLTextAreaElement>, value: string) => {
setValue(value);
};

const handleDataChange = (value: string) => {
setValue(value);
};

Expand All @@ -35,8 +39,8 @@ export const SimpleTextFileUpload: React.FunctionComponent = () => {
filename={filename}
filenamePlaceholder="Drag and drop a file or upload one"
onFileInputChange={handleFileInputChange}
onDataChange={handleTextOrDataChange}
onTextChange={handleTextOrDataChange}
onDataChange={handleDataChange}
onTextChange={handleTextChange}
onReadStarted={handleFileReadStarted}
onReadFinished={handleFileReadFinished}
onClearClick={handleClear}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export const TextFileWithEditsAllowed: React.FunctionComponent = () => {
setFilename(file.name);
};

const handleTextOrDataChange = (value: string) => {
const handleTextChange = (_event: React.ChangeEvent<HTMLTextAreaElement>, value: string) => {
setValue(value);
};

const handleDataChange = (value: string) => {
setValue(value);
};

Expand All @@ -35,8 +39,8 @@ export const TextFileWithEditsAllowed: React.FunctionComponent = () => {
filename={filename}
filenamePlaceholder="Drag and drop a file or upload one"
onFileInputChange={handleFileInputChange}
onDataChange={handleTextOrDataChange}
onTextChange={handleTextOrDataChange}
onDataChange={handleDataChange}
onTextChange={handleTextChange}
onReadStarted={handleFileReadStarted}
onReadFinished={handleFileReadFinished}
onClearClick={handleClear}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ export const TextFileUploadWithRestrictions: React.FunctionComponent = () => {
setFilename(file.name);
};

const handleTextOrDataChange = (value: string) => {
const handleTextChange = (_event: React.ChangeEvent<HTMLTextAreaElement>, value: string) => {
setValue(value);
};

const handleDataChange = (value: string) => {
setValue(value);
};

Expand Down Expand Up @@ -43,8 +47,8 @@ export const TextFileUploadWithRestrictions: React.FunctionComponent = () => {
filename={filename}
filenamePlaceholder="Drag and drop a file or upload one"
onFileInputChange={handleFileInputChange}
onDataChange={handleTextOrDataChange}
onTextChange={handleTextOrDataChange}
onDataChange={handleDataChange}
onTextChange={handleTextChange}
onReadStarted={handleFileReadStarted}
onReadFinished={handleFileReadFinished}
onClearClick={handleClear}
Expand Down