Skip to content

Commit

Permalink
chore(@clayui/core): fixes typing error and deduplicates code
Browse files Browse the repository at this point in the history
  • Loading branch information
matuzalemsteles committed Dec 5, 2024
1 parent a0626c1 commit 3c43c64
Showing 1 changed file with 26 additions and 32 deletions.
58 changes: 26 additions & 32 deletions packages/clay-core/src/vertical-nav/VerticalNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@ const Trigger = ({
</Button>
);

const Menubar = ({collection, value}) => {
return (
<Nav aria-orientation="vertical" nested role="menubar">
<VerticalNavContext.Provider value={value}>
<Collection collection={collection} />
</VerticalNavContext.Provider>
</Nav>
);
};

type Props<T extends Record<string, any> | string> = {
/**
* Flag to define which item has the active state/current page.
Expand Down Expand Up @@ -254,22 +244,30 @@ function VerticalNav<T extends Record<string, any> | string>({
return depthActive(items as Array<Record<string, any>>);
}, [active, items]);

const menubarValue = {
activeKey:
active && collection.hasItem(active)
? active
: hasDepthActive
? null
: undefined,
ariaCurrent: ariaCurrent ? 'page' : null,
childrenRoot: childrenRootRef,
close,
expandedKeys,
firstKey: collection.getFirstItem().key,
open,
spritemap,
toggle,
};
const content = (
<Nav aria-orientation="vertical" nested role="menubar">
<VerticalNavContext.Provider
value={{
activeKey:
active && collection.hasItem(active)
? active
: hasDepthActive
? null
: undefined,
ariaCurrent: ariaCurrent ? 'page' : null,
childrenRoot: childrenRootRef,
close,
expandedKeys,
firstKey: collection.getFirstItem().key,
open,
spritemap,
toggle,
}}
>
<Collection collection={collection} />
</VerticalNavContext.Provider>
</Nav>
);

return (
<nav
Expand Down Expand Up @@ -303,16 +301,12 @@ function VerticalNav<T extends Record<string, any> | string>({
})}
ref={containerRef}
>
<Menubar collection={collection} value={menubarValue} />
{content}
</div>
</>
)}

{displayType === 'primary' && (
<>
<Menubar collection={collection} value={menubarValue} />
</>
)}
{displayType === 'primary' && content}
</nav>
);
}
Expand Down

0 comments on commit 3c43c64

Please sign in to comment.