Skip to content

Commit 631706e

Browse files
authored
Updated popover docs to show onToggle (#904)
1 parent 722f9a0 commit 631706e

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { component$, useSignal } from '@builder.io/qwik';
2+
import { Popover } from '@qwik-ui/headless';
3+
export default component$(() => {
4+
const toggleStatus = useSignal<'open' | 'closed'>('closed');
5+
6+
return (
7+
<Popover.Root>
8+
<p>Panel is {toggleStatus.value}!</p>
9+
<Popover.Trigger class="popover-trigger">Popover Trigger</Popover.Trigger>
10+
<Popover.Panel
11+
class="popover-panel"
12+
onToggle$={(e) => {
13+
toggleStatus.value = e.newState;
14+
}}
15+
>
16+
My Hero!
17+
</Popover.Panel>
18+
</Popover.Root>
19+
);
20+
});

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,14 @@ Above is an example of how we programmatically open and close the popover in the
243243

244244
> In the native spec, these are methods, although we want to ensure code executes on interaction in all browsers, including the polyfill.
245245
246+
### Handling state changes
247+
248+
<Showcase name="toggle-event" />
249+
250+
Use the `onToggle$` prop on the `<Popover.Panel>` to listen for changes to the popover visibility.
251+
252+
The example above uses a `Signal` to track whether the popover is triggered or not.
253+
246254
## Floating Behavior
247255

248256
By default, the Qwik UI Popover will float below the trigger component.
@@ -478,6 +486,19 @@ To read more about the popover API you can check it out on:
478486
]}
479487
/>
480488

489+
### Popover Panel
490+
491+
<APITable
492+
propDescriptors={[
493+
{
494+
name: 'onToggle',
495+
type: 'QRL',
496+
description: 'Function called when the popover opens or closes',
497+
info: 'QRL<(event: CorrectedToggleEvent, element: HTMLDivElement) => void>',
498+
},
499+
]}
500+
/>
501+
481502
### usePopover hook
482503

483504
<APITable

0 commit comments

Comments
 (0)