designing-with-tailwindcss icon indicating copy to clipboard operation
designing-with-tailwindcss copied to clipboard

What about closing dropdown when clicking elsewhere

Open vedmant opened this issue 5 years ago • 8 comments

What about closing dropdown when clicking elsewhere? That's default behavior of all dropdowns.

vedmant avatar Jun 11 '20 05:06 vedmant

Create a transparent button the size of the entire screen that closes the dropdown, and put it between your dropdown and the rest of your site.

arimendelow avatar Jun 11 '20 06:06 arimendelow

@arimendelow The problem here is that other elements will not work when you click somewhere also mouse pointer will not change when you hovering other elements. So with this approach you need to click twice to click some other button when dropdown is active, that's not desired behaviour.

vedmant avatar Jun 12 '20 06:06 vedmant

That’s generally what sites do, but you could also have a click event listener that closes the menu for any click of the mouse.

arimendelow avatar Jun 12 '20 07:06 arimendelow

@arimendelow Popular UI frameworks handle this the proper way: https://bootstrap-vue.org/docs/components/dropdown#dropdowns https://vuetifyjs.com/en/components/buttons/#button-dropdown-variants https://quasar.dev/vue-components/editor#Dropdowns

This is what I find problematic with Tailwind is that it requires to reinvent the wheel in many cases.

vedmant avatar Jun 12 '20 09:06 vedmant

Tailwind is just a better way to write CSS. If you want full components, look into Tailwind UI. They’re doing amazing work on it!

arimendelow avatar Jun 12 '20 18:06 arimendelow

To clarify: TW is not a UI framework. UI frameworks are opinionated and not suitable for devs that want to take ownership over the design of their application

arimendelow avatar Jun 12 '20 18:06 arimendelow

You will have to implement that yourself.

OlamiBounty avatar Jun 12 '20 20:06 OlamiBounty

@arimendelow for sure that what everyone says, but for me main issue with using Tailwind is reinventing wheel in many cases or adding non various Tailwind third party components with it's own styles and different vendors.

Why then there is dropdown example at all if this is only CSS framework. Just means that there is a huge demand for standard components like dropdowns / modals.

Looking forward to Tailwind UI framework.

vedmant avatar Jun 13 '20 02:06 vedmant