Skip to content

Commit 6e48a7c

Browse files
kb(Popover): Refresh Popover posiiton on dimensions change (#3372)
Co-authored-by: Dimo Dimov <961014+dimodi@users.noreply.github.com>
1 parent 1d8e52c commit 6e48a7c

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

components/popover/position-collision.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,7 @@ The following example lets you experiment with the available settings that contr
105105
}
106106
</style>
107107
````
108+
109+
## See Also
110+
111+
* [How to Align Popover with Anchor After Content and Size Change](slug:popover-kb-refresh-callout-position)
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
title: Align Popover with Anchor After Content and Size Change
3+
description: Learn how to align the Telerik Popover for Blazor to its anchor after the component content and size change dynamically at runtime.
4+
type: troubleshooting
5+
page_title: How to Align Popover with Anchor After Content and Size Change
6+
slug: popover-kb-refresh-callout-position
7+
tags: blazor, popover
8+
ticketid: 1703828
9+
res_type: kb
10+
---
11+
12+
## Environment
13+
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product</td>
18+
<td>Popover for Blazor</td>
19+
</tr>
20+
</tbody>
21+
</table>
22+
23+
## Description
24+
25+
I have a Popover that may change its content and size at runtime. In these cases, the callout does not line up with the anchor anymore. How to dynamically align the Popover with its anchor after the content shrinks or expands?
26+
27+
## Cause
28+
29+
The Popover component does not track changes to its content or size for performance reasons.
30+
31+
## Solution
32+
33+
Use the [Popover `Refresh` method](slug:popover-overview#popover-reference-and-methods) to recalculate the component and callout position with regard to the anchor. If the Popover content change depends on C# code, you may need to wait for the next Blazor re-render or trigger it immediately with `await Task.Delay(1)`.
34+
35+
>caption Refresh Popover position and callout when the dimensions change
36+
37+
```RAZOR
38+
<TelerikPopover @ref="@PopoverRef"
39+
AnchorSelector=".popover-target"
40+
ShowOn="@PopoverShowOn.Click"
41+
Position="@PopoverPosition.Right"
42+
Offset="20">
43+
<PopoverContent>
44+
Telerik Popover for Blazor
45+
<br />
46+
<TelerikButton OnClick="@ToggleContent">Toggle Content</TelerikButton>
47+
@if (ContentVisible)
48+
{
49+
<div style="height: 100px; padding: 1em; border: 1px solid var(--kendo-color-border);">
50+
Some dynamic content...
51+
</div>
52+
}
53+
</PopoverContent>
54+
<PopoverActions>
55+
<TelerikButton OnClick="@( () => PopoverRef?.Hide() )"
56+
Icon="@SvgIcon.X">Close</TelerikButton>
57+
</PopoverActions>
58+
</TelerikPopover>
59+
60+
<br /><br /><br /><br /><br /><br /><br />
61+
62+
<TelerikButton Class="popover-target">Toggle Popover</TelerikButton>
63+
64+
@code{
65+
#nullable enable
66+
67+
private TelerikPopover? PopoverRef { get; set; }
68+
69+
private bool ContentVisible { get; set; } = true;
70+
71+
private async Task ToggleContent()
72+
{
73+
ContentVisible = !ContentVisible;
74+
await Task.Delay(1);
75+
76+
PopoverRef?.Refresh();
77+
}
78+
}
79+
```
80+
81+
## See Also
82+
83+
* [Popover Position and Collision](slug:popover-position-collision)

0 commit comments

Comments
 (0)