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
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