Skip to content

Commit ed41e2c

Browse files
authored
docs(ToolbarButton): outline event.preventDefault behavior for click handler (#8206)
1 parent a922b94 commit ed41e2c

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import * as ComponentStories from './Toolbar.stories';
2323
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.
2424
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.
2525

26+
**Note:** To prevent the overflow popover from closing when the opener `ToolbarButton` of the Popover is clicked, you can call `event.preventDefault()` in the `onClick` event handler.
27+
2628
<Canvas of={ComponentStories.OpenPopover} />
2729

2830
### Example Code
@@ -37,6 +39,7 @@ function ToolbarWithPopover() {
3739
<ToolbarButton
3840
onClick={(e) => {
3941
const { targetRef } = e.detail;
42+
e.preventDefault();
4043
if (popoverRef.current) {
4144
popoverRef.current.opener = targetRef;
4245
setPopoverOpen(true);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export const OpenPopover: Story = {
5757
<Toolbar {...args}>
5858
<ToolbarButton
5959
onClick={(e) => {
60+
e.preventDefault();
6061
const { targetRef } = e.detail;
6162
if (popoverRef.current) {
6263
popoverRef.current.opener = targetRef;

0 commit comments

Comments
 (0)