Skip to content

Commit 7ff83b8

Browse files
Merge pull request #58 from umbraco/bugfix/breadcrumbs
Bugfix/Breadcrumbs
2 parents cdaca54 + 9e2d61b commit 7ff83b8

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

packages/uui-breadcrumbs/lib/uui-breadcrumb-item.element.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ export class UUIBreadcrumbItemElement extends LitElement {
2020
color: currentColor;
2121
}
2222
23-
:host(:last-of-type) [part='separator'],
24-
:host([last-item]) [part='separator'] {
25-
display: none;
26-
}
27-
2823
[part='separator']::after {
2924
content: '/';
3025
speak: never;
@@ -71,10 +66,18 @@ export class UUIBreadcrumbItemElement extends LitElement {
7166
@property({ type: Boolean, attribute: 'last-item' })
7267
lastItem = false;
7368

69+
renderLinkAndSeparator() {
70+
return html`<a id="link" href=${this.href}><slot></slot></a
71+
><span part="separator"></span>`;
72+
}
73+
74+
renderCurrent() {
75+
return html`<span id="last-item"><slot></slot></span>`;
76+
}
77+
7478
render() {
7579
return html`${this.lastItem
76-
? html`<span id="last-item"><slot></slot></span>`
77-
: html`<a id="link" href=${this.href}><slot></slot></a>`}<span
78-
part="separator"></span>`;
80+
? this.renderCurrent()
81+
: this.renderLinkAndSeparator()}`;
7982
}
8083
}

packages/uui-breadcrumbs/lib/uui-breadcrumbs.element.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { css, html, LitElement } from 'lit';
2-
import { queryAssignedNodes } from 'lit/decorators.js';
32
import { UUIBreadcrumbItemElement } from './uui-breadcrumb-item.element';
43

54
/**
@@ -26,28 +25,27 @@ export class UUIBreadcrumbsElement extends LitElement {
2625
`,
2726
];
2827

29-
@queryAssignedNodes(undefined, true, 'uui-breadcrumb-item')
30-
_breadcrumbs?: UUIBreadcrumbItemElement[];
31-
32-
private _setLastItem() {
33-
if (this._breadcrumbs) {
34-
this._breadcrumbs[this._breadcrumbs.length - 1].lastItem = true;
35-
this._breadcrumbs[this._breadcrumbs.length - 1].setAttribute(
36-
'aria-current',
37-
'page'
38-
);
39-
}
40-
}
41-
4228
connectedCallback() {
4329
super.connectedCallback();
4430
this.setAttribute('aria-label', 'breadcrumb');
4531
this.setAttribute('role', 'navigation');
4632
}
4733

34+
handleSlotChange() {
35+
const breadcrumbNodes = this.querySelectorAll('uui-breadcrumb-item');
36+
const breadcrumbs = Array.from(
37+
breadcrumbNodes
38+
) as UUIBreadcrumbItemElement[];
39+
40+
if (breadcrumbs?.length > 0) {
41+
breadcrumbs[breadcrumbs.length - 1].lastItem = true;
42+
breadcrumbs[breadcrumbs.length - 1].setAttribute('aria-current', 'page');
43+
}
44+
}
45+
4846
render() {
4947
return html`<ol id="breadcrumbs-list">
50-
<slot @slotchange=${this._setLastItem}></slot>
48+
<slot @slotchange=${this.handleSlotChange}></slot>
5149
</ol>`;
5250
}
5351
}

0 commit comments

Comments
 (0)