Skip to content

Commit 0a68611

Browse files
committed
replace popover renderer with slotted content
1 parent 45c82c6 commit 0a68611

File tree

1 file changed

+24
-29
lines changed

1 file changed

+24
-29
lines changed

src/component/vcf-breadcrumbs.ts

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export class VcfBreadcrumbs extends ResizeMixin(ElementMixin(PolylitMixin(LitEle
274274
* @returns {HTMLElement} An ellipsis breadcrumb element with an associated popover
275275
*/
276276
_createEllipsisBreadcrumb(hiddenItems: HTMLElement[]) {
277-
let ellipsis = document.createElement("vcf-breadcrumb");
277+
const ellipsis = document.createElement("vcf-breadcrumb");
278278
const id = "ellipsis-" + crypto.randomUUID();
279279
ellipsis.setAttribute("id", id);
280280
ellipsis.setAttribute("part", "ellipsis");
@@ -286,41 +286,36 @@ export class VcfBreadcrumbs extends ResizeMixin(ElementMixin(PolylitMixin(LitEle
286286
ellipsis.style.minWidth = '0';
287287

288288
// Create a popover to show the hidden breadcumbs and add it to the ellipsis element
289-
let popover = document.createElement("vaadin-popover");
289+
const popover = document.createElement("vaadin-popover");
290290
popover.setAttribute("for", id);
291291
popover.setAttribute("overlay-role", "menu");
292292
popover.setAttribute('accessible-name-ref', "hidden breadcrumbs");
293293
popover.setAttribute("theme", "hidden-breadcrumbs");
294294
popover.setAttribute("position", "bottom-start");
295295
popover.setAttribute("modal", "true");
296296

297-
popover.renderer = (root) => {
298-
// Ensure content is only added once
299-
if (!root.firstChild) {
300-
const verticalLayout = document.createElement('vaadin-vertical-layout');
301-
verticalLayout.classList.add('hidden-breadcrumbs-layout');
302-
303-
// create new anchor elements for the hidden items and add them to the vertical layout
304-
hiddenItems.forEach((element) => {
305-
const item = document.createElement('a');
306-
item.textContent = element.textContent;
307-
item.setAttribute("href", element.getAttribute('href') ?? '');
308-
item.setAttribute("role", "menuitem");
309-
// Copy element class list
310-
const elementClasses = Array.from(element.classList);
311-
item.classList.add(...elementClasses);
312-
item.classList.add("hidden-breadcrumb-anchor");
313-
314-
// Add click event to close popover when clicking an item
315-
item.addEventListener("click", () => {
316-
popover.opened = false;
317-
});
318-
319-
verticalLayout.appendChild(item);
320-
});
321-
root.appendChild(verticalLayout);
322-
}
323-
};
297+
const verticalLayout = document.createElement('vaadin-vertical-layout');
298+
verticalLayout.classList.add('hidden-breadcrumbs-layout');
299+
300+
// create new anchor elements for the hidden items and add them to the vertical layout
301+
hiddenItems.forEach((element) => {
302+
const item = document.createElement('a');
303+
item.textContent = element.textContent;
304+
item.setAttribute("href", element.getAttribute('href') ?? '');
305+
item.setAttribute("role", "menuitem");
306+
// Copy element class list
307+
const elementClasses = Array.from(element.classList);
308+
item.classList.add(...elementClasses);
309+
item.classList.add("hidden-breadcrumb-anchor");
310+
311+
// Add click event to close popover when clicking an item
312+
item.addEventListener("click", () => {
313+
popover.opened = false;
314+
});
315+
316+
verticalLayout.appendChild(item);
317+
});
318+
popover.appendChild(verticalLayout);
324319

325320
// append popover to ellipsis to move it later to the anchor within the container
326321
ellipsis.appendChild(popover);

0 commit comments

Comments
 (0)