Vannsl / vue-contenteditable-form

A Notion-like forn using Vue 3, Vite and TailwindCSS

Home Page:vue-contenteditable-form.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Close Rich Text Toolbar when clicking outside

Vannsl opened this issue · comments

Story

As a user I want to be able to close the rich text toolbar by clicking anywhere else on the button.

History

Right now an "x" button is implemented to close the toolbar
Bildschirmfoto 2021-08-05 um 08 37 44

Technical notes

Here's an example Vue directive:

export default {
  mounted(el, binding) {
    el.clickOutsideEvent = (event) => {
      if (!(el === event.target || el.contains(event.target))) {
        binding.value(event, el);
      }
    };
    document.body.addEventListener("click", el.clickOutsideEvent);
  },

  unmounted(el) {
    document.body.removeEventListener("click", el.clickOutsideEvent);
  },
};