Skip to content

Commit 44e60ba

Browse files
authored
docs(ShellBar): update popover example (#6372)
Fixes #6370
1 parent 9472c57 commit 44e60ba

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

packages/main/src/webComponents/ShellBar/ShellBar.mdx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,32 @@ import { excludePropsForAbstract } from '@sb/utils';
2525

2626
<br />
2727

28-
### Recipe: How to open a popover on ShellBarItem click?
28+
## Open a Popover on ShellBarItem click
2929

30-
To open a popover with the `ShellBarItem` you can use the `targetRef` property of the `onClick` event.
30+
To open a popover with the `ShellBarItem` you can use the `detail.targetRef` property of the `onClick` event.
3131

32-
```jsx
32+
```tsx
3333
const ShellBarComponent = () => {
34-
const popoverRef = useRef(null);
35-
const handleShellBarItemClick = (e) => {
36-
popoverRef.current.showAt(e.detail.targetRef);
34+
const popoverRef = useRef<PopoverDomRef>(null);
35+
const [popoverOpen, setPopoverOpen] = useState(false);
36+
const handleShellBarItemClick: ShellBarItemPropTypes['onClick'] = (e) => {
37+
popoverRef.current!.opener = e.detail.targetRef;
38+
setPopoverOpen(true);
3739
};
3840
return (
3941
<>
4042
<ShellBar>
4143
<ShellBarItem onClick={handleShellBarItemClick} icon="add" text="add" />
4244
</ShellBar>
43-
<Popover ref={popoverRef}>Hello there!</Popover>
45+
<Popover
46+
ref={popoverRef}
47+
open={popoverOpen}
48+
onClose={() => {
49+
setPopoverOpen(false);
50+
}}
51+
>
52+
Hello there!
53+
</Popover>
4454
</>
4555
);
4656
};

0 commit comments

Comments
 (0)