Skip to content

Commit 2be957a

Browse files
committed
WIP 2
1 parent 8194e58 commit 2be957a

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

frontend/src/components/floating-menus/MenuList.svelte

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<svelte:options accessors={true} />
22

33
<script lang="ts">
4-
import { createEventDispatcher, tick } from "svelte";
4+
import { createEventDispatcher, tick, onDestroy, onMount } from "svelte";
55
66
import type { MenuListEntry } from "@graphite/wasm-communication/messages";
77
@@ -52,6 +52,13 @@
5252
$: virtualScrollingEndIndex = filteredEntries.length === 0 ? 0 : Math.min(filteredEntries[0].length, virtualScrollingStartIndex + 1 + 400 / virtualScrollingEntryHeight);
5353
$: startIndex = virtualScrollingEntryHeight ? virtualScrollingStartIndex : 0;
5454
55+
onMount(() => {
56+
if (open) addEventListener("keydown", keydown);
57+
});
58+
onDestroy(() => {
59+
removeEventListener("keydown", keydown);
60+
});
61+
5562
// Required to keep the highlighted item centered and to find a new highlighted item if necessary
5663
async function watchHighlightedWithSearch(filteredEntries: MenuListEntry[][], open: boolean) {
5764
if (highlighted && open) {
@@ -99,6 +106,9 @@
99106
}
100107
101108
function watchOpen(open: boolean) {
109+
if (open) addEventListener("keydown", keydown);
110+
else removeEventListener("keydown", keydown);
111+
102112
highlighted = activeEntry;
103113
dispatch("open", open);
104114
@@ -197,9 +207,7 @@
197207
198208
/// Handles keyboard navigation for the menu.
199209
// Returns a boolean indicating whether the entire menu stack should be dismissed.
200-
export function keydown(e: KeyboardEvent, submenu: boolean): boolean {
201-
console.log("Burp");
202-
210+
export function keydown(e: KeyboardEvent, submenu = false): boolean {
203211
// Interactive menus should keep the active entry the same as the highlighted one
204212
if (interactive) highlighted = activeEntry;
205213

frontend/src/components/widgets/buttons/TextButton.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
tabindex={disabled ? -1 : 0}
6666
data-floating-menu-spawner={menuListChildrenExists ? "" : "no-hover-transfer"}
6767
on:click={onClick}
68-
on:keydown={(e) => self?.keydown(e, false)}
6968
>
7069
{#if icon}
7170
<IconLabel {icon} />

frontend/src/components/widgets/inputs/DropdownInput.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
{tooltip}
6969
on:click={() => !disabled && (open = true)}
7070
on:blur={unFocusDropdownBox}
71-
on:keydown={(e) => menuList?.keydown(e, false)}
7271
tabindex={disabled ? -1 : 0}
7372
data-floating-menu-spawner
7473
>

frontend/src/components/widgets/inputs/FontInput.svelte

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,7 @@
104104

105105
<!-- TODO: Combine this widget into the DropdownInput widget -->
106106
<LayoutRow class="font-input">
107-
<LayoutRow
108-
class="dropdown-box"
109-
classes={{ disabled }}
110-
styles={{ "min-width": `${minWidth}px` }}
111-
{tooltip}
112-
tabindex={disabled ? -1 : 0}
113-
on:click={toggleOpen}
114-
on:keydown={(e) => menuList?.keydown(e, false)}
115-
data-floating-menu-spawner
116-
>
107+
<LayoutRow class="dropdown-box" classes={{ disabled }} styles={{ "min-width": `${minWidth}px` }} {tooltip} tabindex={disabled ? -1 : 0} on:click={toggleOpen} data-floating-menu-spawner>
117108
<TextLabel class="dropdown-label">{activeEntry?.value || ""}</TextLabel>
118109
<IconLabel class="dropdown-arrow" icon="DropdownArrow" />
119110
</LayoutRow>

0 commit comments

Comments
 (0)