Improve dropdown developer experience #206
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relates to #205
This PR provides several DX improvements for the dropdown component
1. actions are self defined
The action to open close the dropdown and to navigate with the arrow in the menu are self defined by the controller so the html markup becomes simpler. We only need to add the
data-controller="dropdown"
and the button, menu and menuItem targets2. closeOnClickOuside option
The current dropdown would always close on a click outside. This is now configurable by setting the data-dropdown-close-on_click-outside-value="true/false". The default is the current behavior (true)
3. closeOnEsc option
The current dropdown would not close on ESC keydown. This is now configurable by setting the data-dropdown-close-on-esc-value="true/false". The default is (true)
4. defines default transition
If unset the dropdown will default to those transitions
Transition can be set using the Stimulus Class API
Testing
I wanted to add tests to cover the various logic here but I am struggling to make the test run locally
I cannot run the all suite without getting such errors