Skip to content

Commit 201f449

Browse files
authored
feat(uui-popover-container): set popover attribute automatically (#664)
* add popover default value * update docs
1 parent 1874eb3 commit 201f449

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

packages/uui-popover-container/lib/uui-popover-container.element.ts

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ export class UUIPopoverContainerElement extends LitElement {
7474
//TODO: Remove this polyfill when firefox supports the new popover API
7575
!HTMLElement.prototype.hasOwnProperty('popover') && polyfill.bind(this)();
7676

77+
if (!this.hasAttribute('popover')) {
78+
this.setAttribute('popover', '');
79+
}
80+
7781
super.connectedCallback();
7882

7983
this.addEventListener('focusout', this.#onFocusOut);

packages/uui-popover-container/lib/uui-popover-container.mdx

+9-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import * as stories from './uui-popover-container.story';
88
This component is a container for popovers. It is used to position the popover relative to the target element.
99
It is also a native popover. So everything descriped in the **[Popover API documentation](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API)** applies.
1010

11+
**Note**: The `popover` attribute that is required by the Popover API is automatically added to the uui-popover-container if it is not already present. So this attribute can be omitted, unless you want to change the default behavior. More information about this can be found in the **[Manual popover](#manual-popover)** section.
12+
1113
<div
1214
style={{
1315
borderLeft: '6px solid #f3d41b',
@@ -39,7 +41,7 @@ It is also a native popover. So everything descriped in the **[Popover API docum
3941

4042
```html
4143
<uui-button popovertarget="my-popover">Open Popover</uui-button>
42-
<uui-popover-container id="my-popover" popover>
44+
<uui-popover-container id="my-popover">
4345
My popover content
4446
</uui-popover-container>
4547
```
@@ -48,7 +50,7 @@ It is also a native popover. So everything descriped in the **[Popover API docum
4850

4951
```html
5052
<uui-button popovertarget="my-popover">Open Popover</uui-button>
51-
<uui-popover-container id="my-popover" popover placement="top-start">
53+
<uui-popover-container id="my-popover" placement="top-start">
5254
My popover content
5355
</uui-popover-container>
5456
```
@@ -57,7 +59,7 @@ It is also a native popover. So everything descriped in the **[Popover API docum
5759

5860
```html
5961
<uui-button popovertarget="my-popover">Open Popover</uui-button>
60-
<uui-popover-container id="my-popover" popover margin="10">
62+
<uui-popover-container id="my-popover" margin="10">
6163
My popover content
6264
</uui-popover-container>
6365
```
@@ -66,10 +68,10 @@ It is also a native popover. So everything descriped in the **[Popover API docum
6668

6769
```html
6870
<uui-button popovertarget="my-popover">Open Popover</uui-button>
69-
<uui-popover-container id="my-popover" popover>
71+
<uui-popover-container id="my-popover">
7072
My popover content
7173
<uui-button popovertarget="my-popover-2">Open another popover</uui-button>
72-
<uui-popover-container id="my-popover-2" popover>
74+
<uui-popover-container id="my-popover-2">
7375
My other popover content
7476
</uui-popover-container>
7577
</uui-popover-container>
@@ -93,7 +95,7 @@ As a result, you will need to manually close the popover either by clicking the
9395

9496
## Example: Tooltip
9597

96-
A tooltip is a small pop-up box that appears when the user hovers over an item, providing additional information or context about that item.
98+
A tooltip is a small pop-up box that appears when the user hovers over an item, providing additional information or context about that item.
9799
Note: The popover-container always needs a an element with the `popovertarget` attribute, even when it's not a button. This element is used as the anchor to position the popover.
98100

99101
```js
@@ -108,7 +110,7 @@ tooltipToggle.addEventListener('mouseleave', () => tooltipPopover.hide());
108110
Sometimes words such as
109111
<b id="tooltip-toggle" popovertarget="tooltip-popover">petrichor</b>
110112
needs some more explanation
111-
<uui-popover-container id="tooltip-popover" popover>
113+
<uui-popover-container id="tooltip-popover">
112114
A pleasant smell that frequently accompanies the first rain after a long
113115
period of warm, dry weather.
114116
</uui-popover-container>

0 commit comments

Comments
 (0)