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(FilePicker): Do not show checkboxes on single select mode #929

Merged
merged 1 commit into from
Aug 24, 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
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 @@ -33,6 +35,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 @@ -94,6 +98,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
Loading