Skip to content

Commit 5d365c6

Browse files
authored
docs(Toolbar): outline how to open popovers (#6741)
Fixes #6739
1 parent 243ba13 commit 5d365c6

File tree

4 files changed

+85
-2
lines changed

4 files changed

+85
-2
lines changed

packages/main/src/components/ObjectPage/ObjectPage.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ This component exposes public methods. You can use them directly on the instance
6464
</tbody>
6565
</table>
6666

67-
# More Examples
68-
6967
## ObjectPage with IllustratedMessage (`UnableToLoad`) placeholder
7068

7169
<Canvas of={ComponentStories.WithIllustratedMessage} />
@@ -90,6 +88,10 @@ To render a single section in fullscreen mode, set its height to `100%`.
9088
</ObjectPageSection>
9189
```
9290

91+
## Opening popover components by pressing an action
92+
93+
Please see the [Docs](?path=/docs/layouts-floorplans-toolbar--docs#open-popovers-with-toolbarbutton) of the `Toolbar` component.
94+
9395
## Legacy Toolbar Support
9496

9597
The ObjectPage still supports the old (React-only) `Toolbar` implementation. Please only use this toolbar if your app is dependent on some features the `Toolbar` web component is currently not offering.

packages/main/src/webComponents/DynamicPage/DynamicPage.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,8 @@ function DynamicPageWithStickyContent(props) {
112112
}
113113
```
114114

115+
## Opening popover components by pressing an action
116+
117+
Please see the [Docs](?path=/docs/layouts-floorplans-toolbar--docs#open-popovers-with-toolbarbutton) of the `Toolbar` component.
118+
115119
<Footer />

packages/main/src/webComponents/Toolbar/Toolbar.mdx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,47 @@ import * as ComponentStories from './Toolbar.stories';
1818

1919
<ControlsWithNote of={ComponentStories.Default} />
2020

21+
## Opening Popovers via ToolbarButton
22+
23+
Since the `ToolbarButton` is an [abstract UI5 web component](?path=/docs/knowledge-base-faq--docs#what-are-abstract-ui5-web-components), the opener of the `Popover` needs the DOM reference of the actual element to position the popover correctly.
24+
Starting with v2.5.0 of `@ui5/webcomponents(-react)`, the `detail` property of the `ToolbarButton`'s click handler now includes a `targetRef` property, which can be used as the opener.
25+
26+
<Canvas of={ComponentStories.OpenPopover} />
27+
28+
### Example Code
29+
30+
```tsx
31+
function ToolbarWithPopover() {
32+
const [popoverOpen, setPopoverOpen] = useState(false);
33+
const popoverRef = useRef<PopoverDomRef>(null);
34+
return (
35+
<>
36+
<Toolbar>
37+
<ToolbarButton
38+
onClick={(e) => {
39+
const { targetRef } = e.detail;
40+
if (popoverRef.current) {
41+
popoverRef.current.opener = targetRef;
42+
setPopoverOpen(true);
43+
}
44+
}}
45+
text="Open Popover"
46+
/>
47+
</Toolbar>
48+
<Popover
49+
open={popoverOpen}
50+
ref={popoverRef}
51+
onClose={() => {
52+
setPopoverOpen(false);
53+
}}
54+
>
55+
Content
56+
</Popover>
57+
</>
58+
);
59+
}
60+
```
61+
2162
<Markdown>{SubcomponentsSection}</Markdown>
2263

2364
## ToolbarButton

packages/main/src/webComponents/Toolbar/Toolbar.stories.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import type { Meta, StoryObj } from '@storybook/react';
22
import ToolbarAlign from '@ui5/webcomponents/dist/types/ToolbarAlign.js';
3+
import { useRef, useState } from 'react';
4+
import { Popover } from '../Popover/index.js';
5+
import type { PopoverDomRef } from '../Popover/index.js';
36
import { ToolbarButton } from '../ToolbarButton/index.js';
47
import { ToolbarSelect } from '../ToolbarSelect/index.js';
58
import { ToolbarSelectOption } from '../ToolbarSelectOption/index.js';
@@ -43,3 +46,36 @@ export const Default: Story = {
4346
</Toolbar>
4447
)
4548
};
49+
50+
export const OpenPopover: Story = {
51+
name: 'Opening Popovers via ToolbarButton',
52+
render(args) {
53+
const [popoverOpen, setPopoverOpen] = useState(false);
54+
const popoverRef = useRef<PopoverDomRef>(null);
55+
return (
56+
<>
57+
<Toolbar {...args}>
58+
<ToolbarButton
59+
onClick={(e) => {
60+
const { targetRef } = e.detail;
61+
if (popoverRef.current) {
62+
popoverRef.current.opener = targetRef;
63+
setPopoverOpen(true);
64+
}
65+
}}
66+
text="Open Popover"
67+
/>
68+
</Toolbar>
69+
<Popover
70+
open={popoverOpen}
71+
ref={popoverRef}
72+
onClose={() => {
73+
setPopoverOpen(false);
74+
}}
75+
>
76+
Content
77+
</Popover>
78+
</>
79+
);
80+
}
81+
};

0 commit comments

Comments
 (0)