A popover
is a way to toggle content on top of other content. It can be used for small texts, small forms, or even dropdowns. By default, popover will toggle open/closed by simply clicking the trigger element.
In addition, you may also choose to enable enhanced functionality so that the popover may be toggled by clicking outside of the "trigger element" and/or popover itself.
You are building a single page application where clicking into the popover itself triggers some asynchronous actions which mutate the UI instantaneously. As a result, may want the popover to automatically close after a selection has been made from the popover contents.
You are building an custom in-page results filter list which is contained inside of the popover's content area. Since the filter list contains 5 filters, you may want to keep the popover open so that users may select multiple filters then only close the popover when users click outside of the popover.
<%= pb_rails("flex", props: { dark: true, orientation: "row", vertical: "center" }) do %> <%= pb_rails("body", props: { text: "Click info for more details" }) %> <%= pb_rails("circle_icon_button", props: { variant: "secondary", icon: "info", id: "regular-popover-1" }) %> <%= pb_rails("popover", props: { trigger_element_id: "regular-popover-1", tooltip_id: "tooltip-1", offset: true, position: "top", }) do %> I'm a popover. I can show content of any size. <% end %> <% end %>
Notice offset
is not set so the popover is flush with the content.
<%= pb_rails("button", props: { variant: "secondary", id: 'list' }) do %> <%= pb_rails("flex", props: {align: "center"}) do %> Filter By <%= pb_rails("flex/flex_item", props: {margin_left: "xxs"}) do %> <div id="arrow-icon" style="display: flex"> <%= pb_rails("icon", props: { icon: "chevron-down", fixed_width: true }) %> </div> <% end %> <% end %> <% end %> <%= pb_rails("popover", props: {trigger_element_id: "list", tooltip_id: "list-tooltip", position: 'bottom', padding: "none"}) do %> <%= pb_rails("list", props: {ordered: false, dark: false, borderless: false, xpadding: true}) do %> <%= pb_rails("list/item") do %><a>Popularity</a><% end %> <%= pb_rails("list/item") do %><a>Title</a><% end %> <%= pb_rails("list/item") do %><a>Duration</a><% end %> <%= pb_rails("list/item") do %><a>Date Started</a><% end %> <%= pb_rails("list/item") do %><a>Date Ended </a><% end %> <% end %> <% end %> <script type="text/javascript"> const popoverButton = document.querySelector("#list") let buttonClicked = false const arrowDiv = document.querySelector("#arrow-icon") popoverButton.onclick = () => { buttonClicked = !buttonClicked if (buttonClicked) { arrowDiv.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="auto" height="auto" viewBox="0 0 31 25" fill="none" class="pb_custom_icon svg-inline--fa pb_icon_kit svg_fw" id="" data="{}" aria="{}" tabindex=""><path d="M14.2031 5.70312C14.625 5.28125 15.3281 5.28125 15.75 5.70312L24.7969 14.7031C25.2188 15.1719 25.2188 15.875 24.7969 16.2969C24.3281 16.7656 23.625 16.7656 23.2031 16.2969L15 8.09375L6.79688 16.2969C6.32812 16.7656 5.625 16.7656 5.20312 16.2969C4.73438 15.875 4.73438 15.1719 5.20312 14.75L14.2031 5.70312Z" fill="currentColor"/></svg>' } else { arrowDiv.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="auto" height="auto" viewBox="0 0 31 25" fill="none" class="pb_custom_icon svg-inline--fa pb_icon_kit svg_fw" id="" data="{}" aria="{}" tabindex=""><path d="M14.2031 19.2969L5.20312 10.2969C4.73438 9.875 4.73438 9.17188 5.20312 8.70312C5.625 8.28125 6.32812 8.28125 6.79688 8.70312L15 16.9531L23.2031 8.75C23.625 8.28125 24.3281 8.28125 24.7969 8.75C25.2188 9.17188 25.2188 9.875 24.7969 10.2969L15.75 19.2969C15.3281 19.7656 14.625 19.7656 14.2031 19.2969Z" fill="currentColor"/></svg>' } } </script>
<%= pb_rails("flex", props: {classname: "flex-container", spacing: "between"}) do %> <span> <%= pb_rails("button", props: { text: "Click Inside", variant: "secondary", id: "inside-popover-1" }) %> <%= pb_rails("popover", props: { close_on_click: "inside", trigger_element_id: "inside-popover-1", tooltip_id: "inside-tooltip-1", position: "bottom", offset: true }) do %> Click on me! <% end %> </span> <span> <%= pb_rails("button", props: { text: "Click Outside", variant: "secondary", id: "outside-popover-1" }) %> <%= pb_rails("popover", props: { close_on_click: "outside", trigger_element_id: "outside-popover-1", tooltip_id: "outside-tooltip-1", position: "left", offset: true }) do %> Click anywhere but me! <% end %> </span> <span> <%= pb_rails("button", props: { text: "Click Anywhere", variant: "secondary", id: "any-popover-1" }) %> <%= pb_rails("popover", props: { close_on_click: "any", trigger_element_id: "any-popover-1", tooltip_id: "any-tooltip-1", position: "top", offset: true }) do %> Click anything! <% end %> </span> <% end %>
<div style="position: relative; z-index: 2"> <%= pb_rails("body", props: {text: "I've got a z-index of 2", margin_bottom: "md"}) %> </div> <%= pb_rails("button", props: { variant: "secondary", id: 'tooltip-z-index-1', text: "Click Me", }) %> <%= pb_rails("popover", props: { trigger_element_id: "tooltip-z-index-1", tooltip_id: "tooltip-z-index", position: 'top', z_index: "3", offset: true }) do %> I've got a z-index of 3 <% end %>
<%= pb_rails("button", props: { variant: "secondary", id: 'scroll-height', text: "Click Me" }) %> <%= pb_rails("popover", props: { trigger_element_id: "scroll-height", tooltip_id: "scroll-height-1", position: 'top', close_on_click: "any", max_height: "150px", max_width: "240px", offset: true }) do %> <%= pb_rails("body", props: { margin_bottom: "sm", text: "So many people live within unhappy circumstances and yet will not take the initiative to change their situation because they are conditioned to a life of security, conformity, and conservation, all of which may appear to give one peace of mind, but in reality, nothing is more damaging to the adventurous spirit." }) %> <%= pb_rails("title", props: { size: 4, text: "- Christopher McCandless" }) %> <% end %>
<%= pb_rails("flex", props: { dark: true, orientation: "row", vertical: "center" }) do %> <%= pb_rails("body", props: { text: "Click info for more details" }) %> <%= pb_rails("circle_icon_button", props: { variant: "secondary", icon: "info", id: "actionable-popover-1" }) %> <%= pb_rails("popover", props: { close_on_click: "any", trigger_element_id: "actionable-popover-1", tooltip_id: "actionable-tooltip-1", offset: true, position: "top" }) do %> <%= pb_rails("button", props: { id: "actionable-tooltip-button", text: "Learn more" }) %> <% end %> <% end %> <%= javascript_tag do %> document.addEventListener('DOMContentLoaded', function () { document.querySelector('#actionable-tooltip-button').addEventListener('click', function (e) { alert("Let's do this") }, { once: true }) }) <% end %>
Props | Type | Values |
---|---|---|
number_spacing |
array
|
tabular
|
shadow |
array
|
none
deep
deeper
deepest
|
line_height |
array
|
tightest
tighter
tight
normal
loose
looser
loosest
|
display |
array
|
block
inline_block
inline
flex
inline_flex
none
|
cursor |
array
|
auto
default
none
contextMenu
help
pointer
progress
wait
cell
crosshair
text
verticalText
alias
copy
move
noDrop
notAllowed
grab
grabbing
eResize
nResize
neResize
nwResize
sResize
seResize
swResize
wResize
ewResize
nsResize
neswResize
nwseResize
colResize
rowResize
allScroll
zoomIn
zoomOut
|
flex_direction |
array
|
row
column
rowReverse
columnReverse
|
flex_wrap |
array
|
wrap
nowrap
wrapReverse
|
justify_content |
array
|
start
end
center
spaceBetween
spaceAround
spaceEvenly
|
justify_self |
array
|
auto
start
end
center
stretch
|
align_items |
array
|
flexStart
flexEnd
start
end
center
baseline
stretch
|
align_content |
array
|
start
end
center
spaceBetween
spaceAround
spaceEvenly
|
align_self |
array
|
auto
start
end
center
stretch
baseline
|
flex |
array
|
auto
initial
0
1
2
3
4
5
6
7
8
9
10
11
12
none
|
flex_grow |
array
|
1
0
|
flex_shrink |
array
|
1
0
|
order |
array
|
1
2
3
4
5
6
7
8
9
10
11
12
|
hover |
array
|
|
border_radius |
array
|
none
xs
sm
md
lg
xl
rounded
|
text_align |
array
|
start
end
left
right
center
justify
justify-all
match-parent
|
overflow |
array
|
visible
hidden
scroll
auto
|
truncate |
array
|
1
2
3
4
5
|
left |
array
|
0
xxs
xs
sm
md
lg
xl
auto
initial
inherit
|
top |
array
|
0
xxs
xs
sm
md
lg
xl
auto
initial
inherit
|
right |
array
|
0
xxs
xs
sm
md
lg
xl
auto
initial
inherit
|
bottom |
array
|
0
xxs
xs
sm
md
lg
xl
auto
initial
inherit
|
vertical_align |
array
|
baseline
super
top
middle
bottom
sub
text-top
text-bottom
|
height |
array
|
auto
xs
sm
md
lg
xl
xxl
xxxl
|
overflow_x |
array
|
visible
hidden
scroll
auto
|
overflow_y |
array
|
visible
hidden
scroll
auto
|
margin |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_bottom |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_left |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_right |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_top |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_x |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_y |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_bottom |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_left |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_right |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_top |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_x |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_y |
array
|
none
xxs
xs
sm
md
lg
xl
|
classname |
string
|
|
dark |
boolean
|
|
group_hover |
boolean
|
|
id |
string
|
|
data |
hashprop
|
|
aria |
hashprop
|
|
html_options |
hashprop
|
|
children |
proc
|
|
style |
hashprop
|
Props | Type | Values | Default |
---|---|---|---|
max_width |
string
|
||
min_width |
string
|
||
width |
string
|
||
z_index |
string
|
||
position |
enum
|
top
bottom
left
right
top-start
top-end
bottom-start
bottom-end
right-start
right-end
left-start
left-end
|
left
|
min_height |
string
|
||
max_height |
string
|
||
trigger_element_id |
string
|
||
tooltip_id |
string
|
||
offset |
boolean
|
false
|
|
close_on_click |
enum
|
none
outside
inside
any
|
none
|