Skip to content

Commit 1ff2d38

Browse files
docs: improved popover intro
1 parent 64c18ce commit 1ff2d38

File tree

4 files changed

+46
-13
lines changed

4 files changed

+46
-13
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { component$ } from '@builder.io/qwik';
2+
import { Popover, PopoverTrigger } from '@qwik-ui/headless';
3+
export default component$(() => {
4+
return (
5+
<>
6+
<PopoverTrigger popovertarget="hero-id" class="popover-trigger">
7+
Popover Trigger
8+
</PopoverTrigger>
9+
<Popover id="hero-id" class="popover">
10+
My Hero!
11+
</Popover>
12+
</>
13+
);
14+
});

apps/website/src/routes/docs/headless/popover/examples/hero.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1-
import { component$ } from '@builder.io/qwik';
1+
import { component$, useSignal } from '@builder.io/qwik';
22
import { Popover, PopoverTrigger } from '@qwik-ui/headless';
3+
34
export default component$(() => {
5+
const triggerRef = useSignal<HTMLButtonElement>();
6+
47
return (
58
<>
6-
<PopoverTrigger popovertarget="hero-id" class="popover-trigger">
7-
Popover Trigger
9+
<PopoverTrigger ref={triggerRef} popovertarget="popover-id" class="popover-trigger">
10+
Click me
811
</PopoverTrigger>
9-
<Popover id="hero-id" class="popover">
10-
My Hero!
12+
<Popover
13+
anchorRef={triggerRef}
14+
floating={true}
15+
gutter={4}
16+
id="popover-id"
17+
class="popover"
18+
>
19+
I am anchored to the popover trigger!
1120
</Popover>
1221
</>
1322
);

apps/website/src/routes/docs/headless/popover/index.mdx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@ A non-modal primitive with overlays that open and close around a DOM element.
2323
]}
2424
/>
2525

26+
<Note status="warning">
27+
You are about to see a fixed scrolling popover. Yes, this behavior is intended. It is
28+
part of the native popover API! If you want to anchor items, there is a floating section
29+
that covers this behavior.
30+
</Note>
31+
32+
<Showcase name="basic" />
33+
2634
The Qwik UI Popover component is designed to align with the [HTML Popover API Specification](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API). As of now, native support for this API is around `82.5%`, and in almost every browser.
2735

28-
To ensure consistent behavior across all browsers, Qwik UI provides a `polyfill` for browser versions that do not support the API natively.
36+
To ensure consistent behavior across all browsers, Qwik UI provides a `polyfill` with feature parity for browser versions that do not support the API natively.
2937

3038
<div class="flex flex-col gap-2">
3139
<div>
@@ -296,7 +304,9 @@ useTask$(async ({ track }) => {
296304

297305
To use the popover API with floating elements, you can add the `floating={true}` prop to the Popover component. This API enables the use of JavaScript to dynamically position the listbox using the `top` & `left` absolute properties.
298306

299-
> Enabling the `floating={true}` property will introduce a slight increase in code size, as we currently utilize JavaScript to implement floating items. We've strived to keep it as minimal as possible, but powerful in building complex components in anticipation of the forthcoming anchor API.
307+
Enabling the `floating={true}` property will introduce a slight increase in code size, as we currently utilize JavaScript to implement floating items. We've strived to keep it as minimal as possible, but powerful in building complex components.
308+
309+
> Once the native anchor API is available in all browsers, you can remove the floating prop and use CSS instead! Smaller bundle size for the win!
300310
301311
To float an element, it must have an anchored element to latch onto. This can be done with the `anchorRef` prop.
302312

packages/kit-headless/src/components/popover/popover.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async function setup(page: Page, exampleName: string) {
1212
}
1313

1414
test('@Visual diff', async ({ page }) => {
15-
const { driver: d } = await setup(page, 'hero');
15+
const { driver: d } = await setup(page, 'basic');
1616
await expect(page).toHaveScreenshot('closed popover.png');
1717

1818
await d.getTrigger().click();
@@ -24,7 +24,7 @@ test.describe('Mouse Behavior', () => {
2424
test(`GIVEN a closed popover
2525
WHEN clicking on the trigger
2626
THEN the popover should be opened `, async ({ page }) => {
27-
const { driver: d } = await setup(page, 'hero');
27+
const { driver: d } = await setup(page, 'basic');
2828
await expect(d.getPopover()).toBeHidden();
2929

3030
await d.getTrigger().click();
@@ -35,7 +35,7 @@ test.describe('Mouse Behavior', () => {
3535
test(`GIVEN an open popover
3636
WHEN clicking elsewhere on the page
3737
THEN the popover should close`, async ({ page }) => {
38-
const { driver: d } = await setup(page, 'hero');
38+
const { driver: d } = await setup(page, 'basic');
3939

4040
await expect(d.getPopover()).toBeHidden();
4141
await d.getTrigger().click();
@@ -188,7 +188,7 @@ test.describe('Keyboard Behavior', () => {
188188
test(`GIVEN a closed popover
189189
WHEN focusing on the button and pressing the '${key}' key
190190
THEN the popover should open`, async ({ page }) => {
191-
const { driver: d } = await setup(page, 'hero');
191+
const { driver: d } = await setup(page, 'basic');
192192
await expect(d.getPopover()).toBeHidden();
193193

194194
await d.getTrigger().press(key);
@@ -198,7 +198,7 @@ test.describe('Keyboard Behavior', () => {
198198
test(`GIVEN an open popover
199199
WHEN focusing on the button and pressing the '${key}' key
200200
THEN the popover should close`, async ({ page }) => {
201-
const { driver: d } = await setup(page, 'hero');
201+
const { driver: d } = await setup(page, 'basic');
202202

203203
// Open the popover
204204
await d.openPopover(key);
@@ -211,7 +211,7 @@ test.describe('Keyboard Behavior', () => {
211211
test(`GIVEN an open popover
212212
WHEN focusing on the button and pressing the 'Escape' key
213213
THEN the popover should close and the trigger be focused`, async ({ page }) => {
214-
const { driver: d } = await setup(page, 'hero');
214+
const { driver: d } = await setup(page, 'basic');
215215

216216
// Open the popover
217217
await d.openPopover('Enter');

0 commit comments

Comments
 (0)