Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions packages/uui-menu-item/lib/uui-menu-item.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@umbraco-ui/uui-base/lib/mixins';
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
import { demandCustomElement } from '@umbraco-ui/uui-base/lib/utils';
import { css, html, LitElement } from 'lit';
import { css, html, LitElement, TemplateResult } from 'lit';
import { property, state } from 'lit/decorators.js';
import { ref } from 'lit/directives/ref.js';
import { ifDefined } from 'lit/directives/if-defined.js';
Expand Down Expand Up @@ -122,6 +122,12 @@ export class UUIMenuItemElement extends SelectOnlyMixin(
@property({ type: String, attribute: 'caret-label' })
public caretLabel = 'Reveal the underlying items';

/**
* Overwrite the expand symbol rendering, this replaces the Expand Symbol from UI Library.
*/
@property({ attribute: false })
public renderExpandSymbol?: () => Element | TemplateResult<1> | undefined;

@state()
private iconSlotHasContent = false;

Expand Down Expand Up @@ -223,9 +229,7 @@ export class UUIMenuItemElement extends SelectOnlyMixin(
id="caret-button"
aria-label=${this.caretLabel}
@click=${this._onCaretClicked}>
<uui-symbol-expand
aria-hidden="true"
?open=${this.showChildren}></uui-symbol-expand>
${this.#renderExpandSymbol()}
</button>`
: ''}
${this.href && this.selectOnly !== true && this.selectable !== true
Expand All @@ -241,6 +245,19 @@ export class UUIMenuItemElement extends SelectOnlyMixin(
`;
}

#renderExpandSymbol() {
if (this.renderExpandSymbol) {
const result = this.renderExpandSymbol();
if (result) {
return result;
}
}

return html`<uui-symbol-expand
aria-hidden="true"
?open=${this.showChildren}></uui-symbol-expand>`;
}

static styles = [
css`
:host {
Expand Down
34 changes: 34 additions & 0 deletions packages/uui-menu-item/lib/uui-menu-item.story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,40 @@ export const Nested: Story = {
},
};

export const CustomExpandSymbol: Story = {
render: args => html`
${labelNames.map(
(name: string) =>
html` <uui-menu-item
label="${name}"
.caretLabel="${args.caretLabel}"
.renderExpandSymbol=${() => {
return html`<uui-icon name="favorite"></uui-icon>`;
}}
has-children>
${renderItems()}
</uui-menu-item>`,
)}
`,
parameters: {
docs: {
source: {
code: html`
<uui-menu-item
label="Menu Item 1"
has-children
.renderExpandSymbol=${() => {
return html`<uui-icon name="favorite"></uui-icon>`;
}}>
<uui-menu-item label="Nested Menu Item 1"></uui-menu-item>
<uui-menu-item label="Nested Menu Item 2"></uui-menu-item>
</uui-menu-item>
`.strings,
},
},
},
};

export const Active: Story = {
render: () => {
const [activeIndex, setActiveIndex] = useState<number>(1);
Expand Down
Loading