mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-26 07:11:00 -05:00
On latest `dev`, each sidebar section header in `Sidebar/Section.svelte` is a real `<button>` carrying `aria-expanded` and `aria-controls`, but it has **no activation handler**. The toggle comes only from `on:pointerup` on the wrapper inside `common/Collapsible.svelte`. Keyboard activation dispatches a synthetic `click`, never `pointerup`, and that wrapper's own `on:click` handler calls `stopPropagation()`. So pressing Enter or Space on the header does nothing at all, while `aria-expanded` tells assistive technology this is a working disclosure control. This affects every section in the sidebar: Models, Notes, Channels, Folders and Chats. Section state is persisted to `localStorage`, so a user whose section was collapsed on a previous visit has no keyboard way to open it again, and the content stays unreachable. Breaks WCAG 2.1.1 Keyboard (Level A), and 4.1.2 Name, Role, Value (Level A), because the exposed expanded state belongs to a control that cannot be operated. Fix: handle activation on the header button itself, where focus actually lands, and stop the now duplicate pointer path so a mouse click does not toggle twice. The existing inline `onChange` body is extracted to `setOpen` so the `change` dispatch and the `localStorage` write stay in one place and fire exactly once per toggle in both input modes. The adjacent "+" (`onAdd`) button already stops both `pointerup` and `click`, so it still does not toggle the section. `Collapsible`'s wrapper cannot simply become a `<button>` instead, because its slot receives buttons from this component and others, so the fix belongs here. `common/Folder.svelte` and `Sidebar/RecursiveFolder.svelte` have the same latent defect and are not touched by this PR. Severity: Critical. Sidebar navigation cannot be expanded without a mouse. ### Contributor License Agreement <!-- 🚨 DO NOT DELETE THE TEXT BELOW 🚨 Keep the "Contributor License Agreement" confirmation text intact. Deleting it will trigger the CLA-Bot to INVALIDATE your PR. Your PR will NOT be reviewed or merged until you check the box below confirming that you have read and agree to the terms of the CLA. --> - [x] By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. > [!NOTE] > Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.
175 lines
4.6 KiB
Svelte
175 lines
4.6 KiB
Svelte
<script lang="ts">
|
|
import { createEventDispatcher, onDestroy, onMount } from 'svelte';
|
|
|
|
import Collapsible from '$lib/components/common/Collapsible.svelte';
|
|
import Tooltip from '$lib/components/common/Tooltip.svelte';
|
|
import ChevronRight from './icons/ChevronRight.svelte';
|
|
import Plus from './icons/Plus.svelte';
|
|
|
|
const dispatch = createEventDispatcher();
|
|
type AddHandler = () => void | Promise<void>;
|
|
|
|
export let open = true;
|
|
export let id = '';
|
|
export let name = '';
|
|
export let collapsible = true;
|
|
export let className = '';
|
|
export let buttonClassName = '';
|
|
export let contentClassName = 'px-1.5';
|
|
export let onAddLabel = '';
|
|
export let onAdd: null | AddHandler = null;
|
|
export let dragAndDrop = true;
|
|
|
|
let sectionElement: HTMLDivElement;
|
|
let loaded = false;
|
|
let draggedOver = false;
|
|
|
|
const setOpen = (state: boolean) => {
|
|
open = state;
|
|
dispatch('change', state);
|
|
localStorage.setItem(`${id}-folder-state`, `${state}`);
|
|
};
|
|
|
|
const onDragOver = (e: DragEvent) => {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
draggedOver = true;
|
|
};
|
|
|
|
const onDrop = (e: DragEvent) => {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
|
|
if (!sectionElement.contains(e.target as Node)) {
|
|
return;
|
|
}
|
|
|
|
if (e.dataTransfer?.items && e.dataTransfer.items.length > 0) {
|
|
for (const item of Array.from(e.dataTransfer.items)) {
|
|
if (item.kind === 'file') {
|
|
const file = item.getAsFile();
|
|
if (file && file.type === 'application/json') {
|
|
const reader = new FileReader();
|
|
reader.onload = async function (event) {
|
|
try {
|
|
const fileContent = JSON.parse(event.target?.result as string);
|
|
open = true;
|
|
dispatch('import', fileContent);
|
|
} catch (error) {
|
|
console.error('Error parsing JSON file:', error);
|
|
}
|
|
};
|
|
reader.readAsText(file);
|
|
}
|
|
} else {
|
|
open = true;
|
|
try {
|
|
const dataTransfer = e.dataTransfer.getData('text/plain');
|
|
if (dataTransfer) {
|
|
dispatch('drop', JSON.parse(dataTransfer));
|
|
}
|
|
} catch {
|
|
// Ignore drops that are not sidebar JSON payloads.
|
|
} finally {
|
|
draggedOver = false;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
draggedOver = false;
|
|
};
|
|
|
|
const onDragLeave = (e: DragEvent) => {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
draggedOver = false;
|
|
};
|
|
|
|
onMount(() => {
|
|
const state = localStorage.getItem(`${id}-folder-state`);
|
|
if (state !== null) {
|
|
open = state === 'true';
|
|
}
|
|
|
|
loaded = true;
|
|
|
|
if (!dragAndDrop) {
|
|
return;
|
|
}
|
|
|
|
sectionElement.addEventListener('dragover', onDragOver);
|
|
sectionElement.addEventListener('drop', onDrop);
|
|
sectionElement.addEventListener('dragleave', onDragLeave);
|
|
});
|
|
|
|
onDestroy(() => {
|
|
if (!dragAndDrop) {
|
|
return;
|
|
}
|
|
|
|
sectionElement.removeEventListener('dragover', onDragOver);
|
|
sectionElement.removeEventListener('drop', onDrop);
|
|
sectionElement.removeEventListener('dragleave', onDragLeave);
|
|
});
|
|
</script>
|
|
|
|
<div bind:this={sectionElement} class="relative {className}">
|
|
{#if loaded}
|
|
{#if draggedOver}
|
|
<div
|
|
class="absolute inset-0 z-50 rounded-md bg-gray-100/50 pointer-events-none touch-none dark:bg-gray-700/20"
|
|
></div>
|
|
{/if}
|
|
|
|
{#if collapsible}
|
|
<Collapsible bind:open className="w-full" buttonClassName="w-full" onChange={setOpen}>
|
|
<div class="flex items-center justify-between h-6 w-full pl-3.5 pr-1.5 shrink-0">
|
|
<button
|
|
type="button"
|
|
class="group flex flex-1 h-full items-center gap-1 text-left text-xs text-gray-400 hover:text-gray-500 dark:text-gray-500 dark:hover:text-gray-400 transition-colors duration-100 {buttonClassName}"
|
|
aria-expanded={open}
|
|
aria-controls="{id}-content"
|
|
on:pointerup|stopPropagation
|
|
on:click={() => setOpen(!open)}
|
|
>
|
|
<span>{name}</span>
|
|
<span
|
|
class="flex opacity-0 group-hover:opacity-100 transition-all duration-100"
|
|
style="transform: rotate({open ? '90deg' : '0deg'})"
|
|
>
|
|
<ChevronRight className="size-[11px]" />
|
|
</span>
|
|
</button>
|
|
|
|
{#if onAdd}
|
|
<button
|
|
type="button"
|
|
class="flex items-center justify-center w-7 h-7 rounded-lg text-gray-300 hover:text-gray-500 dark:text-gray-600 dark:hover:text-gray-400 transition-colors duration-100"
|
|
aria-label={onAddLabel}
|
|
on:pointerup={(e) => {
|
|
e.stopPropagation();
|
|
}}
|
|
on:click={(e) => {
|
|
e.stopPropagation();
|
|
onAdd();
|
|
}}
|
|
>
|
|
<Tooltip content={onAddLabel}>
|
|
<Plus className="size-3.5" />
|
|
</Tooltip>
|
|
</button>
|
|
{/if}
|
|
</div>
|
|
|
|
<div id="{id}-content" slot="content" class="w-full {contentClassName}">
|
|
<slot></slot>
|
|
</div>
|
|
</Collapsible>
|
|
{:else}
|
|
<slot></slot>
|
|
{/if}
|
|
{/if}
|
|
</div>
|