Fixed #3599 - Menu: start and end templating

pull/3608/head
Tuğçe Küçükoğlu 2023-01-27 16:25:28 +03:00
parent f1b1cdf189
commit cf635e5caa
4 changed files with 45 additions and 1 deletions

View File

@ -49,6 +49,14 @@ const MenuEvents = [
]; ];
const MenuSlots = [ const MenuSlots = [
{
name: 'start',
description: 'Custom content before the content'
},
{
name: 'end',
description: 'Custom content after the content'
},
{ {
name: 'item', name: 'item',
description: 'Template of a menuitem.' description: 'Template of a menuitem.'

View File

@ -49,6 +49,14 @@ export interface MenuProps {
} }
export interface MenuSlots { export interface MenuSlots {
/**
* Custom start template.
*/
start: () => VNode[];
/**
* Custom end template.
*/
end: () => VNode[];
/** /**
* Custom item template. * Custom item template.
* @param {Object} scope - item slot's params. * @param {Object} scope - item slot's params.

View File

@ -2,6 +2,9 @@
<Portal :appendTo="appendTo" :disabled="!popup"> <Portal :appendTo="appendTo" :disabled="!popup">
<transition name="p-connected-overlay" @enter="onEnter" @leave="onLeave" @after-leave="onAfterLeave"> <transition name="p-connected-overlay" @enter="onEnter" @leave="onLeave" @after-leave="onAfterLeave">
<div v-if="popup ? overlayVisible : true" :ref="containerRef" :id="id" :class="containerClass" v-bind="$attrs" @click="onOverlayClick"> <div v-if="popup ? overlayVisible : true" :ref="containerRef" :id="id" :class="containerClass" v-bind="$attrs" @click="onOverlayClick">
<div v-if="$slots.start" class="p-menu-start">
<slot name="start"></slot>
</div>
<ul <ul
:ref="listRef" :ref="listRef"
:id="id + '_list'" :id="id + '_list'"
@ -29,6 +32,9 @@
<PVMenuitem v-else :key="label(item) + i.toString()" :id="id + '_' + i" :item="item" :template="$slots.item" :exact="exact" :focusedOptionId="focusedOptionId" @item-click="itemClick" /> <PVMenuitem v-else :key="label(item) + i.toString()" :id="id + '_' + i" :item="item" :template="$slots.item" :exact="exact" :focusedOptionId="focusedOptionId" @item-click="itemClick" />
</template> </template>
</ul> </ul>
<div v-if="$slots.end" class="p-menu-end">
<slot name="end"></slot>
</div>
</div> </div>
</transition> </transition>
</Portal> </Portal>

View File

@ -93,12 +93,18 @@ toggle(event) {
</code></pre> </code></pre>
<h5>Templating</h5> <h5>Templating</h5>
<p>Menu offers content customization with the <i>item</i> template that receives the menuitem instance from the model as a parameter.</p> <p>Two slots named "start" and "end" are provided to embed content before or after the menu. In additon Menu, offers item customization with the <i>item</i> template that receives the menuitem instance from the model as a parameter.</p>
<pre v-code><code> <pre v-code><code>
&lt;Menu :model="items"&gt; &lt;Menu :model="items"&gt;
&lt;template #start&gt;
Start
&lt;/template&gt;
&lt;template #item="{item}"&gt; &lt;template #item="{item}"&gt;
&lt;a :href="item.url"&gt;&#123;&#123;item.label&#125;&#125;&lt;/a&gt; &lt;a :href="item.url"&gt;&#123;&#123;item.label&#125;&#125;&lt;/a&gt;
&lt;/template&gt; &lt;/template&gt;
&lt;template #end&gt;
End
&lt;/template&gt;
&lt;/Menu&gt; &lt;/Menu&gt;
</code></pre> </code></pre>
@ -265,6 +271,14 @@ toggle(event) {
<td>item</td> <td>item</td>
<td>item: Menuitem instance</td> <td>item: Menuitem instance</td>
</tr> </tr>
<tr>
<td>start</td>
<td>-</td>
</tr>
<tr>
<td>end</td>
<td>-</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>
@ -284,6 +298,14 @@ toggle(event) {
<td>p-menu</td> <td>p-menu</td>
<td>Container element.</td> <td>Container element.</td>
</tr> </tr>
<tr>
<td>p-menu-start</td>
<td>Container of the start slot.</td>
</tr>
<tr>
<td>p-menu-end</td>
<td>Container of the end slot.</td>
</tr>
<tr> <tr>
<td>p-menu-list</td> <td>p-menu-list</td>
<td>List element.</td> <td>List element.</td>