Skip to content

Commit f637d87

Browse files
fix(popover): fix style issue, users can add styles
1 parent a5eb70c commit f637d87

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

apps/website/src/routes/docs/headless/(components)/popover/examples/hero.css

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import { component$ } from '@builder.io/qwik';
22
import { Popover } from '@qwik-ui/headless';
3-
import './hero.css';
43

54
export default component$(() => {
6-
/* same as tailwind slate */
7-
85
return (
96
<>
10-
<button popovertarget="example-id">Open Popover!</button>
11-
<Popover id="example-id">I'm on top of everything!</Popover>
7+
<button
8+
popovertarget="example-id"
9+
class="rounded-md border-2 border-slate-300 bg-slate-800 px-3 py-1 text-white"
10+
>
11+
Popover Trigger
12+
</button>
13+
<Popover
14+
id="example-id"
15+
class="shadow-dark-medium py- rounded-md border-2 border-slate-300 bg-slate-800 px-3 py-1"
16+
>
17+
Popover
18+
</Popover>
1219
</>
1320
);
1421
});

apps/website/src/routes/docs/headless/(components)/popover/index.mdx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ A popover is a **non-modal** UI element that creates overlays around a DOM eleme
2828

2929
This is particularly useful for displaying additional information or options without navigating away from the current context. It is also a **native replacement for [portals](https://qwik.builder.io/docs/cookbook/portal/#portal)**, which are commonly used in other JavaScript frameworks.
3030

31-
> A common use case for a popover, is preventing overflow issues within your UI. The popover API guarantees that your content remains above the rest of the page.
31+
> An example use case for a popover, is preventing overflow issues within your UI. The popover API guarantees that your content remains above the rest of the page.
3232
33-
Most importantly, this API is a foundation for other headless components.
33+
Most importantly, this API is a foundation for other headless components. Qwik UI is one of the first *(if not the first)* headless libraries to align with the specification. The content inside of Qwik UI popovers are also natively resumable.
3434

35-
## Example use cases
35+
## Versatile Use Cases
3636

37-
Here are a couple of example components where the Popover API can be used. Including other parts of Qwik UI headless. Throughout the part of the documentation, we will show the Combobox being used as an example.
38-
39-
The content inside of Qwik UI popovers are resumable and built with Qwik in mind.
37+
Here are a couple of example components where the Popover API can be used. Including other parts of Qwik UI headless. Throughout the documentation, we will show the Combobox being used as an example.
4038

4139
<AnatomyTable
4240
propDescriptors={[
@@ -75,3 +73,10 @@ The content inside of Qwik UI popovers are resumable and built with Qwik in mind
7573
]}
7674
/>
7775

76+
## Caveats
77+
78+
1. The polyfill for the native popover's `:popover-open` pseudo selector uses the `.popover-open` CSS class instead. This class is added to any open popover. With that said, both can be selected using the native way.
79+
80+
2. Styling a popover using .popover-open needs a separate declaration. Using :popover-open in CSS that doesn't support native popover will result in an invalid selector.
81+
82+
3. For **native invokers** (buttons or inputs using the popovertarget attribute) on `popover=auto`, the polyfill sets the `aria-expanded` attribute to render them in the accessibility tree as elements with expanded.

packages/kit-headless/src/components/popover/popover-impl.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ export const loadPolyfill$ = $(async () => {
4141
import('@oddbird/popover-polyfill'),
4242
import('@oddbird/popover-polyfill/dist/popover.css?inline'),
4343
]);
44-
// Inject the polyfill CSS into head
44+
// Inject the polyfill CSS into head BEFORE everything else so that users can override it without important or inline
4545
const styleNode = document.createElement('style');
4646
styleNode.setAttribute('data-qwik-ui-popover-polyfill', '');
4747
styleNode.textContent = css;
48-
document.head.appendChild(styleNode);
48+
document.head.insertBefore(styleNode, document.head.firstChild);
4949
});
5050

5151
// This component is a polyfill for the popover API
@@ -147,7 +147,7 @@ export const PopoverImpl = component$<PopoverImplProps>((props) => {
147147
<>
148148
{isServer && <div data-qui-popover-pf />}
149149
<div
150-
popover={props.popover}
150+
popover={props.popover === 'manual' ? 'manual' : 'auto'}
151151
class={[props.preset, props.class]}
152152
{...props}
153153
ref={childRef}

0 commit comments

Comments
 (0)