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

soc221b/vue-use-popperjs

Repository files navigation

vue-use-popperjs

Vue composable based on @popperjs/core

Installation

npm i vue-use-popperjs@^3

Usage

Use with native elements:

<script setup lang="ts">
  import { ref } from "vue";
  import { usePopperjs } from "vue-use-popperjs";

  const reference = ref<null | Element>(null);
  const popper = ref<null | HTMLElement>(null);
  const { instance } = usePopperjs({ reference, popper });
</script>

<template>
  <button ref="reference" aria-describedby="tooltip">I'm a button</button>
  <span ref="popper" role="tooltip">I'm a tooltip</span>
</template>

Use with components:

<script setup lang="ts">
  import { ref, type ComponentPublicInstance } from "vue";
  import { usePopperjs } from "vue-use-popperjs";

  const reference = ref<null | ComponentPublicInstance>(null);
  const popper = ref<null | ComponentPublicInstance>(null);
  const { instance } = usePopperjs({ reference, popper });
</script>

<template>
  <MyButton ref="reference">Reference</MyButton>
  <MyToolTip ref="popper">Popcorn</MyToolTip>
</template>