Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Make the popover positioning strategy configurable #1415

Merged
merged 3 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/VFilters/VFilterChecklist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<!-- License explanation -->
<VPopover
v-if="filterType === 'licenses'"
strategy="fixed"
:label="$t('browse-page.aria.license-explanation').toString()"
>
<template #trigger="{ a11yProps }">
Expand Down
14 changes: 14 additions & 0 deletions src/components/VPopover/VPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
:visible="visibleRef"
:trigger-element="triggerRef"
:placement="placement"
:strategy="strategy"
:hide-on-esc="hideOnEsc"
:hide-on-click-outside="hideOnClickOutside"
:auto-focus-on-show="autoFocusOnShow"
Expand Down Expand Up @@ -99,6 +100,19 @@ export default defineComponent({
String
),
},
/**
* The positioning strategy of the popover. If your reference element is in a fixed container
* use the fixed strategy; otherwise use the default, absolute strategy.
*
* @see https://popper.js.org/docs/v2/constructors/#strategy
*
* @default 'absolute'
*/
strategy: {
type: /** @type {import('@nuxtjs/composition-api').PropType<import('@popperjs/core').PositioningStrategy>} */ (
String
),
},
/**
* The label of the popover content. Must be provided if `labelledBy` is empty.
*
Expand Down
9 changes: 9 additions & 0 deletions src/components/VPopover/VPopoverContent.types.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ export const propTypes = {
default: 'bottom-end',
validate: (v) => popoverPlacements.includes(v),
},
strategy: {
type: /** @type {import('@nuxtjs/composition-api').PropType<import('@popperjs/core').PositioningStrategy>} */ (
String
),
default: 'absolute',
// todo: Use the actual PositioningStrategy type instead of manually writing these values,
// when this file is updated to TypeScript.
validate: (v) => ['absolute', 'fixed'].includes(v),
},
zIndex: {
type: Number,
},
Expand Down
9 changes: 7 additions & 2 deletions src/composables/use-popper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function usePopper({ popoverRef, popoverPropsRefs }) {
[
popoverPropsRefs.visible,
popoverPropsRefs.placement,
popoverPropsRefs.strategy,
popoverPropsRefs.triggerElement,
popoverRef,
],
Expand All @@ -26,12 +27,16 @@ export function usePopper({ popoverRef, popoverPropsRefs }) {
* @param {unknown} _
* @param {(cb: () => void) => void} onInvalidate
*/
([visible, placement, triggerElement, popover], _, onInvalidate) => {
(
[visible, placement, strategy, triggerElement, popover],
_,
onInvalidate
) => {
if (!(triggerElement && popover)) return

popperInstanceRef.value = createPopper(triggerElement, popover, {
placement,
strategy: 'absolute',
strategy,
modifiers: [
{
name: 'eventListeners',
Expand Down