Skip to content

Folder Picker

A text field for a server path with a Browse button. Browse opens a dialog that lists the server's drives, then a folder's subfolders, with a row to go up a level, an editable path, and a Select button that writes the path to the field.

Decision

When Use
A folder or file on the Jellyfin server, such as a media folder or an export path Folder Picker
A file from the user's own computer File Picker
An image from the user's own computer Image Picker

Usage

import { createFolderPicker } from './configurationpage?name=myplugin_stolon.js';

var folder = createFolderPicker({
    label: 'Media Folder',
    placeholder: '/media/movies',
    value: config.MediaPath,
    onChange: function (value) { config.MediaPath = value; tracker.check(); }
});
container.appendChild(folder.element);

Classes: stolon-folder-picker, stolon-folder-picker-field, stolon-folder-picker-browser, stolon-folder-picker-list, stolon-folder-picker-entry. The handle is { element, input, getValue, setValue, browse, setHeight, setSize, destroy }.

Parts: stolon-folder-picker-label, stolon-folder-picker-description, stolon-folder-picker-browse, stolon-folder-picker-dialog, stolon-folder-picker-path, stolon-folder-picker-up, stolon-folder-picker-file, stolon-folder-picker-name, stolon-folder-picker-empty, stolon-folder-picker-select.

States and Modifiers

  • By default it reads Environment/Drives, Environment/DirectoryContents, and Environment/ParentPath through ApiClient. These are admin routes, so the field suits a config page.
  • listFolders(path, includeFiles) replaces the routes and returns entries { Name, Path, Type }, or a promise of them. The empty path is the top level. parentPath(path) returns the path above, and '' or null means the top level. With listFolders and no parentPath, the parent comes from the path's text.
  • includeFiles: true lists files too. A click on a file fills the path and marks that row alone selected with aria-pressed, and Select confirms it.
  • Each row is a button built as stolon-icon-text, so its icon lines up with the first line of a long name.
  • The dialog opens at the field's path, or at the top level when the field is empty. Select stays disabled while the path is empty.
  • Rows are buttons, so Enter and Space open a folder. Enter in the path field opens the typed path. Escape closes the dialog, and focus returns to Browse.
  • The dialog's rows are a List, so height and maxHeight take what a List takes, and setHeight(height, maxHeight) changes them later. maxHeight is '50vh' by default, and null removes the cap.
  • The List's loading line shows in the list while a folder loads. A folder with nothing to list shows the List's empty sentence, stolon-list-empty outside, under the list. A folder that cannot be read shows the error under the list instead, and the up row stays.
  • The defaults are "Browse" (browseText), "Select a folder" (title), "Select" (selectText), "Cancel" (cancelText), "Go up" (upText), "Path" (pathLabel), "Loading" (loadingText), "This folder is empty." (emptyText), and "Could not read this folder." (errorText).
  • onChange(value) runs on typing and on a Select that changes the path. setValue does not call it.
  • size is small, medium (default), or large, and sizes its fields on the size scale. setSize(size) changes it later.

Reference

Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.

createFolderPicker

function createFolderPicker(options?: FolderPickerOptions): FolderPickerHandle

A text field for a server path with a Browse button. Browse opens a dialog that lists the server's drives, then a folder's subfolders, with a row to go up a level, an editable path, and a Select button that writes the path to the field.

Option Type What it does
value string | null first path [optional]
label string visible label of the field [optional]
placeholder string a valid example path [optional]
description string sentence under the field [optional]
pathLabel string aria-label of the field without a label, and of the dialog's path field (default 'Path')
browseText string text of the browse button (default 'Browse')
title string dialog title (default 'Select a folder')
selectText string text of the select button (default 'Select')
cancelText string text of the cancel button (default 'Cancel')
upText string text of the row that goes up a level (default 'Go up')
loadingText string text a screen reader reads while a folder loads (default 'Loading')
emptyText string sentence shown for a folder with nothing to list (default 'This folder is empty.')
errorText string message under the list when a folder cannot be read (default 'Could not read this folder.')
includeFiles boolean true lists files too, so a file can be picked (default false)
height ListHeight the dialog list's height, 'auto', 'fill', a number of pixels, or a CSS length, as a List takes it (default 'auto')
maxHeight number | string | null the most the dialog list grows before it scrolls, or null for no cap (default '50vh')
size 'small' | 'medium' | 'large' 'small', 'medium', or 'large' for its fields (default 'medium')
listFolders (path: string, includeFiles: boolean): FolderEntry[] | PromiseLike<FolderEntry[]> function(path, includeFiles) returning entries { Name, Path, Type }, or a promise of them, where '' is the top level (default the Jellyfin Environment routes) [optional]
parentPath (path: string): string | null | PromiseLike<string | null> function(path) returning the path above, or '' or null for the top level (default Environment/ParentPath, or the path's text when listFolders is given) [optional]
onChange (value: string): void function(value) called when the path changes by typing or Select [optional]
Handle member Type
input HTMLInputElement
getValue (): string
setValue (value: string | null): void
browse (): void
setSize (size?: 'small' | 'medium' | 'large'): void
setHeight (height: ListHeight, maxHeight?: number | string | null): void
destroy (): void
Type What it is
FolderEntry One entry in a folder, as Jellyfin's Environment routes return it. Type is 'Directory', 'File', 'NetworkComputer', or 'NetworkShare'.
Class What it looks like
stolon-folder-picker A path field with a Browse button beside it, a label above, and a description below
stolon-folder-picker-browser Dialog body with the editable path, the list of folders with its loading line, the list's empty sentence, and the error
stolon-folder-picker-entry One folder, drive, or file in the list as a full width button built as stolon-icon-text, with the up row first

Example

Example Code

<!-- title: Folder Picker -->
<!-- min-height: 460 -->
<div id="mount"></div>
<div id="folderStatus" class="stolon-status-text"></div>
<script type="module">
const base = await window.__baseReady;
const mount = document.getElementById('mount');
const status = document.getElementById('folderStatus');
const tree = {
    '': [{ Name: '/', Path: '/', Type: 'Directory' }],
    '/': [{ Name: 'media', Path: '/media', Type: 'Directory' }, { Name: 'srv', Path: '/srv', Type: 'Directory' }],
    '/media': [{ Name: 'movies', Path: '/media/movies', Type: 'Directory' }, { Name: 'shows', Path: '/media/shows', Type: 'Directory' }, { Name: 'cover.jpg', Path: '/media/cover.jpg', Type: 'File' }],
    '/media/movies': [],
    '/media/shows': [{ Name: 'Season 1', Path: '/media/shows/Season 1', Type: 'Directory' }],
    '/media/shows/Season 1': [],
    '/srv': []
};
const listFolders = (path) => new Promise((resolve, reject) => {
    setTimeout(() => (path in tree ? resolve(tree[path]) : reject(new Error('missing'))), 300);
});
mount.appendChild(base.createFolderPicker({
    label: 'Media Folder',
    placeholder: '/media/movies',
    description: 'The folder the plugin reads from.',
    value: '/media',
    listFolders: listFolders,
    onChange: (value) => { status.textContent = 'Path is ' + value + '.'; }
}).element);
mount.appendChild(base.createFolderPicker({
    label: 'Cover File',
    title: 'Select a File',
    includeFiles: true,
    listFolders: listFolders
}).element);
</script>