diff --git a/api-generator/components/megamenu.js b/api-generator/components/megamenu.js
index 5c295625ef..4398f863da 100644
--- a/api-generator/components/megamenu.js
+++ b/api-generator/components/megamenu.js
@@ -28,6 +28,18 @@ const MegaMenuProps = [
type: 'string',
default: 'horizontal',
description: 'Defines the orientation, valid values are horizontal and vertical.'
+ },
+ {
+ name: 'start',
+ type: 'any',
+ default: 'null',
+ description: 'The template of starting element.'
+ },
+ {
+ name: 'end',
+ type: 'any',
+ default: 'null',
+ description: 'The template of trailing element'
}
];
diff --git a/components/doc/megamenu/index.js b/components/doc/megamenu/index.js
index 2cc481f0a4..026e132c93 100644
--- a/components/doc/megamenu/index.js
+++ b/components/doc/megamenu/index.js
@@ -133,6 +133,9 @@ export class MegaMenuDemo extends Component {
];
}
+ const start = e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} height="40" className="mr-2">;
+ const end = ;
+
render() {
return (
@@ -142,6 +145,11 @@ export class MegaMenuDemo extends Component {
Vertical
+
+ Templating
+
+
+
);
@@ -270,6 +278,9 @@ const MegaMenuDemo = () => {
}
];
+ const start = e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} height="40" className="mr-2">;
+ const end = ;
+
return (
@@ -278,6 +289,11 @@ const MegaMenuDemo = () => {
Vertical
+
+ Templating
+
+
+
);
@@ -405,6 +421,9 @@ const MegaMenuDemo = () => {
}
];
+ const start = e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} height="40" className="mr-2">;
+ const end = ;
+
return (
@@ -413,6 +432,11 @@ const MegaMenuDemo = () => {
Vertical
+
+ Templating
+
+
+
);
@@ -543,6 +567,9 @@ const MegaMenuDemo = () => {
}
];
+ const start = e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} height="40" className="mr-2">;
+ const end = ;
+
return (
@@ -551,6 +578,11 @@ const MegaMenuDemo = () => {
Vertical
+
+ Templating
+
+
+
);
@@ -714,13 +746,14 @@ const items = [
Custom Content
- Any content inside the megamenu will be displayed on the right side by default. You may use ".ui-megamenu-custom" style class to change the location of the content.
+ The megamenu can display custom content by using the "start" and "end" properties.
{`
-
-
-
-
+ }
+ end={ }
+/>
`}
@@ -766,6 +799,18 @@ const items = [
horizontal
Defines the orientation, valid values are horizontal and vertical.
+
+ start
+ any
+ null
+ The template of starting element.
+
+
+ end
+ any
+ null
+ The template of trailing element
+
@@ -786,7 +831,7 @@ const items = [
Container element.
- p-menu-list
+ p-megamenu-root-list
List element.
diff --git a/components/lib/megamenu/MegaMenu.css b/components/lib/megamenu/MegaMenu.css
index 9ec0afc17b..e4d7dce3fc 100644
--- a/components/lib/megamenu/MegaMenu.css
+++ b/components/lib/megamenu/MegaMenu.css
@@ -38,6 +38,12 @@
list-style: none;
}
+.p-megamenu .p-megamenu-custom,
+.p-megamenu .p-megamenu-end {
+ margin-left: auto;
+ align-self: center;
+}
+
/* Horizontal */
.p-megamenu-horizontal .p-megamenu-root-list {
display: flex;
diff --git a/components/lib/megamenu/MegaMenu.d.ts b/components/lib/megamenu/MegaMenu.d.ts
index 32e748a50e..5651bde880 100644
--- a/components/lib/megamenu/MegaMenu.d.ts
+++ b/components/lib/megamenu/MegaMenu.d.ts
@@ -3,12 +3,19 @@ import { MenuItem } from '../menuitem';
type MegaMenuOrientationType = 'vertical' | 'horizontal';
+type MegaMenuStartTemplate = React.ReactNode | ((props: MegaMenuProps) => React.ReactNode);
+
+type MegaMenuEndTemplate = React.ReactNode | ((props: MegaMenuProps) => React.ReactNode);
+
+
export interface MegaMenuProps {
id?: string;
model?: MenuItem[];
style?: object;
className?: string;
orientation?: MegaMenuOrientationType;
+ start?: MegaMenuStartTemplate;
+ end?: MegaMenuEndTemplate;
children?: React.ReactNode;
}
diff --git a/components/lib/megamenu/MegaMenu.js b/components/lib/megamenu/MegaMenu.js
index 13ecb56290..c3b6707820 100644
--- a/components/lib/megamenu/MegaMenu.js
+++ b/components/lib/megamenu/MegaMenu.js
@@ -338,12 +338,28 @@ export const MegaMenu = React.memo(React.forwardRef((props, ref) => {
return null;
}
- const createCustomContent = () => {
- if (props.children) {
+ const createStartContent = () => {
+ if (props.start) {
+ const start = ObjectUtils.getJSXElement(props.start, props);
+
return (
-
- {props.children}
-
+
+ {start}
+
+ )
+ }
+
+ return null;
+ }
+
+ const createEndContent = () => {
+ if (props.end) {
+ const end = ObjectUtils.getJSXElement(props.end, props);
+
+ return (
+
+ {end}
+
)
}
@@ -356,14 +372,16 @@ export const MegaMenu = React.memo(React.forwardRef((props, ref) => {
'p-megamenu-vertical': props.orientation === 'vertical'
}, props.className);
const menu = createMenu();
- const customContent = createCustomContent();
+ const start = createStartContent();
+ const end = createEndContent();
return (
)
}));
@@ -375,5 +393,7 @@ MegaMenu.defaultProps = {
model: null,
style: null,
className: null,
- orientation: 'horizontal'
+ orientation: 'horizontal',
+ start: null,
+ end: null
}
diff --git a/components/lib/menubar/Menubar.js b/components/lib/menubar/Menubar.js
index a0f1b6b0ab..7fe4c84156 100644
--- a/components/lib/menubar/Menubar.js
+++ b/components/lib/menubar/Menubar.js
@@ -52,18 +52,6 @@ export const Menubar = React.memo(React.forwardRef((props, ref) => {
useCustomContent
}));
- const createCustomContent = () => {
- if (props.children) {
- return (
-
- {props.children}
-
- )
- }
-
- return null;
- }
-
const createStartContent = () => {
if (props.start) {
const start = ObjectUtils.getJSXElement(props.start, props);
diff --git a/pages/megamenu/index.js b/pages/megamenu/index.js
index f8f573724d..668fb7cc88 100644
--- a/pages/megamenu/index.js
+++ b/pages/megamenu/index.js
@@ -1,8 +1,10 @@
import React from 'react';
import { MegaMenu } from '../../components/lib/megamenu/MegaMenu';
+import { InputText } from '../../components/lib/inputtext/InputText';
import MegaMenuDoc from '../../components/doc/megamenu';
import { DocActions } from '../../components/doc/common/docactions';
import Head from 'next/head';
+import getConfig from 'next/config';
const MegaMenuDemo = () => {
@@ -119,6 +121,10 @@ const MegaMenuDemo = () => {
}
];
+ const contextPath = getConfig().publicRuntimeConfig.contextPath;
+ const start = e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} height="40" className="mr-2">;
+ const end = ;
+
return (
@@ -136,10 +142,15 @@ const MegaMenuDemo = () => {
Horizontal
-
+
Vertical
+
+ Templating
+
+
+