Gathering detailed insights and metrics for ember-on-modifier
Gathering detailed insights and metrics for ember-on-modifier
Gathering detailed insights and metrics for ember-on-modifier
Gathering detailed insights and metrics for ember-on-modifier
ember-on-resize-modifier
Modifier relying on a single ResizeObserver instance for better performance.
ember-event-helpers
Complimentary event template helpers to the {{on}} modifier
ember-on-modifier-sugar
Syntax sugar for simple on modifier usecases
@twyr/ember-event-modifiers
Ember modifiers for detecting events not on the element, and in the capture phase
Implements the `{{on eventName this.someAction}}` element modifier from https://github.com/emberjs/rfcs/blob/master/text/0471-on-modifier.md
npm install ember-on-modifier
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (95.3%)
HTML (4.57%)
Handlebars (0.13%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
37 Stars
282 Commits
6 Forks
2 Watchers
41 Branches
8 Contributors
Updated on Jul 01, 2025
Latest Version
1.0.1
Package Id
ember-on-modifier@1.0.1
Size
129.50 kB
NPM Version
6.14.4
Node Version
13.12.0
Published on
Apr 16, 2020
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
26
A polyfill for the {{on}}
element modifier specified by
RFC #471 "{{on}}
modifier".
ember install ember-on-modifier
ember-source
3.11 or higherember-source
v2.13, v2.18, v3.4 in CI1<button {{on "click" this.onClick}}> 2 Click me baby, one more time! 3</button>
1import Component from '@ember/component'; 2import { action } from '@ember-decorators/object'; 3 4export default class BritneySpearsComponent extends Component { 5 @action 6 onClick(event: MouseEvent) { 7 console.log('I must confess, I still believe.'); 8 } 9}
The @action
decorator is used to bind the onClick
method to the
component instance.
This is essentially equivalent to:
1didInsertElement() { 2 super.didInsertElement(); 3 4 const button = this.element.querySelector('button'); 5 button.addEventListener('click', this.onClick); 6}
In addition to the above {{on}}
will properly tear down the event listener,
when the element is removed from the DOM. It will also re-register the event
listener, if any of the passed parameters change.
You can use the {{on}}
modifier multiple times on the same element, even for
the same event.
1<button 2 {{on "click" this.onClick}} 3 {{on "click" this.anotherOnClick}} 4 {{on "mouseover" this.onMouseEnter}} 5> 6 Click me baby, one more time! 7</button>
All named parameters will be passed through to
addEventListener
as the third parameter, the options hash.
1<div {{on "scroll" this.onScroll passive=true}}> 2 Lorem Ipsum ... 3</div>
This is essentially equivalent to:
1didInsertElement() { 2 super.didInsertElement(); 3 4 const div = this.element.querySelector('div'); 5 div.addEventListener('scroll', this.onScroll, { passive: true }); 6}
once
To fire an event listener only once, you can pass the once
option:
1<button 2 {{on "click" this.clickOnlyTheFirstTime once=true}} 3 {{on "click" this.clickEveryTime}} 4> 5 Click me baby, one more time! 6</button>
clickOnlyTheFirstTime
will only be fired the first time the button is clicked.
clickEveryTime
is fired every time the button is clicked, including the first
time.
capture
To listen for an event during the capture phase already, use the capture
option:
1<div {{on "click" this.triggeredFirst capture=true}}> 2 <button {{on "click" this.triggeredLast}}> 3 Click me baby, one more time! 4 </button> 5</div>
passive
If true
, you promise to not call event.preventDefault()
. This allows the
browser to optimize the processing of this event and not block the UI thread.
This prevent scroll jank.
If you still call event.preventDefault()
, an assertion will be raised.
1<div {{on "scroll" this.trackScrollPosition passive=true}}> 2 Lorem ipsum... 3</div>
Internet Explorer 11 has a buggy and incomplete implementation of
addEventListener
: It does not accept an
options
parameter and sometimes even throws
a cryptic error when passing options.
This is why this addon ships a tiny ponyfill for addEventLisener
that is used internally to emulate the once
, capture
and passive
option.
This means that all currently known options
are
polyfilled, so that you can rely on them in your logic.
If you want to curry the function call / partially apply arguments, you can do
so using the {{fn}}
helper:
1{{#each this.users as |user|}} 2 <button {{on "click" (fn this.deleteUser user)}}> 3 Delete {{user.name}} 4 </button> 5{{/each}}
1import Component from '@ember/component'; 2import { action } from '@ember-decorators/object'; 3 4interface User { 5 name: string; 6} 7 8export default class UserListComponent extends Component { 9 users: User[] = [{ name: 'Tom Dale' }, { name: 'Yehuda Katz' }]; 10 11 @action 12 deleteUser(user: User, event: MouseEvent) { 13 event.preventDefault(); 14 this.users.removeObject(user); 15 } 16}
preventDefault
/ stopPropagation
/ stopImmediatePropagation
The old {{action}}
modifier used to allow easily
calling event.preventDefault()
like so:
1<a href="/" {{action this.someAction preventDefault=true}}>Click me</a>
You also could easily call event.stopPropagation()
to avoid bubbling like so:
1<a href="/" {{action this.someAction bubbles=false}}>Click me</a>
You can still do this using ember-event-helpers
:
1<a href="/" {{on "click" (prevent-default this.someAction)}}>Click me</a>
1<a href="/" {{on "click" (stop-propagation this.someAction)}}>Click me</a>
ember-on-helper
: A complimentary {{on}
template
helper that accepts arbitrary event targets.
1{{on eventTarget eventName eventListener}}
Also ships with two convenience helpers for adding event listeners to
document
and window
:
1{{on-document eventName eventListener}} 2{{on-window eventName eventListener}}
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Found 2/30 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
74 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More