Skip to content

Commit c6aafc0

Browse files
committed
enable parsing a custom expand symbol render method
1 parent a88759c commit c6aafc0

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

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

Lines changed: 12 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>;
130+
125131
@state()
126132
private iconSlotHasContent = false;
127133

@@ -222,9 +228,11 @@ export class UUIMenuItemElement extends SelectOnlyMixin(
222228
id="caret-button"
223229
aria-label=${this.caretLabel}
224230
@click=${this._onCaretClicked}>
225-
<uui-symbol-expand
226-
aria-hidden="true"
227-
?open=${this.showChildren}></uui-symbol-expand>
231+
${this.renderExpandSymbol
232+
? this.renderExpandSymbol()
233+
: html` <uui-symbol-expand
234+
aria-hidden="true"
235+
?open=${this.showChildren}></uui-symbol-expand>`}
228236
</button>`
229237
: ''}
230238
${this.href && this.selectOnly !== true && this.selectable !== true

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,35 @@ 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 label="Menu Item 1" has-children>
149+
<uui-menu-item label="Nested Menu Item 1"></uui-menu-item>
150+
<uui-menu-item label="Nested Menu Item 2"></uui-menu-item>
151+
</uui-menu-item>
152+
`.strings,
153+
},
154+
},
155+
},
156+
};
157+
129158
export const Active: Story = {
130159
render: () => {
131160
const [activeIndex, setActiveIndex] = useState<number>(1);

0 commit comments

Comments
 (0)