Skip to content

Commit

Permalink
Merge pull request #1192 from nextcloud-libraries/fix/stop-click-event
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv committed Jan 18, 2024
2 parents 3d03e52 + 3908ba9 commit 7d3a052
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
10 changes: 8 additions & 2 deletions lib/components/FilePicker/FileListRow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
*/

import { afterEach, describe, expect, it, vi } from 'vitest'
import { shallowMount } from '@vue/test-utils'
import { File } from '@nextcloud/files'
import { shallowMount } from '@vue/test-utils'

import FileListRow from './FileListRow.vue'

Expand All @@ -33,6 +33,7 @@ describe('FilePicker: FileListRow', () => {
mime: 'text/plain',
source: 'https://example.com/dav/a.txt',
root: '/',
attributes: { displayName: 'test' },
})

afterEach(() => {
Expand Down Expand Up @@ -90,9 +91,14 @@ describe('FilePicker: FileListRow', () => {
node,
cropImagePreviews: true,
},
stubs: {
NcCheckboxRadioSwitch: {
template: '<label><input type="checkbox" @click="$emit(\'update:checked\', true)" ></label>',
},
},
})

await wrapper.find('[data-testid="row-checkbox"]').trigger('click')
await wrapper.find('input[type="checkbox"]').trigger('click')

// one event with payload `true` is expected
expect(wrapper.emitted('update:selected')).toEqual([[true]])
Expand Down
15 changes: 7 additions & 8 deletions lib/components/FilePicker/FileListRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
}]"
:data-filename="node.basename"
data-testid="file-list-row"
@click="handleClick"
v-on="
v-on="{
click: handleClick,
/* same as tabindex -> if we hide the checkbox or this is a directory we need keyboard access to enter the directory or select the node */
(!showCheckbox || isDirectory) ? { keydown: handleKeyDown } : {}
">
<td v-if="showCheckbox" class="row-checkbox">
<NcCheckboxRadioSwitch :disabled="!isPickable"
...(!showCheckbox || isDirectory ? { keydown: handleKeyDown } : {}),
}">
<td v-if="showCheckbox" class="row-checkbox" @click.stop="() => {/* Stop the click event */}">
<NcCheckboxRadioSwitch :aria-label="t('Select the row for {nodename}', { nodename: displayName })"
:checked="selected"
:aria-label="t('Select the row for {nodename}', { nodename: displayName })"
:disabled="!isPickable"
data-testid="row-checkbox"
@click.stop="/* just stop the click event */"
@update:checked="toggleSelected" />
</td>
<td class="row-name">
Expand Down

0 comments on commit 7d3a052

Please sign in to comment.