Skip to content

Commit

Permalink
Fix primefaces#5817: PanelMenu respect item.expanded prop
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Jan 23, 2024
1 parent b33953c commit c13ebf7
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions components/lib/panelmenu/PanelMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { PrimeReactContext } from '../api/Api';
import { useHandleStyle } from '../componentbase/ComponentBase';
import { CSSTransition } from '../csstransition/CSSTransition';
import { useMergeProps, useMountEffect } from '../hooks/Hooks';
import { useUpdateEffect } from '../hooks/useUpdateEffect';
import { ChevronDownIcon } from '../icons/chevrondown';
import { ChevronRightIcon } from '../icons/chevronright';
import { DomHandler, IconUtils, ObjectUtils, UniqueComponentId, classNames } from '../utils/Utils';
Expand Down Expand Up @@ -63,9 +62,7 @@ export const PanelMenu = React.memo(
if (props.expandedKeys) {
return props.expandedKeys[getItemProp(item, 'key')];
} else {
const result = props.multiple ? activeItemsState.some((subItem) => ObjectUtils.equals(item, subItem)) : ObjectUtils.equals(item, activeItemState);

return result || item.expanded;
return props.multiple ? activeItemsState.some((subItem) => ObjectUtils.equals(item, subItem)) : ObjectUtils.equals(item, activeItemState);
}
};

Expand Down Expand Up @@ -187,7 +184,7 @@ export const PanelMenu = React.memo(
const changeActiveItem = (event, item) => {
if (!isItemDisabled(item)) {
const active = isItemActive(item);
const isOpen = !active;
const isExpanded = !active;
const _activeItemState = activeItemState && ObjectUtils.equals(item, activeItemState) ? null : item;

setActiveItemState(_activeItemState);
Expand All @@ -208,8 +205,8 @@ export const PanelMenu = React.memo(
setActiveItemsState(activeItems);
}

changeExpandedKeys({ item, expanded: !active });
isOpen ? props.onOpen && props.onOpen({ originalEvent: event, item }) : props.onClose && props.onClose({ originalEvent: event, item });
changeExpandedKeys({ item, expanded: isExpanded });
isExpanded && event ? props.onOpen && props.onOpen({ originalEvent: event, item }) : props.onClose && props.onClose({ originalEvent: event, item });
}
};

Expand Down Expand Up @@ -248,8 +245,17 @@ export const PanelMenu = React.memo(
!idState && setIdState(UniqueComponentId());
});

useUpdateEffect(() => {
React.useEffect(() => {
setAnimationDisabled(true);

props.model &&
props.model.forEach((item) => {
if (item.expanded) {
changeActiveItem(null, item);
item.expanded = false;
}
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [props.model]);

const onEnter = () => {
Expand All @@ -262,7 +268,7 @@ export const PanelMenu = React.memo(
}

const key = item.id || idState + '_' + index;
const active = isItemActive(item);
const active = isItemActive(item) || item.expanded;
const iconClassName = classNames('p-menuitem-icon', item.icon);
const headerIconProps = mergeProps(
{
Expand Down

0 comments on commit c13ebf7

Please sign in to comment.