mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-21 20:59:20 +00:00
hotfix(ui-shell): HeaderNavMenu is possibly undefined
This commit is contained in:
parent
995a47450f
commit
5b9b680e51
1 changed files with 18 additions and 6 deletions
|
@ -17,13 +17,24 @@
|
||||||
/** Obtain a reference to the HTML anchor element */
|
/** Obtain a reference to the HTML anchor element */
|
||||||
export let ref = null;
|
export let ref = null;
|
||||||
|
|
||||||
import { getContext } from "svelte";
|
import { getContext, onMount } from "svelte";
|
||||||
|
|
||||||
const id = "ccs-" + Math.random().toString(36);
|
const id = "ccs-" + Math.random().toString(36);
|
||||||
const { selectedItems, updateSelectedItems, closeMenu } =
|
const ctx = getContext("HeaderNavMenu");
|
||||||
getContext("HeaderNavMenu");
|
|
||||||
|
|
||||||
$: updateSelectedItems({ id, isSelected });
|
let selectedItemIds = [];
|
||||||
|
|
||||||
|
const unsubSelectedItems = ctx?.selectedItems.subscribe((_selectedItems) => {
|
||||||
|
selectedItemIds = Object.keys(_selectedItems);
|
||||||
|
});
|
||||||
|
|
||||||
|
$: ctx?.updateSelectedItems({ id, isSelected });
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
return () => {
|
||||||
|
if (unsubSelectedItems) unsubSelectedItems();
|
||||||
|
};
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<li role="none">
|
<li role="none">
|
||||||
|
@ -45,8 +56,9 @@
|
||||||
on:focus
|
on:focus
|
||||||
on:blur
|
on:blur
|
||||||
on:blur="{() => {
|
on:blur="{() => {
|
||||||
const ids = Object.keys($selectedItems);
|
if (selectedItemIds.indexOf(id) === selectedItemIds.length - 1) {
|
||||||
if (ids.indexOf(id) === ids.length - 1) closeMenu();
|
ctx?.closeMenu();
|
||||||
|
}
|
||||||
}}"
|
}}"
|
||||||
>
|
>
|
||||||
<span class:bx--text-truncate--end="{true}">{text}</span>
|
<span class:bx--text-truncate--end="{true}">{text}</span>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue