Skip to content

Commit

Permalink
fix(a11y): focus on uploaded file and narrate status (#3189)
Browse files Browse the repository at this point in the history
* Focus on uploaded file and narrate status

* Use uploadDom as HTMLElement

Co-authored-by: Nickii Miaro <miaronkirote@gmail.com>

* Make uploadDom an HTMLElement

* fix prettier issues

* Ignore unbound method rule in constructor

---------

Co-authored-by: Nickii Miaro <miaronkirote@gmail.com>
  • Loading branch information
musale and Mnickii authored May 29, 2024
1 parent 6395096 commit 7f9eac3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ $file-upload-border-drag: var(--file-upload-border-drag, 1px dashed #0078d4);
margin-top: 30px;
}

.focus,:focus {
outline: none;
}

fluent-button {
.upload-icon {
path {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,20 @@ export class MgtFileUpload extends MgtBaseComponent {
private _excludedFileType = false;

constructor() {
/* eslint-disable @typescript-eslint/unbound-method */
super();
this.filesToUpload = [];
this.addEventListener('__uploadfailed', this.focusOnUpload);
this.addEventListener('__uploadsuccess', this.focusOnUpload);
}

focusOnUpload() {
const uploadDom = this.renderRoot.querySelector<HTMLElement>('mgt-file[part="upload"]');
if (uploadDom) {
uploadDom.setAttribute('tabindex', '0');
uploadDom.classList.add('upload');
uploadDom.focus();
}
}

/**
Expand Down Expand Up @@ -466,12 +478,13 @@ export class MgtFileUpload extends MgtBaseComponent {
const folder =
folderTabStyle + (fileItem.fieldUploadResponse === 'lastModifiedDateTime' ? ' file-upload-dialog-success' : '');

const isDescription = fileItem.fieldUploadResponse === 'description';
const description = classMap({
description: fileItem.fieldUploadResponse === 'description'
description: isDescription
});

const completedTemplate = !fileItem.completed ? this.renderFileUploadTemplate(fileItem) : html``;

const failOrSuccess = isDescription ? strings.failUploadFile : strings.successUploadFile;
return mgtHtml`
<div class="${completed}">
<div class="${folder}">
Expand All @@ -484,6 +497,7 @@ export class MgtFileUpload extends MgtBaseComponent {
.fileDetails=${fileItem.driveItem}
.view=${fileItem.view}
.line2Property=${fileItem.fieldUploadResponse}
aria-label="${fileItem.driveItem.name} ${failOrSuccess}"
part="upload"
class="mgt-file-item">
</mgt-file>
Expand Down Expand Up @@ -1121,6 +1135,7 @@ export class MgtFileUpload extends MgtBaseComponent {
fileUpload.completed = true;
void super.requestStateUpdate(true);
void clearFilesCache();
this.fireCustomEvent('__uploadsuccess');
}, 500);
}

Expand All @@ -1137,6 +1152,7 @@ export class MgtFileUpload extends MgtBaseComponent {
fileUpload.fieldUploadResponse = 'description';
fileUpload.completed = true;
void super.requestStateUpdate(true);
this.fireCustomEvent('__uploadfailed');
}, 500);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

export const strings = {
failUploadFile: 'File upload fail.',
failUploadFile: 'File upload failed',
successUploadFile: 'File upload succeeded',
cancelUploadFile: 'File cancel.',
buttonUploadFile: 'Upload Files',
maximumFilesTitle: 'Maximum files',
Expand Down

0 comments on commit 7f9eac3

Please sign in to comment.