Skip to content

Commit

Permalink
fix: made changes to add isSelected prop to menuGroup (#514)
Browse files Browse the repository at this point in the history
* fix(MI-19): made changes to add highlight on menu group when it is not expanded

* fix(MI-19): fixed linting

* fix(MI-19): added changesety
  • Loading branch information
vivek-p44 authored Nov 29, 2023
1 parent 4d63af6 commit 409daa7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/gold-spies-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@project44-manifest/react': patch
---

added isSelected prop to menu group to highlight it when it is not expanded and one of it's child is
selected
2 changes: 2 additions & 0 deletions packages/react/src/components/MenuGroup/MenuGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const MenuGroup = React.forwardRef((props, forwardedRef) => {
labelProps,
onExpandedChange = noop,
startIcon,
isSelected = false,
...other
} = props;

Expand All @@ -43,6 +44,7 @@ export const MenuGroup = React.forwardRef((props, forwardedRef) => {
<MenuItem
{...itemProps}
endIcon={<StyledIcon {...iconProps} isExpanded={isExpanded} />}
isSelected={isSelected && !isExpanded} // Need to highlight menu group only if it not expanded
label={label}
labelProps={labelProps}
startIcon={startIcon}
Expand Down
4 changes: 4 additions & 0 deletions packages/react/src/components/MenuGroup/MenuGroup.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ export interface MenuGroupProps {
* Icon added before the button text.
*/
startIcon?: React.ReactElement;
/**
* Adds a highlight style when a submenu is selected and menu group is not in expanded mode.
*/
isSelected?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
} from './SideNavigationMenuGroup.types';

export const SideNavigationMenuGroup = React.forwardRef((props, forwardedRef) => {
const { className: classNameProp, isExpanded: isExpandedProp, ...other } = props;
const { className: classNameProp, isExpanded: isExpandedProp, isSelected, ...other } = props;

const { isOpen } = useNavigation();

Expand All @@ -22,6 +22,7 @@ export const SideNavigationMenuGroup = React.forwardRef((props, forwardedRef) =>
className={className}
isExpanded={!isOpen ? false : undefined}
isOpen={isOpen}
isSelected={isSelected}
/>
);
}) as ForwardRefComponent<SideNavigationMenuGroupElement, SideNavigationMenuGroupProps>;
Expand Down

0 comments on commit 409daa7

Please sign in to comment.