Skip to content

Commit 4b05a77

Browse files
Merge pull request #691 from thejackshelton/popover-styles
Deprecate listbox class in favor of floating mode default
2 parents 87188c9 + cc40aed commit 4b05a77

File tree

6 files changed

+35
-49
lines changed

6 files changed

+35
-49
lines changed

.changeset/tough-keys-rest.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@qwik-ui/headless': patch
3+
---
4+
5+
refactor: popover listbox class deprecated and set as a default when in floating mode.

apps/website/src/routes/docs/headless/popover/examples/anchor-ref.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default component$(() => {
3535
placement="top"
3636
gutter={4}
3737
id="anchor-ref-id"
38-
class="my-transition listbox rounded-base border-2 border-slate-300 bg-slate-800 !p-4 text-white shadow-md"
38+
class="my-transition rounded-base border-2 border-slate-300 bg-slate-800 !p-4 text-white shadow-md"
3939
>
4040
I am anchored to the trigger!
4141
</Popover>

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

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ The browser support for these is similar to support of the popover API. That sai
172172

173173
```css
174174
.my-transition {
175-
transition: opacity 0.5s, display 0.5s, overlay 0.5s;
175+
transition:
176+
opacity 0.5s,
177+
display 0.5s,
178+
overlay 0.5s;
176179

177180
/* on new-line so the declaration is valid in all browsers */
178181
transition-behavior: allow-discrete;
@@ -324,7 +327,6 @@ For the following examples, we'll be using the Combobox component. `ComboboxPopo
324327
floating={true}
325328
// "stick" to the input
326329
anchorRef={context.inputRef}
327-
class="listbox"
328330
>
329331
<Slot />
330332
</Popover>
@@ -379,43 +381,17 @@ If Tailwind is the framework of choice, then styles can be added using the [arbi
379381

380382
> The arbitrary variant can be customized/abstracted even further by [adding a variant](https://tailwindcss.com/docs/plugins#adding-variants) as a plugin in the tailwind config.
381383
382-
### Listbox preset
384+
### Floating preset
383385

384-
By default, the popover API comes with built-in styles, including fixed behavior, margin, the list goes on.
386+
By default, the popover API comes with built-in user agent styles, including fixed behavior, margin, the list goes on.
385387

386-
There are times when we want to override this behavior. An example being when we want an absolutely positioned listbox.
388+
There are times when we want to override this behavior. An example being when we want floating behavior.
387389

388-
To do that, we can add the `listbox` class to the popover component.
390+
Qwik UI strips the following styles when in floating mode:
389391

390-
If you need to override any of the listbox properties, use the following CSS variables:
392+
<CodeSnippet name="floating.css" />
391393

392-
<AnatomyTable
393-
firstColumnLabel="Property"
394-
propDescriptors={[
395-
{
396-
name: 'margin',
397-
description: '--listbox-margin',
398-
},
399-
{
400-
name: 'padding',
401-
description: '--listbox-padding',
402-
},
403-
{
404-
name: 'border',
405-
description: '--listbox-border',
406-
},
407-
{
408-
name: 'overflow',
409-
description: '--listbox-overflow',
410-
},
411-
{
412-
name: 'position',
413-
description: '--listbox-position',
414-
},
415-
]}
416-
/>
417-
418-
> Another option is to use the `!important` syntax to override any of the CSS variable values.
394+
We put it under an `@layer` so that it can be easily overridden when adding your own styles.
419395

420396
## Animations
421397

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@layer qwik-ui {
2+
[data-floating] {
3+
margin: unset;
4+
padding: unset;
5+
border: unset;
6+
overflow: unset;
7+
position: absolute;
8+
}
9+
}

packages/kit-headless/src/components/popover/popover.css

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@
1010
display: block !important;
1111
}
1212

13-
/* Popover Presets: TODO figure out specificity to make this easier for user to override */
14-
.listbox {
15-
--listbox-margin: unset;
16-
--listbox-padding: unset;
17-
--listbox-border: unset;
18-
--listbox-overflow: unset;
19-
--listbox-position: absolute;
20-
21-
margin: var(--listbox-margin);
22-
padding: var(--listbox-padding);
23-
border: var(--listbox-border);
24-
overflow: var(--listbox-overflow);
25-
position: var(--listbox-position);
13+
/* Strips the user agent styles from the popover when in floating mode */
14+
@layer qwik-ui {
15+
[data-floating] {
16+
margin: unset;
17+
padding: unset;
18+
border: unset;
19+
overflow: unset;
20+
position: absolute;
21+
}
2622
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const Popover = component$<PopoverProps>((props) => {
1818
}
1919

2020
return (
21-
<FloatingPopover ref={ref} anchorRef={anchorRef} {...rest}>
21+
<FloatingPopover data-floating ref={ref} anchorRef={anchorRef} {...rest}>
2222
<Slot />
2323
</FloatingPopover>
2424
);

0 commit comments

Comments
 (0)