Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5817: PanelMenu respect item.expanded prop #5826

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading