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): Fix checkbox state semantics #42949

Merged
merged 2 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/files/src/components/FileEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
<span v-if="source.attributes.failed" class="files-list__row--failed" />

<!-- Checkbox -->
<FileEntryCheckbox :display-name="displayName"
:fileid="fileid"
<FileEntryCheckbox :fileid="fileid"
:is-loading="isLoading"
:nodes="nodes" />
:nodes="nodes"
:source="source" />

<!-- Link to file -->
<td class="files-list__row-name" data-cy-files-list-row-name>
Expand Down
20 changes: 14 additions & 6 deletions apps/files/src/components/FileEntry/FileEntryCheckbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
@keyup.esc.exact="resetSelection">
<NcLoadingIcon v-if="isLoading" />
<NcCheckboxRadioSwitch v-else
:aria-label="t('files', 'Select the row for {displayName}', { displayName })"
:aria-label="ariaLabel"
:checked="isSelected"
@update:checked="onSelectionChange" />
</td>
</template>

<script lang="ts">
import { Node } from '@nextcloud/files'
import { Node, FileType } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import Vue, { PropType } from 'vue'

Expand All @@ -51,10 +51,6 @@ export default Vue.extend({
},

props: {
displayName: {
type: String,
required: true,
},
fileid: {
type: String,
required: true,
Expand All @@ -67,6 +63,10 @@ export default Vue.extend({
type: Array as PropType<Node[]>,
required: true,
},
source: {
type: Object as PropType<Node>,
required: true,
},
},

setup() {
Expand All @@ -88,6 +88,14 @@ export default Vue.extend({
index() {
return this.nodes.findIndex((node: Node) => node.fileid === parseInt(this.fileid))
},
isFile() {
return this.source.type === FileType.File
},
ariaLabel() {
return this.isFile
? t('files', 'Toggle selection for file "{displayName}"', { displayName: this.source.basename })
: t('files', 'Toggle selection for folder "{displayName}"', { displayName: this.source.basename })
},
},

methods: {
Expand Down
6 changes: 3 additions & 3 deletions apps/files/src/components/FileEntryGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
<span v-if="source.attributes.failed" class="files-list__row--failed" />

<!-- Checkbox -->
<FileEntryCheckbox :display-name="displayName"
:fileid="fileid"
<FileEntryCheckbox :fileid="fileid"
:is-loading="isLoading"
:nodes="nodes" />
:nodes="nodes"
:source="source" />

<!-- Link to file -->
<td class="files-list__row-name" data-cy-files-list-row-name>
Expand Down
8 changes: 3 additions & 5 deletions apps/files/src/components/FilesListTableHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
</template>

<script lang="ts">
import { translate } from '@nextcloud/l10n'
import { translate as t } from '@nextcloud/l10n'
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
import Vue from 'vue'

Expand Down Expand Up @@ -142,9 +142,7 @@ export default Vue.extend({
},

selectAllBind() {
const label = this.isNoneSelected || this.isSomeSelected
? this.t('files', 'Select all')
: this.t('files', 'Unselect all')
const label = t('files', 'Toggle selection for all files and folders')
Copy link
Member

Choose a reason for hiding this comment

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

Aren't we loosing context here ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess not because it will be announced like checkbox - checked - Toggle selection for all files and folders or checkbox - unchecked - Toggle selection for all files and folders

Copy link
Member Author

Choose a reason for hiding this comment

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

Accessibility best practices suggest not doubling information that is already available e.g. a popup menu label should not say "Close menu" when opened or "Open menu" when closed when the state is already communicated with aria-expanded

return {
'aria-label': label,
checked: this.isAllSelected,
Expand Down Expand Up @@ -203,7 +201,7 @@ export default Vue.extend({
this.selectionStore.reset()
},

t: translate,
t,
},
})
</script>
Expand Down