From 38d3f0e3905987bd857a132d8d5e229cad2c0bef Mon Sep 17 00:00:00 2001 From: Zola Richards Date: Mon, 16 Dec 2024 14:50:15 -0800 Subject: [PATCH] fix: (overlay): Changing getAssignedElementsFromSlot to return just the first element --- packages/overlay/src/OverlayTrigger.ts | 56 ++++++++++++------------ packages/radio/src/radio-overrides.css | 44 +++++++++---------- packages/radio/src/spectrum-radio.css | 2 +- packages/search/src/search-overrides.css | 20 ++++----- packages/search/src/spectrum-search.css | 25 ++++++----- 5 files changed, 77 insertions(+), 70 deletions(-) diff --git a/packages/overlay/src/OverlayTrigger.ts b/packages/overlay/src/OverlayTrigger.ts index 50b397f0b8..894f9c43c8 100644 --- a/packages/overlay/src/OverlayTrigger.ts +++ b/packages/overlay/src/OverlayTrigger.ts @@ -74,22 +74,22 @@ export class OverlayTrigger extends SpectrumElement { public receivesFocus: 'true' | 'false' | 'auto' = 'auto'; @state() - private clickContent: HTMLElement[] = []; + private clickContent: HTMLElement | null = null; private clickPlacement?: Placement; @state() - private longpressContent: HTMLElement[] = []; + private longpressContent: HTMLElement | null = null; private longpressPlacement?: Placement; @state() - private hoverContent: HTMLElement[] = []; + private hoverContent: HTMLElement | null = null; private hoverPlacement?: Placement; @state() - private targetContent: HTMLElement[] = []; + private targetContent: HTMLElement | null = null; @query('#click-overlay', true) clickOverlayElement!: Overlay; @@ -100,11 +100,14 @@ export class OverlayTrigger extends SpectrumElement { @query('#hover-overlay', true) hoverOverlayElement!: Overlay; - private getAssignedElementsFromSlot(slot: HTMLSlotElement): HTMLElement[] { + private getAssignedElementsFromSlot( + slot: HTMLSlotElement + ): HTMLElement | null { const nodes = slot.assignedNodes({ flatten: true }); - return [ - nodes.find((node) => node instanceof HTMLElement), - ] as HTMLElement[]; + const element = nodes.find( + (node) => node instanceof HTMLElement + ) as HTMLElement; + return element ? element : null; } private handleTriggerContent( @@ -158,22 +161,22 @@ export class OverlayTrigger extends SpectrumElement { protected override update(changes: PropertyValues): void { if (changes.has('clickContent')) { this.clickPlacement = - ((this.clickContent[0]?.getAttribute('placement') || - this.clickContent[0]?.getAttribute( + ((this.clickContent?.getAttribute('placement') || + this.clickContent?.getAttribute( 'direction' )) as Placement) || undefined; } if (changes.has('hoverContent')) { this.hoverPlacement = - ((this.hoverContent[0]?.getAttribute('placement') || - this.hoverContent[0]?.getAttribute( + ((this.hoverContent?.getAttribute('placement') || + this.hoverContent?.getAttribute( 'direction' )) as Placement) || undefined; } if (changes.has('longpressContent')) { this.longpressPlacement = - ((this.longpressContent[0]?.getAttribute('placement') || - this.longpressContent[0]?.getAttribute( + ((this.longpressContent?.getAttribute('placement') || + this.longpressContent?.getAttribute( 'direction' )) as Placement) || undefined; } @@ -189,17 +192,17 @@ export class OverlayTrigger extends SpectrumElement { protected renderClickOverlay(): TemplateResult { import('@spectrum-web-components/overlay/sp-overlay.js'); const slot = this.renderSlot('click-content'); - if (!this.clickContent.length) { + if (!this.clickContent) { return slot; } return html`