Skip to content

1966 ListItemAttachments cancel event is hanging the control #1982

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/controls/listItemAttachments/IUploadAttachmentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export interface IUploadAttachmentProps {
context: BaseComponentContext;
fireUpload?: boolean;
onAttachmentUpload: (file?: File) => void;
onUploadDialogClosed: () => void;
}
2 changes: 2 additions & 0 deletions src/controls/listItemAttachments/ListItemAttachments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class ListItemAttachments extends React.Component<IListItemAttachmentsPro
}, () => this.loadAttachments().then(resolve));
});
}

protected loadAttachmentsPreview(files: IListItemAttachmentFile[]): Promise<void> {
const filePreviewImages = files.map(file => this.loadAttachmentPreview(file));
return Promise.all(filePreviewImages).then(filePreviews => {
Expand Down Expand Up @@ -252,6 +253,7 @@ export class ListItemAttachments extends React.Component<IListItemAttachmentsPro
context={this.props.context}
onAttachmentUpload={this._onAttachmentUpload}
fireUpload={this.state.fireUpload}
onUploadDialogClosed={() => this.setState({ fireUpload: false })}
/>

{
Expand Down
23 changes: 22 additions & 1 deletion src/controls/listItemAttachments/UploadAttachment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ export class UploadAttachment extends React.Component<IUploadAttachmentProps, IU

}

/**
* Called when the hidden file input is clicked (activated).
* @param e - Mouse click event on the file input element.
*/
private onInputActivated = (e: React.MouseEvent<HTMLInputElement>): void => {
setTimeout(() => {
window.addEventListener('focus', this.handleFocusAfterDialog);
}, 300);
}

/**
* Handles window focus event after the file picker dialog is closed.
*/
private handleFocusAfterDialog = (): void => {
window.removeEventListener('focus', this.handleFocusAfterDialog);
this._isFileExplorerOpen = false;
this.props.onUploadDialogClosed();
};

/**
* Close dialog
*/
Expand All @@ -109,7 +128,9 @@ export class UploadAttachment extends React.Component<IUploadAttachmentProps, IU
style={{ display: 'none' }}
type="file"
onChange={(e) => this.addAttachment(e)}
ref={this.fileInput} />
onClick={(e) => this.onInputActivated(e)}
ref={this.fileInput}
/>
<div className={styles.uploadBar}>
<CommandBar
items={[{
Expand Down