Blazor Popover
The Blazor Bootstrap Popover component shows a title and rich content next to a trigger, with placements, triggers, colors, and content that updates while it is open. The examples below cover placements, triggers, dismiss behavior, rich content and live content.
INFO
Popover wraps the Bootstrap 5.3 popover.
Put the trigger, a focusable element such as a button, inside
Popover. The title and content are rendered by Blazor and keep updating while the popover is open.
A popover with no title and no content never opens.
Basic usage #
Click the button to open and close the popover.
How to use:
How to use:
- Wrap the trigger in
Popover, and setTitleandContent. Strings always show as text. - The trigger gets
aria-describedbyandaria-expanded.
Placements #
Open the popover on the top, right, bottom, or left of the trigger, or let it pick the side with the most room.
How to use:
How to use:
- Set
Placement. The default isRight; Right and Left are mirrored in right-to-left layouts.
Triggers #
Open the popover on click (default), hover, focus, or only from code.
How to use:
How to use:
- Set
Trigger. Combine Click, Hover, and Focus with|; Manual stands alone. - Pair Hover with Focus, so keyboard users can open it too.
- Hover and Focus popovers close when focus leaves the trigger, so use them for content that is read; put links and buttons in a Click popover.
Dismiss behavior #
Close the popover on the next click, on a click outside, or on Escape.
How to use:
How to use:
- For Bootstrap's dismiss on next click, use the Focus trigger on an
<a tabindex="0" role="button">; buttons do not take focus on click in every browser. AutoClose(defaulttrue) closes the popover on a click outside it and its trigger, on Escape, and when focus leaves its content. Set it tofalseto keep it open until the trigger is clicked again.
Rich content #
Show markup in the title and content, such as an icon, a badge, a table, or a link.
How to use:
How to use:
- Set
TitleTemplateandContentTemplate, and put the trigger inChildContent. - Widen the popover for a table with a
CustomClassthat sets--bs-popover-max-width.
Live content #
The content updates in place while the popover is open, and the popover repositions when its size changes.
How to use:
How to use:
- Bind the content to your state as usual; the open popover is never re-created.
- Open it with Enter or Space, and focus moves to its first button; Escape closes it and returns focus to the trigger.
- Tab and Shift+Tab move between the trigger and the content as if the popover sat right after the trigger; tabbing past the last button closes it.
Methods #
Control the popover from code.
How to use:
How to use:
- Get a reference with
@ref, and callShowAsync,HideAsync,ToggleAsync, orUpdateAsync. - Call
UpdateAsyncafter the trigger moves; content size changes reposition the popover by themselves.
Events #
React when the popover shows and hides.
How to use:
How to use:
- Handle
OnShowing,OnInserted,OnShown,OnHiding, andOnHidden.
Colors #
Color the popover's header and border.
How to use:
How to use:
- Set
Color.
Custom popovers #
Style a popover through Bootstrap's popover CSS variables.
How to use:
How to use:
- Define a class that sets the
--bs-popover-*variables, and set it asCustomClass.
Disabled elements #
Describe a disabled control. A disabled element cannot be hovered, clicked, or focused, so the wrapper around it gets the popover, and becomes focusable with the Click or Focus trigger.
How to use:
How to use:
- Put the disabled control in
Popover; the wrapper takes over automatically. - Use
PopoverTrigger.Hover | PopoverTrigger.Focus, as users may not expect to click a disabled control.
Disabled popover #
Stop a popover from opening until it is enabled again.
How to use:
How to use:
- Set
Disabled="true". An open popover closes when it is disabled.
Offset, delay, animation, and fallback placements #
Fine-tune where and when the popover appears.
How to use:
How to use:
Offsetis "skidding,distance" in pixels (Bootstrap's default is "0,8").ShowDelayandHideDelayapply to the Hover and Focus triggers.Animation="false"turns off the fade.FallbackPlacementslists the sides to try, in order, whenPlacementhas no room.
Custom container #
Add the popover to another element, for example a modal, so its interactive content works inside the modal's focus trap.
How to use:
How to use:
- Set
Containerto a CSS selector, such as"#my-modal .modal-body". The default is the page body.