diff --git a/src/components/popover/bl-popover.ts b/src/components/popover/bl-popover.ts
index f2e04b9b..a783e1f2 100644
--- a/src/components/popover/bl-popover.ts
+++ b/src/components/popover/bl-popover.ts
@@ -13,6 +13,7 @@ import {
Middleware,
MiddlewareState,
} from "@floating-ui/dom";
+import { getTarget } from "../../utilities/elements";
import { event, EventDispatcher } from "../../utilities/event";
import style from "./bl-popover.css";
@@ -176,15 +177,16 @@ export default class BlPopover extends LitElement {
}
set target(value: string | Element) {
- if (typeof value === "string") {
- this._target = document.getElementById(value) as Element;
- } else if (value instanceof Element) {
- this._target = value;
- } else {
+ const target = getTarget(value);
+
+ if (!target) {
console.warn(
"BlPopover target only accepts an Element instance or a string id of a DOM element."
);
+ return;
}
+
+ this._target = target;
}
/**
diff --git a/src/components/tooltip/bl-tooltip.stories.mdx b/src/components/tooltip/bl-tooltip.stories.mdx
index 4ed8732a..eea19f01 100644
--- a/src/components/tooltip/bl-tooltip.stories.mdx
+++ b/src/components/tooltip/bl-tooltip.stories.mdx
@@ -44,6 +44,13 @@ export const PlacementTemplate = (args) => html`
You can use this section to cancel your order.
`
+export const TargetAttrTemplate = (args) => html`
+
+ Target Attribute
+
+With Target
+`;
+
# Tooltip
ADR
@@ -153,6 +160,14 @@ For example, if there is not enough room on the top, the tooltip is shown on the
+## Target Attribute
+
+By using the target attribute, we can add a tooltip to the element.
+
+
+
## Reference
diff --git a/src/components/tooltip/bl-tooltip.test.ts b/src/components/tooltip/bl-tooltip.test.ts
index 92b62f0f..55add7bc 100644
--- a/src/components/tooltip/bl-tooltip.test.ts
+++ b/src/components/tooltip/bl-tooltip.test.ts
@@ -202,4 +202,54 @@ describe("bl-tooltip", () => {
expect(ev).to.exist;
expect(el.visible).to.be.false;
});
+
+ it("should work with target attribute", async () => {
+ // given
+ const el = await fixture(html`
+