Skip to content

Commit

Permalink
Make uploadeditor accessible
Browse files Browse the repository at this point in the history
Signed-off-by: Marco Ambrosini <marcoambrosini@pm.me>
  • Loading branch information
marcoambrosini committed Aug 13, 2020
1 parent 5bd1e7a commit 7bdc55b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@

<template>
<file-preview v-bind="filePreview"
:tabindex="wrapperTabIndex"
class="file-preview"
:class="{ 'file-preview--viewer-available': isViewerAvailable, 'file-preview--upload-editor': isUploadEditor }"
@click="showPreview">
@click="handleClick"
@keydown.enter="handleClick">
<img v-if="(!isLoading && !failed) || hasTemporaryImageUrl"
:class="previewSizeClass"
class="file-preview__image"
alt=""
:src="previewUrl">
<img v-if="!isLoading && failed"
Expand All @@ -38,6 +41,8 @@
class="preview loading" />
<strong>{{ name }}</strong>
<button v-if="isUploadEditor"
tabindex="1"
:aria-label="removeAriaLabel"
class="remove-file primary">
<Close class="remove-file__icon" @click="$emit('remove-file', id)" />
</button>
Expand Down Expand Up @@ -200,6 +205,14 @@ export default {
hasTemporaryImageUrl() {
return this.mimetype.startsWith('image/') && this.localUrl
},

wrapperTabIndex() {
return this.isUploadEditor ? '0' : ''
},

removeAriaLabel() {
return t('spreed', 'Remove' + this.name)
},
},
mounted() {
const img = new Image()
Expand All @@ -213,7 +226,12 @@ export default {
img.src = this.previewUrl
},
methods: {
showPreview(event) {
handleClick(event) {
if (this.isUploadEditor) {
this.$emit('remove-file', this.id)
return
}

if (!this.isViewerAvailable) {
// Regular event handling by opening the link.
return
Expand Down Expand Up @@ -270,6 +288,10 @@ export default {
}
}

&__image {
object-fit: cover;
}

.preview {
display: block;
width: 128px;
Expand Down
8 changes: 7 additions & 1 deletion src/components/UploadEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
@remove-file="handleRemoveFileFromSelection" />
</template>
<div :key="'addMore'" class="add-more">
<button class="add-more__button primary" @click="clickImportInput">
<button :aria-label="addMoreAriaLabel"
class="add-more__button primary"
@click="clickImportInput">
<Plus :size="48" class="upload-editor__plus-icon" />
</button>
</div>
Expand Down Expand Up @@ -103,6 +105,10 @@ export default {
showModal() {
return this.showUploadEditor && !this.modalDismissed
},

addMoreAriaLabel() {
return t('spreed', 'Add more files')
},
},

watch: {
Expand Down

0 comments on commit 7bdc55b

Please sign in to comment.