Skip to content

Commit 6a50297

Browse files
authored
uui-menu-item: custom expand symbol render method (#1198)
* enable parsing a custom expand symbol render method * fix docs
1 parent e7d1ef9 commit 6a50297

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

packages/uui-menu-item/lib/uui-menu-item.element.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from '@umbraco-ui/uui-base/lib/mixins';
77
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
88
import { demandCustomElement } from '@umbraco-ui/uui-base/lib/utils';
9-
import { css, html, LitElement } from 'lit';
9+
import { css, html, LitElement, TemplateResult } from 'lit';
1010
import { property, state } from 'lit/decorators.js';
1111
import { ref } from 'lit/directives/ref.js';
1212
import { ifDefined } from 'lit/directives/if-defined.js';
@@ -122,6 +122,12 @@ export class UUIMenuItemElement extends SelectOnlyMixin(
122122
@property({ type: String, attribute: 'caret-label' })
123123
public caretLabel = 'Reveal the underlying items';
124124

125+
/**
126+
* Overwrite the expand symbol rendering, this replaces the Expand Symbol from UI Library.
127+
*/
128+
@property({ attribute: false })
129+
public renderExpandSymbol?: () => Element | TemplateResult<1> | undefined;
130+
125131
@state()
126132
private iconSlotHasContent = false;
127133

@@ -223,9 +229,7 @@ export class UUIMenuItemElement extends SelectOnlyMixin(
223229
id="caret-button"
224230
aria-label=${this.caretLabel}
225231
@click=${this._onCaretClicked}>
226-
<uui-symbol-expand
227-
aria-hidden="true"
228-
?open=${this.showChildren}></uui-symbol-expand>
232+
${this.#renderExpandSymbol()}
229233
</button>`
230234
: ''}
231235
${this.href && this.selectOnly !== true && this.selectable !== true
@@ -241,6 +245,19 @@ export class UUIMenuItemElement extends SelectOnlyMixin(
241245
`;
242246
}
243247

248+
#renderExpandSymbol() {
249+
if (this.renderExpandSymbol) {
250+
const result = this.renderExpandSymbol();
251+
if (result) {
252+
return result;
253+
}
254+
}
255+
256+
return html`<uui-symbol-expand
257+
aria-hidden="true"
258+
?open=${this.showChildren}></uui-symbol-expand>`;
259+
}
260+
244261
static styles = [
245262
css`
246263
:host {

packages/uui-menu-item/lib/uui-menu-item.story.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,40 @@ export const Nested: Story = {
126126
},
127127
};
128128

129+
export const CustomExpandSymbol: Story = {
130+
render: args => html`
131+
${labelNames.map(
132+
(name: string) =>
133+
html` <uui-menu-item
134+
label="${name}"
135+
.caretLabel="${args.caretLabel}"
136+
.renderExpandSymbol=${() => {
137+
return html`<uui-icon name="favorite"></uui-icon>`;
138+
}}
139+
has-children>
140+
${renderItems()}
141+
</uui-menu-item>`,
142+
)}
143+
`,
144+
parameters: {
145+
docs: {
146+
source: {
147+
code: html`
148+
<uui-menu-item
149+
label="Menu Item 1"
150+
has-children
151+
.renderExpandSymbol=${() => {
152+
return html`<uui-icon name="favorite"></uui-icon>`;
153+
}}>
154+
<uui-menu-item label="Nested Menu Item 1"></uui-menu-item>
155+
<uui-menu-item label="Nested Menu Item 2"></uui-menu-item>
156+
</uui-menu-item>
157+
`.strings,
158+
},
159+
},
160+
},
161+
};
162+
129163
export const Active: Story = {
130164
render: () => {
131165
const [activeIndex, setActiveIndex] = useState<number>(1);

0 commit comments

Comments
 (0)