mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-29 06:32:52 +00:00
fix(a11y): opening a filter list from the keyboard moves focus to its options (#33025)
This commit is contained in:
parent
988602e135
commit
9aae241770
1 changed files with 17 additions and 2 deletions
|
|
@ -105,11 +105,21 @@
|
|||
}
|
||||
}
|
||||
|
||||
async function toggleOpen() {
|
||||
async function toggleOpen(focusContent = false) {
|
||||
open = !open;
|
||||
if (open) {
|
||||
await tick();
|
||||
positionContent();
|
||||
if (focusContent) {
|
||||
contentEl?.querySelector<HTMLElement>('button:not([disabled]), a[href], input')?.focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleTriggerKeydown(event) {
|
||||
if (event.target === triggerEl && (event.key === 'Enter' || event.key === ' ')) {
|
||||
event.preventDefault();
|
||||
toggleOpen(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -123,15 +133,19 @@
|
|||
|
||||
function handleKeydown(event) {
|
||||
if (event.key === 'Escape' && open) {
|
||||
const restoreFocus = contentEl?.contains(document.activeElement);
|
||||
open = false;
|
||||
onClose();
|
||||
if (restoreFocus) triggerEl?.focus();
|
||||
}
|
||||
}
|
||||
|
||||
export function selectItem(item) {
|
||||
const restoreFocus = contentEl?.contains(document.activeElement);
|
||||
value = item.value;
|
||||
open = false;
|
||||
onChange(value);
|
||||
if (restoreFocus) triggerEl?.focus();
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
@ -147,7 +161,8 @@
|
|||
class="focus-ring {triggerClass}"
|
||||
type="button"
|
||||
aria-expanded={open}
|
||||
on:click={toggleOpen}
|
||||
on:click={() => toggleOpen()}
|
||||
on:keydown={handleTriggerKeydown}
|
||||
>
|
||||
<slot name="trigger" {selectedLabel} {open}>
|
||||
<span class={labelClass}>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue