|
| 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