Skip to content

Commit

Permalink
fix: added as prop in sidenavmenuitem (#18056)
Browse files Browse the repository at this point in the history
Co-authored-by: Gururaj J <[email protected]>
  • Loading branch information
riddhybansal and Gururajj77 authored Nov 18, 2024
1 parent 6972097 commit a219b00
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7286,6 +7286,9 @@ Map {
"SideNavMenuItem" => Object {
"$$typeof": Symbol(react.forward_ref),
"propTypes": Object {
"as": Object {
"type": "elementType",
},
"children": Object {
"type": "node",
},
Expand Down
25 changes: 22 additions & 3 deletions packages/react/src/components/UIShell/SideNavMenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,23 @@ interface SideNavMenuItemProps extends ComponentProps<typeof Link> {
* Optionally provide an href for the underlying li`
*/
href?: string;

/**
* Optional component to render instead of default Link
*/
as?: ElementType;
}

const SideNavMenuItem = React.forwardRef<HTMLElement, SideNavMenuItemProps>(
function SideNavMenuItem(props, ref: ForwardedRef<HTMLElement>) {
const prefix = usePrefix();
const { children, className: customClassName, isActive, ...rest } = props;
const {
children,
className: customClassName,
as: Component = Link,
isActive,
...rest
} = props;
const className = cx(`${prefix}--side-nav__menu-item`, customClassName);
const linkClassName = cx({
[`${prefix}--side-nav__link`]: true,
Expand All @@ -48,9 +59,12 @@ const SideNavMenuItem = React.forwardRef<HTMLElement, SideNavMenuItemProps>(

return (
<li className={className}>
<Link {...rest} className={linkClassName} ref={ref as Ref<ElementType>}>
<Component
{...rest}
className={linkClassName}
ref={ref as Ref<ElementType>}>
<SideNavLinkText>{children}</SideNavLinkText>
</Link>
</Component>
</li>
);
}
Expand Down Expand Up @@ -79,6 +93,11 @@ SideNavMenuItem.propTypes = {
* `aria-current="page"`, as well.
*/
isActive: PropTypes.bool,

/**
* Optional component to render instead of default Link
*/
as: PropTypes.elementType,
};

export default SideNavMenuItem;

0 comments on commit a219b00

Please sign in to comment.