Skip to content

Commit

Permalink
Merge pull request #929 from nextcloud-libraries/fix/do-not-show-chec…
Browse files Browse the repository at this point in the history
…kbox-on-single-select
  • Loading branch information
skjnldsv authored Aug 24, 2023
2 parents 8b7f0eb + e4b1173 commit 7a07526
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
14 changes: 10 additions & 4 deletions lib/components/FilePicker/FileList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<table>
<thead>
<tr>
<th class="row-checkbox">
<th class="row-checkbox" v-if="multiselect">
<span class="hidden-visually">
{{ t('Select entry') }}
</span>
<NcCheckboxRadioSwitch v-if="props.multiselect" :aria-label="t('Select all entries')" :checked="allSelected" @update:checked="onSelectAll" />
<NcCheckboxRadioSwitch v-if="multiselect" :aria-label="t('Select all entries')" :checked="allSelected" @update:checked="onSelectAll" />
</th>
<th :aria-sort="sortByName" class="row-name">
<NcButton :wide="true" type="tertiary" @click="toggleSortByName">
Expand Down Expand Up @@ -49,6 +49,7 @@
<FileListRow v-for="file in sortedFiles"
:key="file.fileid || file.path"
:allow-pick-directory="allowPickDirectory"
:show-checkbox="multiselect"
:can-pick="multiselect || selectedFiles.length === 0 || selectedFiles.includes(file)"
:selected="selectedFiles.includes(file)"
:node="file"
Expand Down Expand Up @@ -156,11 +157,16 @@ function onSelectAll() {
}
}
function onNodeSelected(file: Node){
function onNodeSelected(file: Node) {
if (props.selectedFiles.includes(file)) {
emit('update:selectedFiles', props.selectedFiles.filter((f) => f.path !== file.path))
} else {
emit('update:selectedFiles', [...props.selectedFiles, file])
if (props.multiselect) {
emit('update:selectedFiles', [...props.selectedFiles, file])
} else {
// no multi select so only this file is selected
emit('update:selectedFiles', [file])
}
}
}
Expand Down
17 changes: 15 additions & 2 deletions lib/components/FilePicker/FileListRow.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<template>
<tr tabindex="0"
class="file-picker__row"
:class="['file-picker__row', {
'file-picker__row--selected': selected && !showCheckbox
}]"
@key-down="handleKeyDown">
<td class="row-checkbox">
<td v-if="showCheckbox" class="row-checkbox">
<NcCheckboxRadioSwitch :disabled="!isPickable"
:checked="selected"
:aria-label="t('Select the row for {nodename}', { nodename: displayName })"
Expand Down Expand Up @@ -34,6 +36,8 @@ const props = defineProps<{
allowPickDirectory: boolean
/** Is this node currently selected */
selected: boolean
/** Whether to show the checkbox in first column */
showCheckbox: boolean
/** Whether the node can be picked */
canPick: boolean
/** The current node */
Expand Down Expand Up @@ -100,6 +104,15 @@ function handleKeyDown(event: KeyboardEvent) {
@use './FileList.scss';
.file-picker {
&__row {
&--selected {
background-color: var(--color-background-dark);
}
&:hover {
background-color: var(--color-background-hover);
}
}
&__name-container {
display: flex;
justify-content: start;
Expand Down

0 comments on commit 7a07526

Please sign in to comment.