Skip to content
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

fix(files): Move aria-label for favorite icon from span to icon #41953

Merged
merged 2 commits into from
Dec 1, 2023
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
17 changes: 12 additions & 5 deletions apps/files/src/components/FileEntry/FavoriteIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
-
-->
<template>
<NcIconSvgWrapper class="favorite-marker-icon" :svg="StarSvg" />
<NcIconSvgWrapper class="favorite-marker-icon" :name="t('files', 'Favorite')" :svg="StarSvg" />
</template>

<script>
<script lang="ts">
import { translate as t } from '@nextcloud/l10n'
import { defineComponent } from 'vue'

import StarSvg from '@mdi/svg/svg/star.svg?raw'
import NcIconSvgWrapper from '@nextcloud/vue/dist/Components/NcIconSvgWrapper.js'

Expand All @@ -38,7 +41,7 @@ import NcIconSvgWrapper from '@nextcloud/vue/dist/Components/NcIconSvgWrapper.js
* }
* ```
*/
export default {
export default defineComponent({
name: 'FavoriteIcon',
components: {
NcIconSvgWrapper,
Expand All @@ -52,10 +55,14 @@ export default {
await this.$nextTick()
// MDI default viewbox is "0 0 24 24" but we add a stroke of 10px so we must adjust it
const el = this.$el.querySelector('svg')
el.setAttribute('viewBox', '-4 -4 30 30')
el?.setAttribute?.('viewBox', '-4 -4 30 30')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, why add optional chaining here? Is it possible that there would be no SVG, or that the SVG element would not have the setAttribute method?

Copy link
Contributor Author

@susnux susnux Dec 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

querySelector returns Element | undefined so for defensive programming either check and throw an error or use optional chaining. Otherwise at least casting to SvgElement is required.

But doing non of those results in type errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

querySelector returns Element | undefined

But we select an SVG element here, and we at least know that there is the setAttribute method. No chance el.setAttribute would be undefined. If that was only for TypeScript, IMO, we should use !. or as to fix TS error. (Otherwise, there is an unneeded check in a bundle and runtime).

In theory querySelector could return undefined here, but it would mean that something has changed in <NcIconSvgWrapper> and ?. would hide the issue instead of exposing it.

},
}
methods: {
t,
},
})
</script>

<style lang="scss" scoped>
.favorite-marker-icon {
color: #a08b00;
Expand Down
8 changes: 3 additions & 5 deletions apps/files/src/components/FileEntry/FileEntryPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<template>
<span class="files-list__row-icon">
<template v-if="source.type === 'folder'">
<FolderOpenIcon v-once v-if="dragover" />
<FolderOpenIcon v-if="dragover" v-once />
<template v-else>
<FolderIcon v-once />
<OverlayIcon :is="folderOverlay"
Expand All @@ -42,12 +42,10 @@
@error="backgroundFailed = true"
@load="backgroundFailed = false">

<FileIcon v-once v-else />
<FileIcon v-else v-once />

<!-- Favorite icon -->
<span v-if="isFavorite"
class="files-list__row-icon-favorite"
:aria-label="t('files', 'Favorite')">
<span v-if="isFavorite" class="files-list__row-icon-favorite">
<FavoriteIcon v-once />
</span>

Expand Down
4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

Loading