Skip to content

Commit

Permalink
Fixed #1011 - PanelMenu collapses on clicking the menu link instead o…
Browse files Browse the repository at this point in the history
…f being in expanded state
  • Loading branch information
mertsincan committed Mar 5, 2021
1 parent 3db2101 commit 48f224e
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions src/components/panelmenu/PanelMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,64 @@ class PanelMenuSub extends Component {
}

if (this.state.activeItem && this.state.activeItem === item) {
item.expanded = false;
this.setState({
activeItem: null
});
}
else {
let activeItem = this.state.activeItem;
if (activeItem) {
activeItem.expanded = false;
}

item.expanded = true;
this.setState({
activeItem: item
});
}
}

updateActiveItemState(item, isActive) {
let activeItem = this.state.activeItem;
if (activeItem) {
activeItem.expanded = isActive;
}

item.expanded = !isActive;
this.setState({
activeItem: !isActive ? item : null
});
}

findActiveItem() {
let activeItem = null;

if (this.props.model) {
this.props.model.forEach(item => {
if (item.expanded) {
if (!activeItem) {
activeItem = item;
}
else {
item.expanded = false;
}
}
});
}

return activeItem;
}

componentDidMount() {
const activeItem = this.findActiveItem();
if (activeItem) {
this.setState({
activeItem
});
}
}

renderSeparator(index) {
return (
<li key={'separator_' + index} className="p-menu-separator"></li>
Expand Down Expand Up @@ -189,17 +236,64 @@ export class PanelMenu extends Component {
}

if (this.state.activeItem && this.state.activeItem === item) {
item.expanded = false;
this.setState({
activeItem: null
});
}
else {
let activeItem = this.state.activeItem;
if (activeItem) {
activeItem.expanded = false;
}

item.expanded = true;
this.setState({
activeItem: item
});
}
}

updateActiveItemState(item, isActive) {
let activeItem = this.state.activeItem;
if (activeItem) {
activeItem.expanded = isActive;
}

item.expanded = !isActive;
this.setState({
activeItem: !isActive ? item : null
});
}

findActiveItem() {
let activeItem = null;

if (this.props.model) {
this.props.model.forEach(item => {
if (item.expanded) {
if (!activeItem) {
activeItem = item;
}
else {
item.expanded = false;
}
}
});
}

return activeItem;
}

componentDidMount() {
const activeItem = this.findActiveItem();
if (activeItem) {
this.setState({
activeItem
});
}
}

renderPanelIcon(item) {
const className = classNames('p-menuitem-icon', item.icon);

Expand Down

0 comments on commit 48f224e

Please sign in to comment.