Fix target logic

This commit is contained in:
Cory LaViska
2021-02-08 11:01:30 -05:00
parent 295e2cd1c5
commit dc0edc597f
2 changed files with 8 additions and 4 deletions

4
src/components.d.ts vendored
View File

@@ -1303,7 +1303,7 @@ export namespace Components {
}
interface SlTooltip {
/**
* The tooltip's content.
* The tooltip's content. Alternatively, you can use the content slot.
*/
"content": string;
/**
@@ -3001,7 +3001,7 @@ declare namespace LocalJSX {
}
interface SlTooltip {
/**
* The tooltip's content.
* The tooltip's content. Alternatively, you can use the content slot.
*/
"content"?: string;
/**

View File

@@ -28,7 +28,7 @@ export class Tooltip {
@Element() host: HTMLSlTooltipElement;
/** The tooltip's content. */
/** The tooltip's content. Alternatively, you can use the content slot. */
@Prop() content = '';
/**
@@ -162,7 +162,11 @@ export class Tooltip {
}
getTarget() {
const target = this.host.querySelector('*:not(style)') as HTMLElement;
// Get the first child that isn't a <style> or content slot
const target = [...this.host.children].find(
el => el.tagName.toLowerCase() !== 'style' && el.getAttribute('slot') !== 'content'
) as HTMLElement;
if (!target) {
throw new Error('Invalid tooltip target: no child element was found.');
}