From 41774ec075bef32c7171779f549b288e5bec056e Mon Sep 17 00:00:00 2001 From: Ryan Gossiaux Date: Tue, 28 Dec 2021 09:08:51 -1000 Subject: [PATCH] Fix searching for MenuItems --- src/lib/components/menu/MenuItem.svelte | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib/components/menu/MenuItem.svelte b/src/lib/components/menu/MenuItem.svelte index 9424e01..42fa0b2 100644 --- a/src/lib/components/menu/MenuItem.svelte +++ b/src/lib/components/menu/MenuItem.svelte @@ -25,8 +25,13 @@ $: buttonStore = $api.buttonStore; let elementRef: HTMLElement | undefined; - $: textValue = elementRef?.textContent?.toLowerCase().trim(); - $: data = { disabled, textValue } as MenuItemData; + $: textValue = elementRef?.textContent?.toLowerCase().trim() || ""; + // Fairly hacky (Svelte): only mutate the contents of the data object. + // On first registration, `data` will not contain the correct textValue, + // so it must be mutated afterwards + let data = { disabled, textValue } as MenuItemData; + $: data.disabled = disabled; + $: data.textValue = textValue; onMount(async () => { $api.registerItem(id, data);