Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideMininni-Fincons committed Mar 28, 2024
1 parent e26e72e commit 1276487
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,6 @@ export class SbbAutocompleteGridOptionElement extends SbbOptionBaseElement {
this.setSelectedViaUserInteraction(true);
}

protected setupHighlightHandler(event: Event): void {
const slotNodes = (event.target as HTMLSlotElement).assignedNodes();
const labelNodes = slotNodes.filter((el) => el.nodeType === Node.TEXT_NODE) as Text[];

// Disable the highlight if the slot contains more than just text nodes
if (
labelNodes.length === 0 ||
slotNodes.filter((n) => !(n instanceof Element) || n.localName !== 'template').length !==
labelNodes.length
) {
this.disableLabelHighlight = true;
return;
}
this.label = labelNodes
.map((l) => l.wholeText)
.filter((l) => l.trim())
.join();
}

protected override render(): TemplateResult {
return super.render();
}
Expand Down
21 changes: 20 additions & 1 deletion src/components/core/common-behaviors/option-base-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export abstract class SbbOptionBaseElement extends SbbDisabledMixin(SbbIconNameM

private _abort = new ConnectedAbortController(this);
protected abstract selectByClick(event: MouseEvent): void;
protected abstract setupHighlightHandler(event: Event): void;
// protected abstract setupHighlightHandler(event: Event): void;
protected abstract setAttributeFromParent(): void;

/**
Expand Down Expand Up @@ -126,6 +126,25 @@ export abstract class SbbOptionBaseElement extends SbbDisabledMixin(SbbIconNameM
}
}

protected setupHighlightHandler(event: Event): void {
const slotNodes = (event.target as HTMLSlotElement).assignedNodes();
const labelNodes = slotNodes.filter((el) => el.nodeType === Node.TEXT_NODE) as Text[];

// Disable the highlight if the slot contains more than just text nodes
if (
labelNodes.length === 0 ||
slotNodes.filter((n) => !(n instanceof Element) || n.localName !== 'template').length !==
labelNodes.length
) {
this.disableLabelHighlight = true;
return;
}
this.label = labelNodes
.map((l) => l.wholeText)
.filter((l) => l.trim())
.join();
}

protected getHighlightedLabel(): TemplateResult {
if (!this._highlightString || !this._highlightString.trim()) {
return html`${this.label}`;
Expand Down
19 changes: 2 additions & 17 deletions src/components/option/option/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,28 +102,13 @@ export class SbbOptionElement extends SbbOptionBaseElement {
}
}

protected setupHighlightHandler(event: Event): void {
protected override setupHighlightHandler(event: Event): void {
if (!this._isAutocomplete) {
this.disableLabelHighlight = true;
return;
}

const slotNodes = (event.target as HTMLSlotElement).assignedNodes();
const labelNodes = slotNodes.filter((el) => el.nodeType === Node.TEXT_NODE) as Text[];

// Disable the highlight if the slot contains more than just text nodes
if (
labelNodes.length === 0 ||
slotNodes.filter((n) => !(n instanceof Element) || n.localName !== 'template').length !==
labelNodes.length
) {
this.disableLabelHighlight = true;
return;
}
this.label = labelNodes
.map((l) => l.wholeText)
.filter((l) => l.trim())
.join();
super.setupHighlightHandler(event);
}

protected override renderIcon(): TemplateResult {
Expand Down

0 comments on commit 1276487

Please sign in to comment.