Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

498 add event handlers #499

Merged
merged 15 commits into from
Jul 16, 2020
11 changes: 11 additions & 0 deletions addon/components/basic-dropdown-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ export default @layout(templateLayout) @tagName('')class BasicDropdownContent ex
}

// Methods
/**
* Allows similair behaviour to `ember-composable-helpers`' `optional` helper.
* Avoids adding extra dependencies.
* Can be removed when the template `V1` compatability event handlers are removed.
*
* @see https://github.com/cibernox/ember-basic-dropdown/issues/498
* @memberof BasicDropdownContent
*/
@action
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are not accessing this, there is no need of decorating the function with @action

noop() {}

@action
setup(dropdownElement) {
let triggerElement = document.querySelector(`[data-ebd-id=${this.dropdown.uniqueId}-trigger]`);
Expand Down
11 changes: 11 additions & 0 deletions addon/components/basic-dropdown-trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ export default @layout(templateLayout) @tagName('') class BasicDropdownTrigger e
stopPropagation = false;

// Actions
/**
* Allows similair behaviour to `ember-composable-helpers`' `optional` helper.
* Avoids adding extra dependencies.
* Can be removed when the template `V1` compatability event handlers are removed.
*
* @see https://github.com/cibernox/ember-basic-dropdown/issues/498
* @memberof BasicDropdownContent
*/
@action
noop() {}

@action
handleMouseDown(e) {
if (this.dropdown.disabled) {
Expand Down
6 changes: 6 additions & 0 deletions addon/templates/components/basic-dropdown-content.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
{{will-destroy this.teardownMutationObserver}}
{{will-destroy this.animateOut}}
{{will-destroy this.teardown}}

{{!-- V1 compatibility - See #498 --}}
{{on "focusin" (fn (or @onFocusIn this.noop) @dropdown)}}
{{on "focusout" (fn (or @onFocusOut this.noop) @dropdown)}}
{{on "mouseenter" (fn (or @onMouseEnter this.noop) @dropdown)}}
{{on "mouseleave" (fn (or @onMouseLeave this.noop) @dropdown)}}
...attributes>
{{yield}}
</Element>
Expand Down
12 changes: 12 additions & 0 deletions addon/templates/components/basic-dropdown-trigger.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
{{on "keydown" this.handleKeyDown}}
{{on "touchstart" this.handleTouchStart}}
{{on "touchend" this.handleTouchEnd}}

{{!-- V1 compatibility - See #498 --}}
{{on "keydown" (fn (or @onKeyDown this.noop) @dropdown)}}
{{on "mousedown" (fn (or @onMouseDown this.noop) @dropdown)}}
{{on "touchend" (fn (or @onTouchEnd this.noop) @dropdown)}}
{{on "click" (fn (or @onClick this.noop) @dropdown)}}
{{on "mouseenter" (fn (or @onMouseEnter this.noop) @dropdown)}}
{{on "mouseleave" (fn (or @onMouseLeave this.noop) @dropdown)}}
{{on "focus" (fn (or @onFocus this.noop) @dropdown)}}
{{on "blur" (fn (or @onBlur this.noop) @dropdown)}}
{{on "focusin" (fn (or @onFocusIn this.noop) @dropdown)}}
{{on "focusout" (fn (or @onFocusOut this.noop) @dropdown)}}
>
{{yield}}
</Element>
Expand Down