Popover
Popover
lets you create accessible popovers 😉.
-->
Popover
lets you create accessible popovers 😉.
No need for endless configuration. Just specify an id
for the PopoverContent
and target
it with PopoverTrigger
to get started.
Popover Content
Set show
to true
on PopoverTrigger
to show your PopoverContent
when it loads. This makes it easy to debug and style PopoverContent
!
Popover Content
You can place popovers on the top
, bottom
, left
and right
. You can even shift them towards the start
or end
of that position for further fine-tuning!
Have you noticed that most popover libraries force you to specify an offset
in px
values, even when you style the rest of your content in rem
and em
?
Well, we don’t. Go ahead and use rem
and em
.
Static Drawer Content
This content is placed in the normal document flow.
Absolute Drawer Content
This content is placed relative to the nearest ancestor with position: relative
.
Fixed Drawer Content
This content is placed relative to the nearest stacking context.
Set the arrow
option to true
and PopoverContent
will create a built-in arrow for you. They work in all 12 positions too.
Popover
built to be accessible — for both keyboards users and screen readers.
We have taken the pains to understand the ARIA specifications and built the component to meet that specification, to the best of our abilities.
First — the most basic of all features — is you can open and close the popover with your keyboard.
Popover Content
Popover
handles focus elegantly in every scenario.
PopoverContent
so keyboard users and screen readers can start interacting with it immediately.PopoverTrigger
so keyboard and screen reader users navigate to the next item without using a mouse.PopoverContent
is closed and focus is moved to the next item after PopoverTrigger
. This allows users to continue tabbing forward. See the accessibility tab for more details.PopoverContent
needs an accessible name for it to be accessible. We have added an accessibility tab to show you how to do this.
We’ve also included notes on how you can change the role
of the PopoverContent
if you need to.
As you can see, we are pretty serious about accessibility!
A basic popover can be created with PopoverTrigger
and PopoverContent
.
When creating a popover, you need to pass the same value to the trigger’s target
and content’s id
property.
Popover Content
You can create a close button with PopoverCloseButton
.
Use Splendid Layouts
to create a layout for your popover
content easily.
If you do not wish to manually name the id
and target
properties, you can use randomString
from Splendid Utils
to create a DOM-ready random string. This can sometimes make things a tiny bit easier.
PopoverTrigger
creates a trigger button that opens PopoverContent
when clicked.
If you want to show the popover by default (great for debugging purposes), you can set show
to true.
If you want to show the popover on hover, you can set showOnHover
to true.
You can also control the delay before the popover closes by setting hoverCloseDelay
to a number in milliseconds.
Normally, only one popover will be opened by default. So if you open a new popover, the previous one will close automatically.
If you wish to have multiple popovers opened, you can set closeOthers
to false
on them all.
PopoverTrigger
is built on top of DisclosureTrigger
and inherits all of its options. In addition to the above properties, you can pass other DisclosureTrigger
properties into PopoverTrigger
.
All other unnamed properties will be passed directly to the underlying button
element.
PopoverContent
contains content that should show up when PopoverTrigger
is clicked.
PopoverContent
has 12 placement options:
top
, top-start
, top-end
left
, left-start
, left-end
right
, right-start
, right-end
bottom
, bottom-start
, bottom-end
top
, left
, right
, and bottom
refer to its position on the main axis. while start
and end
refers to its position on the cross axis. The following example would make more sense:
If there isn’t enough space to display the popover on the main axis, it will automatically be displayed in the opposite direction. If there is still insuffient space, it will be displayed in the other axis, whenever possible.
See Portal
below for an example on how they will be displayed.
By default, PopoverContent
will be moved out from their default DOM locations and inserted as a direct descendant of the <body>
element. This prevents PopoverContent
from being constrained (or even cut-off) by parent elements.
If you wish to disable this behaviour, set the portal
option to false
.
You can set an offset value in px
, em
or rem
. em
and rem
values will be calculated and output in pixels accordingly.
Set arrow
to true
if you want your popover to contain arrows. These arrows will be placed accordingly to the placement
you have set
. They also take into account the border-radius
of the popover so they look right.
You can change the arrow’s width by setting arrowWidth
.
When arrows
are set, offset
will be the distance between PopoverTrigger
and the edge of the arrow.
If you encounter rounding issues with arrow
, you can use arrowDelta
to correct those rounding errors manually. This will give you precise control over the final placement of the arrow in the main axis.
You might need to zoom in cause the difference is extremely tiny. Alternatively, see the video example!
PopoverContent
is built on top of DisclosureContent
and inherits all of its options. In addition to the above properties, you can pass other DisclosureContent
properties into PopoverContent
.
PopoverContent
emits the following events:
open
- emitted when the PopoverContent
is openedclose
- emitted when the PopoverContent
is closedPopoverCloseButton
creates a button that closes the Popover when clicked. It is normally used inside PopoverContent
, but it can also be used elsewhere.
If you’re using PopoverCloseButton
outside PopoverContent
, you’ll need to give it a target
which corresponds to the Popover’s ID.
PopoverCloseButton
uses Tabler’s x
icon by default.
If you wish to change the icon, simply set the icon
property to your desired icon. See SVG
for more information on using icon
.
You can insert HTML into PopoverCloseButton
if you wish to create a custom close button.
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
A basic popover can be created with PopoverTrigger
and PopoverContent
.
When creating a popover, you need to pass the same value to the trigger’s target
and content’s id
property.
Popover Content
You can create a close button with PopoverCloseButton
.
Use Splendid Layouts
to create a layout for your popover
content easily.
If you do not wish to manually name the id
and target
properties, you can use randomString
from Splendid Utils
to create a DOM-ready random string. This can sometimes make things a tiny bit easier.
PopoverTrigger
creates a trigger button that opens PopoverContent
when clicked.
If you want to show the popover by default (great for debugging purposes), you can set show
to true.
If you want to show the popover on hover, you can set showOnHover
to true.
You can also control the delay before the popover closes by setting hoverCloseDelay
to a number in milliseconds.
Normally, only one popover will be opened by default. So if you open a new popover, the previous one will close automatically.
If you wish to have multiple popovers opened, you can set closeOthers
to false
on them all.
PopoverTrigger
is built on top of DisclosureTrigger
and inherits all of its options. In addition to the above properties, you can pass other DisclosureTrigger
properties into PopoverTrigger
.
All other unnamed properties will be passed directly to the underlying button
element.
PopoverContent
contains content that should show up when PopoverTrigger
is clicked.
PopoverContent
has 12 placement options:
top
, top-start
, top-end
left
, left-start
, left-end
right
, right-start
, right-end
bottom
, bottom-start
, bottom-end
top
, left
, right
, and bottom
refer to its position on the main axis. while start
and end
refers to its position on the cross axis. The following example would make more sense:
If there isn’t enough space to display the popover on the main axis, it will automatically be displayed in the opposite direction. If there is still insuffient space, it will be displayed in the other axis, whenever possible.
See Portal
below for an example on how they will be displayed.
By default, PopoverContent
will be moved out from their default DOM locations and inserted as a direct descendant of the <body>
element. This prevents PopoverContent
from being constrained (or even cut-off) by parent elements.
If you wish to disable this behaviour, set the portal
option to false
.
You can set an offset value in px
, em
or rem
. em
and rem
values will be calculated and output in pixels accordingly.
Set arrow
to true
if you want your popover to contain arrows. These arrows will be placed accordingly to the placement
you have set
. They also take into account the border-radius
of the popover so they look right.
You can change the arrow’s width by setting arrowWidth
.
When arrows
are set, offset
will be the distance between PopoverTrigger
and the edge of the arrow.
If you encounter rounding issues with arrow
, you can use arrowDelta
to correct those rounding errors manually. This will give you precise control over the final placement of the arrow in the main axis.
You might need to zoom in cause the difference is extremely tiny. Alternatively, see the video example!
PopoverContent
is built on top of DisclosureContent
and inherits all of its options. In addition to the above properties, you can pass other DisclosureContent
properties into PopoverContent
.
PopoverContent
emits the following events:
open
- emitted when the PopoverContent
is openedclose
- emitted when the PopoverContent
is closedPopoverCloseButton
creates a button that closes the Popover when clicked. It is normally used inside PopoverContent
, but it can also be used elsewhere.
If you’re using PopoverCloseButton
outside PopoverContent
, you’ll need to give it a target
which corresponds to the Popover’s ID.
PopoverCloseButton
uses Tabler’s x
icon by default.
If you wish to change the icon, simply set the icon
property to your desired icon. See SVG
for more information on using icon
.
You can insert HTML into PopoverCloseButton
if you wish to create a custom close button.
Popover is built on top of Disclosure
and inherits all its accessibility features. For your convenience, we have listed some of the most important features and how to use them here.
Users can dismiss the popover via three main ways:
PopoverContent
*: “Clicking” includes using Enter and Space keys because we used the standard <button>
element.
You can disable the second and third dismissal methods by setting their respective options to false
:
This section covers how Popover
handles focus.
When PopoverContent
opens, it will automatically be focused, so keyboard users and screen readers can start interacting with it immediately.
Open the popover and press the Tab key to try it out!
If a user closes PopoverContent
with the Esc key or by clicking on PopoverCloseButton
, we will focus on the PopoverTrigger
. This lets keyboard and screen reader users navigate to the next item without using a mouse.
To disable this behaviour, you can set focusTriggerOnClose
to false
:
PopoverContent
handles focus in the following way:
PopoverContent
, PopoverContent
will close and focus will move onto the next item after PopoverTrigger
.PopoverContent
will not close, and focus goes back to PopoverTrigger
.We built this behaviour because it seems to be most sensible for screen readers and keyboard users.
Try these:
And these:
The following is true for labelling Popover components:
PopoverTrigger
is optional if the text content is clear enough.PopoverContent
is necessary.PopoverCloseButton
has a default label set to “Close dialog”.You can use aria-label
or aria-labelledby
to give PopoverTrigger
, PopoverContent
, and PopoverCloseButton
accessible names.
PopoverContent
needs a role
to be accessible. We have set it to dialog
because that’s what you would use for most use-cases. (Don’t worry about other roles because our others components would handle those roles
for you).
That said, you can change PopoverContent
’s role
if you want to. If the role
is menu
, Listbox
, grid
, or tree
, you should also set PopoverTrigger
’s aria-haspopup
value to the same role. If not, set aria-haspopup
to null
.
Popover Content
Popover Content
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
Popover is built on top of Disclosure
and inherits all its accessibility features. For your convenience, we have listed some of the most important features and how to use them here.
Users can dismiss the popover via three main ways:
PopoverContent
*: “Clicking” includes using Enter and Space keys because we used the standard <button>
element.
You can disable the second and third dismissal methods by setting their respective options to false
:
This section covers how Popover
handles focus.
When PopoverContent
opens, it will automatically be focused, so keyboard users and screen readers can start interacting with it immediately.
Open the popover and press the Tab key to try it out!
If a user closes PopoverContent
with the Esc key or by clicking on PopoverCloseButton
, we will focus on the PopoverTrigger
. This lets keyboard and screen reader users navigate to the next item without using a mouse.
To disable this behaviour, you can set focusTriggerOnClose
to false
:
PopoverContent
handles focus in the following way:
PopoverContent
, PopoverContent
will close and focus will move onto the next item after PopoverTrigger
.PopoverContent
will not close, and focus goes back to PopoverTrigger
.We built this behaviour because it seems to be most sensible for screen readers and keyboard users.
Try these:
And these:
The following is true for labelling Popover components:
PopoverTrigger
is optional if the text content is clear enough.PopoverContent
is necessary.PopoverCloseButton
has a default label set to “Close dialog”.You can use aria-label
or aria-labelledby
to give PopoverTrigger
, PopoverContent
, and PopoverCloseButton
accessible names.
PopoverContent
needs a role
to be accessible. We have set it to dialog
because that’s what you would use for most use-cases. (Don’t worry about other roles because our others components would handle those roles
for you).
That said, you can change PopoverContent
’s role
if you want to. If the role
is menu
, Listbox
, grid
, or tree
, you should also set PopoverTrigger
’s aria-haspopup
value to the same role. If not, set aria-haspopup
to null
.
Popover Content
Popover Content
You can import the basic styles for Popover
through Splendid Styles.
PopoverTrigger
produces the following output:
PopoverContent
produces the following output.
If you set the arrow
option to true
, PopoverContent
will include a PopoverArrow
element.
PopoverCloseButton
produces the following HTML:
If content is passed into PopoverCloseButton
, the content will replace the <svg>
element.
The following classes are used by PopoverTrigger
Class | Description |
---|---|
Button | Generic styles used for buttons. See Button . |
PopoverTrigger | Styles for Popover trigger |
These properties can be used to add classes to PopoverTrigger
.
Class | Description |
---|---|
class | Adds classes to the button |
The following classes are used by PopoverContent
Class | Description |
---|---|
PopoverContent | Styles the content |
These properties can be used to add classes to PopoverContent
.
Class | Description |
---|---|
class | Adds classes to the content |
The following classes are used by PopoverCloseButton
Class | Description |
---|---|
Button-icon | Generic styles used for button icons. See Button . |
PopoverCloseButton | Styles for the close button |
These properties can be used to add classes to PopoverCloseButton
.
Class | Description |
---|---|
class | Adds classes to the button |
iconClass | Adds classes to icon |
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
You can import the basic styles for Popover
through Splendid Styles.
PopoverTrigger
produces the following output:
PopoverContent
produces the following output.
If you set the arrow
option to true
, PopoverContent
will include a PopoverArrow
element.
PopoverCloseButton
produces the following HTML:
If content is passed into PopoverCloseButton
, the content will replace the <svg>
element.
The following classes are used by PopoverTrigger
Class | Description |
---|---|
Button | Generic styles used for buttons. See Button . |
PopoverTrigger | Styles for Popover trigger |
These properties can be used to add classes to PopoverTrigger
.
Class | Description |
---|---|
class | Adds classes to the button |
The following classes are used by PopoverContent
Class | Description |
---|---|
PopoverContent | Styles the content |
These properties can be used to add classes to PopoverContent
.
Class | Description |
---|---|
class | Adds classes to the content |
The following classes are used by PopoverCloseButton
Class | Description |
---|---|
Button-icon | Generic styles used for button icons. See Button . |
PopoverCloseButton | Styles for the close button |
These properties can be used to add classes to PopoverCloseButton
.
Class | Description |
---|---|
class | Adds classes to the button |
iconClass | Adds classes to icon |
The following properties affect the functionality of PopoverTrigger
.
Property | Type | Description |
---|---|---|
target | string | id of the PopoverContent . Required. |
show | boolean | Whether to show the popover. Default is false . |
aria-haspopup | string | aria-haspopup value. Default is dialog . |
options | object | Additional options. This inherits from DisclosureTrigger . |
The following properties affect the functionality of PopoverContent
.
Property | Type | Description |
---|---|---|
id | string | id of PopoverContent . Required. |
role | boolean | Role for the popover content |
options | object | Additional options. Includes options DisclosureContent options and other options below. |
PopoverContent
has these options:
Property | Type | Default | Description |
---|---|---|---|
placement | string | top | Placement of the popover content. Can be top , top-start , top-end , bottom , bottom-start , bottom-end , left , left-start , left-end , right , right-start or right-end |
offset | string|number | 0.5rem | Offset between PopoverTrigger and PopoverContent . |
arrow | boolean | false | Whether to create an arrow. |
arrowDelta | number | 0 | Amount to bump the arrow position by |
arrowWidth | string|number | 0.5rem | Size of the arrow. |
You can provide the following properties to PopoverCloseButton
.
Property | Type | Description |
---|---|---|
icon | string | Icon to use when content is not passed into default slot. See SVG . |
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
The following properties affect the functionality of PopoverTrigger
.
Property | Type | Description |
---|---|---|
target | string | id of the PopoverContent . Required. |
show | boolean | Whether to show the popover. Default is false . |
aria-haspopup | string | aria-haspopup value. Default is dialog . |
options | object | Additional options. This inherits from DisclosureTrigger . |
The following properties affect the functionality of PopoverContent
.
Property | Type | Description |
---|---|---|
id | string | id of PopoverContent . Required. |
role | boolean | Role for the popover content |
options | object | Additional options. Includes options DisclosureContent options and other options below. |
PopoverContent
has these options:
Property | Type | Default | Description |
---|---|---|---|
placement | string | top | Placement of the popover content. Can be top , top-start , top-end , bottom , bottom-start , bottom-end , left , left-start , left-end , right , right-start or right-end |
offset | string|number | 0.5rem | Offset between PopoverTrigger and PopoverContent . |
arrow | boolean | false | Whether to create an arrow. |
arrowDelta | number | 0 | Amount to bump the arrow position by |
arrowWidth | string|number | 0.5rem | Size of the arrow. |
You can provide the following properties to PopoverCloseButton
.
Property | Type | Description |
---|---|---|
icon | string | Icon to use when content is not passed into default slot. See SVG . |