You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/website/src/routes/docs/headless/modal/index.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ A window overlaid on either the primary window or another dialog window. Modal c
16
16
17
17
The modal makes use of the HTML `dialog` element, which is supported in [every major browser](https://caniuse.com/?search=dialog).
18
18
19
-
> For non-modal UI elements, it is preferred to use [Qwik UI's popover component](../../../docs/headless/popover/)_(in progress)_. In the near future, Qwik's popover component can be applied to the most-semantically-relevant HTML element, including the `<dialog>` element itself for non-modal dialogs.
19
+
> For non-modal UI elements, it is preferred to use [Qwik UI's popover component](../../../docs/headless/popover/). Qwik's popover component can be applied to the most-semantically-relevant HTML element, including the `<dialog>` element itself for non-modal dialogs.
20
20
21
21
Modals are used when an important choice needs to be made in the application. The rest of the content isn't interactive until a certain action has been performed.
Copy file name to clipboardExpand all lines: apps/website/src/routes/docs/headless/popover/index.mdx
+81-29Lines changed: 81 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,9 +19,8 @@ A non-modal primitive with overlays that open and close around a DOM element.
19
19
`"Early" access to MDN's native popover API`,
20
20
'Support across all browsers',
21
21
'Resumable / Lazily executes code on interaction',
22
-
'Top Layer behavior',
23
-
'Opt-in floating behavior',
24
-
'Portal polyfill works across meta-frameworks',
22
+
'UI is placed above everything else.',
23
+
'stick or float elements to other elements, similar to the upcoming Anchor API.',
25
24
]}
26
25
/>
27
26
@@ -39,6 +38,8 @@ This is particularly useful for displaying additional information or options wit
39
38
40
39
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.
41
40
41
+
Even if a popover is in the HTML Tree, its children will not execute unless resumed.
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.
@@ -119,7 +120,7 @@ A separate declaration is needed to select popovers in all browsers.
119
120
120
121
### Cross-browser Animations
121
122
122
-
Entry and exit animations have often been a frustrating experience. Especially trying to animate between `display: none`, a discrete property.
123
+
Entry and exit animations have often been a frustrating experience in web development. Especially trying to animate between `display: none`, a discrete property.
123
124
124
125
Until recently, discrete properties were not animatable. Luckily, there's [new properties to CSS](https://developer.chrome.com/blog/entry-exit-animations) that solve this problem.
125
126
@@ -189,28 +190,60 @@ An auto popover will automatically hide when you click outside of it and typical
189
190
190
191
On the other hand, a `manual` popover needs to be manually hidden, such as toggling the button or programmatically, and allows for scenarios like nested popovers in menus.
191
192
192
-
### Popover Methods
193
+
We can add a manual popover by adding the `popover="manual"` prop, or `manual` shorthand.
194
+
195
+
> Notice that the last opened popover is always above the other!
196
+
197
+
## Programmatic Behavior
193
198
194
-
There are two methods for showing and hiding popovers manually in JavaScript. The `showPopover` and `hidePopover` methods.
199
+
<Showcasename="programmatic" />
195
200
196
-
For example, here is programmatic behavior syncing the popover state with the listbox in the `Combobox` component.
201
+
We can also enable programmatic behavior with popovers. Qwik UI provides several functions you can use to control this behavior.
202
+
203
+
<AnatomyTable
204
+
propDescriptors={[
205
+
{
206
+
name: 'showPopover()',
207
+
description: 'Opens the popover.',
208
+
},
209
+
{
210
+
name: 'togglePopover()',
211
+
description: 'Toggles the popover between the open and closed state.',
212
+
},
213
+
{
214
+
name: 'hidePopover()',
215
+
description: 'Closes the popover.',
216
+
},
217
+
]}
218
+
/>
219
+
220
+
We can access them anywhere by importing the `usePopover` hook. We also need to pass in the **popover id or popovertarget string** to usePopover, which will find the popover we intend to perform an action on.
221
+
222
+
For example, here is programmatic behavior syncing the popover state with the listbox in Qwik UI's `Combobox` component.
> In the native spec, these are methods, although we want to ensure the polyfill loads on interaction, rather than page load with a proxy.
242
+
212
243
## Floating Behavior
213
244
245
+
<Showcasename="floating-intro" />
246
+
214
247
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.
215
248
216
249
> 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.
@@ -238,12 +271,12 @@ For the following examples, we'll be using the Combobox component. `ComboboxPopo
238
271
```tsx
239
272
<Popover
240
273
{...props}
241
-
manual
242
274
id={popoverId}
275
+
ref={context.popoverRef}
276
+
manual
243
277
floating={true}
244
-
//passing in a custom ref for programmatic behavior
278
+
//"stick" to the input
245
279
anchorRef={context.inputRef}
246
-
popoverRef={context.popoverRef}
247
280
class="listbox"
248
281
>
249
282
<Slot />
@@ -256,8 +289,6 @@ To set the default position of the listbox, you can use the `placement` prop. In
256
289
257
290
<Showcasename="placement" />
258
291
259
-
The example above sets the `placement` prop to `top`. The default placement is **bottom**.
260
-
261
292
### Flip
262
293
263
294
Allows the listbox to flip its position based on available space. It's enabled by default, but can be disabled by adding `flip={false}` on the listbox.
@@ -301,21 +332,44 @@ If Tailwind is the framework of choice, then styles can be added using the [arbi
301
332
302
333
> 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.
303
334
304
-
##Animations
335
+
### Listbox preset
305
336
306
-
### The problem
337
+
By default, the popover API comes with built-in styles, including fixed behavior, margin, the list goes on.
307
338
308
-
Currently, native animation support for the popover API is [not quite there yet](https://open-ui.org/components/popover.research.explainer/#animation-of-popovers). Part of this has to do with the native API managing the popover state and adding the `display: none` declaration.
339
+
There are times when we want to override this behavior. An example being when we want an absolutely positioned listbox.
309
340
310
-
This declaration is `unanimatable`, meaning you cannot animate to or from display none at this time. With that said, we currently have a way to animate popovers using a clever trick under the hood.
341
+
To do that, we can add the `listbox` class to the popover component.
311
342
312
-
> There are [new properties to CSS](https://developer.chrome.com/blog/entry-exit-animations) that aim to fix this problem, but regardless we need to be able to support all browsers.
343
+
If you need to override any of the listbox properties, use the following CSS variables:
313
344
314
-
### Custom animation support
345
+
<AnatomyTable
346
+
propDescriptors={[
347
+
{
348
+
name: 'margin',
349
+
description: '--listbox-margin',
350
+
},
351
+
{
352
+
name: 'padding',
353
+
description: '--listbox-padding',
354
+
},
355
+
{
356
+
name: 'border',
357
+
description: '--listbox-border',
358
+
},
359
+
{
360
+
name: 'overflow',
361
+
description: '--listbox-overflow',
362
+
},
363
+
{
364
+
name: 'position',
365
+
description: '--listbox-position',
366
+
},
367
+
]}
368
+
/>
315
369
316
-
Regardless of native support, animations need support in polyfill browsers too, and so we've provided a way for you to use both `animation` and `transition` declarations in your `Popover` component for **all browsers**.
370
+
> Another option is to use the `!important` syntax to override any of the CSS variable values.
317
371
318
-
### Animation declarations
372
+
##Animations
319
373
320
374
<Showcasename="listbox-animation" />
321
375
@@ -359,8 +413,6 @@ Here's the CSS imported from the example:
359
413
360
414
### Transition declarations
361
415
362
-
<Showcasename="animation" />
363
-
364
416
Transitions use the same classes for entry and exit animations. Those being `.popover-showing` and `.popover-closing`. They are explained move in the section above.
365
417
366
418
> The [View Transitions API](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API) is another native solution that aims to solve animating between states. Support is currently in around **~70%** of browsers.
0 commit comments