Skip to content

Commit 6aef5be

Browse files
authored
Merge pull request #1982 from Ateina/1966-ListItemAttachments-cancel-event
1966 ListItemAttachments cancel event is hanging the control
2 parents cf1c117 + ea3e826 commit 6aef5be

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/controls/listItemAttachments/IUploadAttachmentProps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export interface IUploadAttachmentProps {
99
context: BaseComponentContext;
1010
fireUpload?: boolean;
1111
onAttachmentUpload: (file?: File) => void;
12+
onUploadDialogClosed: () => void;
1213
}

src/controls/listItemAttachments/ListItemAttachments.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export class ListItemAttachments extends React.Component<IListItemAttachmentsPro
9393
}, () => this.loadAttachments().then(resolve));
9494
});
9595
}
96+
9697
protected loadAttachmentsPreview(files: IListItemAttachmentFile[]): Promise<void> {
9798
const filePreviewImages = files.map(file => this.loadAttachmentPreview(file));
9899
return Promise.all(filePreviewImages).then(filePreviews => {
@@ -252,6 +253,7 @@ export class ListItemAttachments extends React.Component<IListItemAttachmentsPro
252253
context={this.props.context}
253254
onAttachmentUpload={this._onAttachmentUpload}
254255
fireUpload={this.state.fireUpload}
256+
onUploadDialogClosed={() => this.setState({ fireUpload: false })}
255257
/>
256258

257259
{

src/controls/listItemAttachments/UploadAttachment.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,25 @@ export class UploadAttachment extends React.Component<IUploadAttachmentProps, IU
8989

9090
}
9191

92+
/**
93+
* Called when the hidden file input is clicked (activated).
94+
* @param e - Mouse click event on the file input element.
95+
*/
96+
private onInputActivated = (e: React.MouseEvent<HTMLInputElement>): void => {
97+
setTimeout(() => {
98+
window.addEventListener('focus', this.handleFocusAfterDialog);
99+
}, 300);
100+
}
101+
102+
/**
103+
* Handles window focus event after the file picker dialog is closed.
104+
*/
105+
private handleFocusAfterDialog = (): void => {
106+
window.removeEventListener('focus', this.handleFocusAfterDialog);
107+
this._isFileExplorerOpen = false;
108+
this.props.onUploadDialogClosed();
109+
};
110+
92111
/**
93112
* Close dialog
94113
*/
@@ -109,7 +128,9 @@ export class UploadAttachment extends React.Component<IUploadAttachmentProps, IU
109128
style={{ display: 'none' }}
110129
type="file"
111130
onChange={(e) => this.addAttachment(e)}
112-
ref={this.fileInput} />
131+
onClick={(e) => this.onInputActivated(e)}
132+
ref={this.fileInput}
133+
/>
113134
<div className={styles.uploadBar}>
114135
<CommandBar
115136
items={[{

0 commit comments

Comments
 (0)