mirror of
https://github.com/siemens-mobile-hacks/web-tools.git
synced 2026-11-25 17:17:22 +00:00
fix opening drawer links on nav
This commit is contained in:
parent
0784faead6
commit
aaf0b80244
1 changed files with 9 additions and 3 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { Component, createMemo, createSignal, For, JSX, ParentComponent, Show } from "solid-js";
|
||||
import { Component, createEffect, createMemo, createSignal, For, JSX, ParentComponent, Show } from "solid-js";
|
||||
import { A, useMatch } from "@solidjs/router";
|
||||
import { Box, Drawer, List, ListItemButton, ListItemIcon, ListItemText, Toolbar, useMediaQuery } from '@suid/material';
|
||||
import ScreenshotIcon from '@suid/icons-material/Screenshot';
|
||||
|
|
@ -42,7 +42,7 @@ type DrawerLinkProps = {
|
|||
|
||||
export const DrawerLink: Component<DrawerLinkProps> = (props) => {
|
||||
const isSelected = () => props.url != null && matchURL(props.url);
|
||||
const isNestedSelected = () => {
|
||||
const isNestedSelected = createMemo(() => {
|
||||
if (props.sublinks) {
|
||||
for (const sublink of props.sublinks) {
|
||||
if (sublink.url && matchURL(sublink.url))
|
||||
|
|
@ -50,10 +50,16 @@ export const DrawerLink: Component<DrawerLinkProps> = (props) => {
|
|||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
});
|
||||
const [isOpen, setIsOpen] = createSignal(isNestedSelected());
|
||||
const depth = () => props.depth ?? 1;
|
||||
|
||||
createEffect(() => {
|
||||
// Update on navigation
|
||||
if (isNestedSelected())
|
||||
setIsOpen(true);
|
||||
});
|
||||
|
||||
return (
|
||||
<Show when={props.sublinks && props.sublinks.length > 0} fallback={
|
||||
<ListItemButton component={A} href={props.url ?? ""} selected={isSelected()} sx={{ pl: depth() * 2 }}>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue