Skip to content

Commit

Permalink
Add ability to conditionally render Popper
Browse files Browse the repository at this point in the history
  • Loading branch information
Valgeir Bjornsson committed Jul 6, 2021
1 parent 398db41 commit 7eb011e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
11 changes: 4 additions & 7 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
const devPresets = ['@vue/babel-preset-app'];
const devPresets = ["@vue/babel-preset-app"];
const buildPresets = [
[
'@babel/preset-env',
"@babel/preset-env",
// Config for @babel/preset-env
{
// Example: Always transpile optional chaining/nullish coalescing
// include: [
// /(optional-chaining|nullish-coalescing)/
// ],
include: [/(optional-chaining|nullish-coalescing)/],
},
],
];
module.exports = {
presets: (process.env.NODE_ENV === 'development' ? devPresets : buildPresets),
presets: process.env.NODE_ENV === "development" ? devPresets : buildPresets,
};
11 changes: 8 additions & 3 deletions src/component/Popper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</div>
<Transition name="fade">
<div
v-if="isOpen"
:class="['popper', isOpen ? 'inline-block' : null]"
v-show="showPopper"
:class="['popper', showPopper ? 'inline-block' : null]"
ref="popperNode"
>
<!-- A slot for the popper content -->
Expand All @@ -28,7 +28,7 @@
</template>

<script>
import { defineComponent, toRefs } from "vue";
import { computed, defineComponent, toRefs } from "vue";
import usePopper from "@/composables";
import clickAway from "@/directives";

Expand Down Expand Up @@ -131,13 +131,18 @@
close,
} = usePopper({ offsetX, offsetY, arrowPadding, placement, emit });

const showPopper = computed(() => {
return isOpen.value && slots.content?.().length;
});

return {
popperNode,
triggerNode,
isOpen,
toggle,
open,
close,
showPopper,
};
},
});
Expand Down

0 comments on commit 7eb011e

Please sign in to comment.