Skip to content

Commit

Permalink
Fix primefaces#5941: Menus consistent handling of URL and command
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Feb 13, 2024
1 parent 83fe22d commit d64a0d2
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 36 deletions.
9 changes: 5 additions & 4 deletions components/lib/breadcrumb/BreadCrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ export const BreadCrumb = React.memo(
return;
}

if (!item.url) {
event.preventDefault();
}

if (item.command) {
item.command({
originalEvent: event,
item
});
}

if (!item.url) {
event.preventDefault();
event.stopPropagation();
}
};

const isCurrent = (url) => {
Expand Down
9 changes: 5 additions & 4 deletions components/lib/contextmenu/ContextMenuSub.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ export const ContextMenuSub = React.memo(
return;
}

if (!item.url) {
event.preventDefault();
}

if (item.command) {
item.command({
originalEvent: event,
Expand All @@ -59,6 +55,11 @@ export const ContextMenuSub = React.memo(
if (!item.items) {
props.onLeafClick(event);
}

if (!item.url) {
event.preventDefault();
event.stopPropagation();
}
};

const position = () => {
Expand Down
8 changes: 4 additions & 4 deletions components/lib/megamenu/MegaMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,16 @@ export const MegaMenu = React.memo(
return;
}

if (!item.url) {
originalEvent.preventDefault();
}

if (item.command) {
item.command({
originalEvent: originalEvent,
item: props.item
});
}

if (!item.url) {
originalEvent.preventDefault();
originalEvent.stopPropagation();
}

const grouped = isProccessedItemGroup(processedItem);
Expand Down
9 changes: 5 additions & 4 deletions components/lib/menubar/MenubarSub.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ export const MenubarSub = React.memo(
return;
}

if (!item.url) {
event.preventDefault();
}

if (item.command) {
item.command({
originalEvent: event,
Expand All @@ -56,6 +52,11 @@ export const MenubarSub = React.memo(
}

onLeafClick({ originalEvent: event, processedItem, isFocus: true });

if (!item.url) {
event.preventDefault();
event.stopPropagation();
}
};

const onLeafClick = (event) => {
Expand Down
9 changes: 5 additions & 4 deletions components/lib/panelmenu/PanelMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ export const PanelMenu = React.memo(
return;
}

if (!item.url) {
event.preventDefault();
}

if (item.command) {
item.command({
originalEvent: event,
Expand All @@ -52,6 +48,11 @@ export const PanelMenu = React.memo(
if (item.items) {
changeActiveItem(event, item);
}

if (!item.url) {
event.preventDefault();
event.stopPropagation();
}
};

const getItemProp = (item, name) => {
Expand Down
9 changes: 5 additions & 4 deletions components/lib/slidemenu/SlideMenuSub.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ export const SlideMenuSub = React.memo((props) => {
return;
}

if (!item.url) {
event.preventDefault();
}

if (item.command) {
item.command({
originalEvent: event,
Expand All @@ -43,6 +39,11 @@ export const SlideMenuSub = React.memo((props) => {
setActiveItemState(item);
props.onForward();
}

if (!item.url) {
event.preventDefault();
event.stopPropagation();
}
};

const createSeparator = (index) => {
Expand Down
9 changes: 5 additions & 4 deletions components/lib/steps/Steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,18 @@ export const Steps = React.memo(
});
}

if (!item.url) {
event.preventDefault();
}

if (item.command) {
item.command({
originalEvent: event,
item,
index
});
}

if (!item.url) {
event.preventDefault();
event.stopPropagation();
}
};

const onItemKeyDown = (event, item, index) => {
Expand Down
9 changes: 5 additions & 4 deletions components/lib/tabmenu/TabMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ export const TabMenu = React.memo(
return;
}

if (!item.url) {
event.preventDefault();
}

if (item.command) {
item.command({
originalEvent: event,
Expand All @@ -70,6 +66,11 @@ export const TabMenu = React.memo(
} else {
setActiveIndexState(index);
}

if (!item.url) {
event.preventDefault();
event.stopPropagation();
}
};

const isSelected = (index) => {
Expand Down
9 changes: 5 additions & 4 deletions components/lib/tieredmenu/TieredMenuSub.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ export const TieredMenuSub = React.memo(
return;
}

if (!item.url) {
event.preventDefault();
}

if (item.command) {
item.command({
originalEvent: event,
Expand All @@ -61,6 +57,11 @@ export const TieredMenuSub = React.memo(
}

props.onItemClick && props.onItemClick({ originalEvent: event, processedItem });

if (!item.url) {
event.preventDefault();
event.stopPropagation();
}
};

const getItemId = (processedItem) => {
Expand Down

0 comments on commit d64a0d2

Please sign in to comment.