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

Commit

Permalink
Make the popover positioning strategy configurable (#1415)
Browse files Browse the repository at this point in the history
* Switch popper.js to use fixed positioning strategy

* Make the popover positioning strategy configurable

* Update pot file
  • Loading branch information
zackkrida committed May 11, 2022
1 parent 1b01103 commit b0565a1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/components/VFilters/VFilterChecklist.vue
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
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
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
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
8 changes: 4 additions & 4 deletions src/locales/po-files/openverse.pot
Expand Up @@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Openverse \n"
"Report-Msgid-Bugs-To: https://github.com/wordpress/openverse/issues \n"
"POT-Creation-Date: 2022-05-11T02:19:06+00:00\n"
"POT-Creation-Date: 2022-05-11T19:21:48+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -142,7 +142,7 @@ msgid "Close"
msgstr ""

#. Do not translate words between ### ###.
#: src/components/VFilters/VFilterChecklist.vue:138
#: src/components/VFilters/VFilterChecklist.vue:139
msgctxt "modal.close-named"
msgid "Close ###name###"
msgstr ""
Expand Down Expand Up @@ -764,7 +764,7 @@ msgctxt "browse-page.aria.remove-filter"
msgid "remove filter"
msgstr ""

#: src/components/VFilters/VFilterChecklist.vue:27
#: src/components/VFilters/VFilterChecklist.vue:28
msgctxt "browse-page.aria.license-explanation"
msgid "license explanation"
msgstr ""
Expand Down Expand Up @@ -926,7 +926,7 @@ msgctxt "filters.license-explanation.more.read-more"
msgid "Read more"
msgstr ""

#: src/components/VFilters/VFilterChecklist.vue:118
#: src/components/VFilters/VFilterChecklist.vue:119
msgctxt "filters.search-by.title"
msgid "Search By"
msgstr ""
Expand Down

0 comments on commit b0565a1

Please sign in to comment.