diff options
author | Rohit Sharma <rohit2sharma95@gmail.com> | 2021-02-03 22:51:19 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-03 22:51:19 +0300 |
commit | 3770b7b9e3fd92b164a58caef05a4d9cd650a86a (patch) | |
tree | e77ca96026e5957f68939b95709731ddb4d22c5f /js/src/dropdown.js | |
parent | 02d103be9155514824f74edf17db92ed407b92f3 (diff) |
Dropdown — Emit events on the `.dropdown-toggle` button (#32625)
* Emit events on the dropdown button
Emit the events on `.dropdown-toggle` button and then bubble up
* Add migration note for events
* Update the docs for events
* Add unit test to check the event bubbling
Co-authored-by: XhmikosR <xhmikosr@gmail.com>
Diffstat (limited to 'js/src/dropdown.js')
-rw-r--r-- | js/src/dropdown.js | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/js/src/dropdown.js b/js/src/dropdown.js index 8fdf455801..69b99e628c 100644 --- a/js/src/dropdown.js +++ b/js/src/dropdown.js @@ -194,7 +194,7 @@ class Dropdown extends BaseComponent { this._menu.classList.toggle(CLASS_NAME_SHOW) this._element.classList.toggle(CLASS_NAME_SHOW) - EventHandler.trigger(parent, EVENT_SHOWN, relatedTarget) + EventHandler.trigger(this._element, EVENT_SHOWN, relatedTarget) } hide() { @@ -202,12 +202,11 @@ class Dropdown extends BaseComponent { return } - const parent = Dropdown.getParentFromElement(this._element) const relatedTarget = { relatedTarget: this._element } - const hideEvent = EventHandler.trigger(parent, EVENT_HIDE, relatedTarget) + const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE, relatedTarget) if (hideEvent.defaultPrevented) { return @@ -219,7 +218,7 @@ class Dropdown extends BaseComponent { this._menu.classList.toggle(CLASS_NAME_SHOW) this._element.classList.toggle(CLASS_NAME_SHOW) - EventHandler.trigger(parent, EVENT_HIDDEN, relatedTarget) + EventHandler.trigger(this._element, EVENT_HIDDEN, relatedTarget) } dispose() { @@ -383,7 +382,6 @@ class Dropdown extends BaseComponent { const toggles = SelectorEngine.find(SELECTOR_DATA_TOGGLE) for (let i = 0, len = toggles.length; i < len; i++) { - const parent = Dropdown.getParentFromElement(toggles[i]) const context = Data.getData(toggles[i], DATA_KEY) const relatedTarget = { relatedTarget: toggles[i] @@ -409,7 +407,7 @@ class Dropdown extends BaseComponent { continue } - const hideEvent = EventHandler.trigger(parent, EVENT_HIDE, relatedTarget) + const hideEvent = EventHandler.trigger(toggles[i], EVENT_HIDE, relatedTarget) if (hideEvent.defaultPrevented) { continue } @@ -429,7 +427,7 @@ class Dropdown extends BaseComponent { dropdownMenu.classList.remove(CLASS_NAME_SHOW) toggles[i].classList.remove(CLASS_NAME_SHOW) - EventHandler.trigger(parent, EVENT_HIDDEN, relatedTarget) + EventHandler.trigger(toggles[i], EVENT_HIDDEN, relatedTarget) } } |