# Dropdown Component ![dropdown](dropdown.gif) ## Usage ```javascript import { Dropdown } from "tailwindcss-stimulus-components" application.register('dropdown', Dropdown) ``` ```html
``` Dropdowns are set up to toggle if you click on the dropdown button or any of the options with in the dropdown menu (via `data-action="click->dropdown#toggle`). It will also close if you click anywhere outside of the dropdown. This is done using a window click event to check if the user clicked outside the dropdown (`data-action="click@window->dropdown#hide"`). Users can also focus on the dropdown button if `tabindex="0"` is included. They can toggle the dropdown with Space or Enter if the attribute `data-dropdown-target="button"` is included on the button. If you want a dropdown to be opened on page load you can set the ```data-dropdown-open-value="true"``` as a data attribute. The code above will toggle the dropdown component, if you needed to only perform a single action, such as `show` or `hide`. the dropdown component exposes such method. ```html data-action="click->dropdown#show" data-action="click->dropdown#hide" ``` ### Transitions The Dropdown component allows you to natively personalize the css transitions as described in the [transition](/docs/transition.md) utility. In the table below are detailed the defaults tansitions options values, and the data classes attributes you can apply to your controller element to customize your transitions. | Options | Default value | HTML data atribute | |-----------|------------------------------------|----------------------------------| | enter | `transition ease-out duration-100` | `data-dropdown-enter-class` | | enterFrom | `transform opacity-0 scale-95` | `data-dropdown-enter-from-class` | | enterTo | `transform opacity-100 scale-100` | `data-dropdown-enter-to-class` | | leave | `transition ease-in duration-75` | `data-dropdown-leave-class` | | leaveFrom | `transform opacity-100 scale-100` | `data-dropdown-leave-from-class` | | leaveTo | `transform opacity-0 scale-95` | `data-dropdown-leave-to-class` | | toggle | `hidden` | `data-dropdown-toggle-class` |