Skip to content

Commit b743568

Browse files
committed
feat: allow to disable file picker navigation
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
1 parent 6224a5b commit b743568

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

lib/components/FilePicker/FilePicker.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
<template #navigation="{ isCollapsed }">
1212
<FilePickerNavigation :is-collapsed="isCollapsed"
1313
:current-view.sync="currentView"
14-
:filter-string.sync="filterString" />
14+
:filter-string.sync="filterString"
15+
:disabled-navigation="disabledNavigation" />
1516
</template>
1617

1718
<div class="file-picker__main">
@@ -89,6 +90,11 @@ const props = withDefaults(defineProps<{
8990
*/
9091
allowPickDirectory?: boolean
9192
93+
/**
94+
* Is the navigation disabled
95+
*/
96+
disabledNavigation?: boolean
97+
9298
/**
9399
* Where to mount the dialog
94100
* @default 'body'
@@ -121,6 +127,7 @@ const props = withDefaults(defineProps<{
121127
path?: string
122128
}>(), {
123129
allowPickDirectory: false,
130+
disabledNavigation: false,
124131
container: 'body',
125132
filterFn: undefined,
126133
mimetypeFilter: () => [],

lib/components/FilePicker/FilePickerNavigation.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<IconClose :size="16" />
1313
</template>
1414
</NcTextField>
15-
<template v-if="availableViews.length > 1">
15+
<template v-if="availableViews.length > 1 && !disabledNavigation">
1616
<!-- On non collapsed dialogs show the tablist, otherwise a dropdown is shown -->
1717
<ul v-if="!isCollapsed"
1818
class="file-picker__side">
@@ -52,7 +52,8 @@ import { useViews } from '../../composables/views'
5252
const props = defineProps<{
5353
currentView: 'files' | 'recent' | 'favorites',
5454
filterString: string,
55-
isCollapsed: boolean
55+
isCollapsed: boolean,
56+
disabledNavigation: boolean,
5657
}>()
5758
5859
interface INavigationEvents {

lib/filepicker-builder.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export class FilePicker<IsMultiSelect extends boolean> {
5656
private path?: string
5757
private filter?: IFilePickerFilter
5858
private container?: string
59+
private disabledNavigation: boolean
5960

6061
public constructor(title: string,
6162
multiSelect: IsMultiSelect,
@@ -64,7 +65,9 @@ export class FilePicker<IsMultiSelect extends boolean> {
6465
buttons: IFilePickerButton[] | IFilePickerButtonFactory,
6566
path?: string,
6667
filter?: IFilePickerFilter,
67-
container?: string) {
68+
container?: string,
69+
disabledNavigation = false,
70+
) {
6871
this.title = title
6972
this.multiSelect = multiSelect
7073
this.mimeTypeFilter = mimeTypeFilter
@@ -73,6 +76,7 @@ export class FilePicker<IsMultiSelect extends boolean> {
7376
this.filter = filter
7477
this.buttons = buttons
7578
this.container = container
79+
this.disabledNavigation = disabledNavigation
7680
}
7781

7882
/**
@@ -93,6 +97,7 @@ export class FilePicker<IsMultiSelect extends boolean> {
9397
mimetypeFilter: this.mimeTypeFilter,
9498
multiselect: this.multiSelect,
9599
filterFn: this.filter,
100+
disabledNavigation: this.disabledNavigation,
96101
}, (...rest: unknown[]) => {
97102
const [nodes] = rest as [nodes: Node[]]
98103
if (!Array.isArray(nodes) || nodes.length === 0) {
@@ -120,6 +125,7 @@ export class FilePickerBuilder<IsMultiSelect extends boolean> {
120125
private filter?: IFilePickerFilter
121126
private buttons: IFilePickerButton[] | IFilePickerButtonFactory = []
122127
private container?: string
128+
private disabledNavigation = false
123129

124130
/**
125131
* Construct a new FilePicker
@@ -273,6 +279,16 @@ export class FilePickerBuilder<IsMultiSelect extends boolean> {
273279
return this
274280
}
275281

282+
/**
283+
* Allow to pick directories besides files
284+
*
285+
* @param allow True to allow picking directories
286+
*/
287+
public disableNavigation() {
288+
this.disabledNavigation = true
289+
return this
290+
}
291+
276292
/**
277293
* Construct the configured FilePicker
278294
*/
@@ -285,6 +301,8 @@ export class FilePickerBuilder<IsMultiSelect extends boolean> {
285301
this.buttons,
286302
this.path,
287303
this.filter,
304+
this.container,
305+
this.disabledNavigation,
288306
)
289307
}
290308

0 commit comments

Comments
 (0)