{"id":13807394,"url":"https://github.com/ember-polyfills/ember-on-modifier","last_synced_at":"2026-03-01T09:36:13.888Z","repository":{"id":44117089,"uuid":"168217533","full_name":"ember-polyfills/ember-on-modifier","owner":"ember-polyfills","description":"Implements the `{{on eventName this.someAction}}` element modifier from https://github.com/emberjs/rfcs/blob/master/text/0471-on-modifier.md","archived":false,"fork":false,"pushed_at":"2022-12-10T16:52:39.000Z","size":1844,"stargazers_count":36,"open_issues_count":41,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-02-06T00:30:29.574Z","etag":null,"topics":["ember","ember-addon","ember-element-modifier","ember-modifier","emberjs","polyfill"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ember-polyfills.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-29T19:47:40.000Z","updated_at":"2026-01-19T13:42:29.000Z","dependencies_parsed_at":"2023-01-26T06:45:08.921Z","dependency_job_id":null,"html_url":"https://github.com/ember-polyfills/ember-on-modifier","commit_stats":null,"previous_names":["buschtoens/ember-on-modifier"],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/ember-polyfills/ember-on-modifier","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ember-polyfills%2Fember-on-modifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ember-polyfills%2Fember-on-modifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ember-polyfills%2Fember-on-modifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ember-polyfills%2Fember-on-modifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ember-polyfills","download_url":"https://codeload.github.com/ember-polyfills/ember-on-modifier/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ember-polyfills%2Fember-on-modifier/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29965708,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T09:33:09.965Z","status":"ssl_error","status_checked_at":"2026-03-01T09:25:48.915Z","response_time":124,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ember","ember-addon","ember-element-modifier","ember-modifier","emberjs","polyfill"],"created_at":"2024-08-04T01:01:25.037Z","updated_at":"2026-03-01T09:36:13.577Z","avatar_url":"https://github.com/ember-polyfills.png","language":"JavaScript","funding_links":[],"categories":["Packages"],"sub_categories":["Modifiers"],"readme":"# ember-on-modifier\n\n[![Build Status](https://travis-ci.org/buschtoens/ember-on-modifier.svg)](https://travis-ci.org/buschtoens/ember-on-modifier)\n[![npm version](https://badge.fury.io/js/ember-on-modifier.svg)](http://badge.fury.io/js/ember-on-modifier)\n[![Download Total](https://img.shields.io/npm/dt/ember-on-modifier.svg)](http://badge.fury.io/js/ember-on-modifier)\n[![Ember Observer Score](https://emberobserver.com/badges/ember-on-modifier.svg)](https://emberobserver.com/addons/ember-on-modifier)\n[![Ember Versions](https://img.shields.io/badge/Ember.js%20Versions-%5E2.18%20%7C%7C%20%5E3.0-brightgreen.svg)](https://travis-ci.org/buschtoens/ember-on-modifier)\n[![ember-cli Versions](https://img.shields.io/badge/ember--cli%20Versions-%5E2.12%20%7C%7C%20%5E3.0-brightgreen.svg)](https://travis-ci.org/buschtoens/ember-on-modifier)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![dependencies](https://img.shields.io/david/buschtoens/ember-on-modifier.svg)](https://david-dm.org/buschtoens/ember-on-modifier)\n[![devDependencies](https://img.shields.io/david/dev/buschtoens/ember-on-modifier.svg)](https://david-dm.org/buschtoens/ember-on-modifier)\n\nA polyfill for the `{{on}}` element modifier specified by\n[RFC #471 \"`{{on}}` modifier\"](https://github.com/emberjs/rfcs/blob/master/text/0471-on-modifier.md).\n\n## Installation\n\n```\nember install ember-on-modifier\n```\n\n## Compatibility\n\n* Completely inert when running `ember-source` 3.11 or higher\n* Tested against `ember-source` v2.12, v2.18, v3.4 in CI\n\n## Usage\n\n```hbs\n\u003cbutton {{on \"click\" this.onClick}}\u003e\n  Click me baby, one more time!\n\u003c/button\u003e\n```\n\n```ts\nimport Component from '@ember/component';\nimport { action } from '@ember-decorators/object';\n\nexport default class BritneySpearsComponent extends Component {\n  @action\n  onClick(event: MouseEvent) {\n    console.log('I must confess, I still believe.');\n  }\n}\n```\n\nThe [`@action` decorator][@action] is used to bind the `onClick` method to the\ncomponent instance.\n\n[@action]: https://github.com/emberjs/rfcs/blob/master/text/0408-decorators.md#method-binding\n\nThis is essentially equivalent to:\n\n```ts\ndidInsertElement() {\n  super.didInsertElement();\n\n  const button = this.element.querySelector('button');\n  button.addEventListener('click', this.onClick);\n}\n```\n\nIn addition to the above `{{on}}` will properly tear down the event listener,\nwhen the element is removed from the DOM. It will also re-register the event\nlistener, if any of the passed parameters change.\n\n### Listening to Multiple Events\n\nYou can use the `{{on}}` modifier multiple times on the same element, even for\nthe same event.\n\n```hbs\n\u003cbutton\n  {{on \"click\" this.onClick}}\n  {{on \"click\" this.anotherOnClick}}\n  {{on \"mouseover\" this.onMouseEnter}}\n\u003e\n  Click me baby, one more time!\n\u003c/button\u003e\n```\n\n### Event Options\n\nAll named parameters will be passed through to\n[`addEventListener`][addeventlistener] as the third parameter, the options hash.\n\n[addeventlistener]: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener\n\n```hbs\n\u003cdiv {{on \"scroll\" this.onScroll passive=true}}\u003e\n  Lorem Ipsum ...\n\u003c/div\u003e\n```\n\nThis is essentially equivalent to:\n\n```ts\ndidInsertElement() {\n  super.didInsertElement();\n\n  const div = this.element.querySelector('div');\n  div.addEventListener('scroll', this.onScroll, { passive: true });\n}\n```\n\n#### `once`\n\nTo fire an event listener only once, you can pass the [`once` option][addeventlistener-parameters]:\n\n```hbs\n\u003cbutton\n  {{on \"click\" this.clickOnlyTheFirstTime once=true}}\n  {{on \"click\" this.clickEveryTime}}\n\u003e\n  Click me baby, one more time!\n\u003c/button\u003e\n```\n\n`clickOnlyTheFirstTime` will only be fired the first time the button is clicked.\n`clickEveryTime` is fired every time the button is clicked, including the first\ntime.\n\n[addeventlistener-parameters]: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Parameters\n\n#### `capture`\n\nTo listen for an event during the capture phase already, use the [`capture` option][addeventlistener-parameters]:\n\n```hbs\n\u003cdiv {{on \"click\" this.triggeredFirst capture=true}}\u003e\n  \u003cbutton {{on \"click\" this.triggeredLast}}\u003e\n    Click me baby, one more time!\n  \u003c/button\u003e\n\u003c/div\u003e\n```\n\n#### `passive`\n\nIf `true`, you promise to not call `event.preventDefault()`. This allows the\nbrowser to optimize the processing of this event and not block the UI thread.\nThis prevent scroll jank.\n\nIf you still call `event.preventDefault()`, an assertion will be raised.\n\n```hbs\n\u003cdiv {{on \"scroll\" this.trackScrollPosition passive=true}}\u003e\n  Lorem ipsum...\n\u003c/div\u003e\n```\n\n#### Internet Explorer 11 Support\n\nInternet Explorer 11 has a buggy and incomplete implementation of\n`addEventListener`: It does not accept an\n[`options`][addeventlistener-parameters] parameter and _sometimes_ even throws\na cryptic error when passing options.\n\nThis is why this addon ships a tiny [ponyfill][ponyfill] for `addEventLisener`\nthat is used internally to emulate the `once`, `capture` and `passive` option.\nThis means that all currently known [`options`][addeventlistener-parameters] are\npolyfilled, so that you can rely on them in your logic.\n\n[ponyfill]: https://github.com/sindresorhus/ponyfill\n\n### Currying / Partial Application\n\nIf you want to curry the function call / partially apply arguments, you can do\nso using the [`{{fn}}` helper][fn-helper]:\n\n[fn-helper]: https://github.com/emberjs/rfcs/blob/master/text/0470-fn-helper.md\n\n```hbs\n{{#each this.users as |user|}}\n  \u003cbutton {{on \"click\" (fn this.deleteUser user)}}\u003e\n    Delete {{user.name}}\n  \u003c/button\u003e\n{{/each}}\n```\n\n```ts\nimport Component from '@ember/component';\nimport { action } from '@ember-decorators/object';\n\ninterface User {\n  name: string;\n}\n\nexport default class UserListComponent extends Component {\n  users: User[] = [{ name: 'Tom Dale' }, { name: 'Yehuda Katz' }];\n\n  @action\n  deleteUser(user: User, event: MouseEvent) {\n    event.preventDefault();\n    this.users.removeObject(user);\n  }\n}\n```\n\n### `preventDefault` / `stopPropagation` / `stopImmediatePropagation`\n\nThe old [`{{action}}` modifier][action-event-propagation] used to allow easily\ncalling `event.preventDefault()` like so:\n\n```hbs\n\u003ca href=\"/\" {{action this.someAction preventDefault=true}}\u003eClick me\u003c/a\u003e\n```\n\n[action-event-propagation]: https://www.emberjs.com/api/ember/release/classes/Ember.Templates.helpers/methods/action?anchor=action#event-propagation\n\nYou also could easily call `event.stopPropagation()` to avoid bubbling like so:\n\n```hbs\n\u003ca href=\"/\" {{action this.someAction bubbles=false}}\u003eClick me\u003c/a\u003e\n```\n\nYou can still do this using [`ember-event-helpers`][ember-event-helpers]:\n\n[ember-event-helpers]: https://github.com/buschtoens/ember-event-helpers\n\n```hbs\n\u003ca href=\"/\" {{on \"click\" (prevent-default this.someAction)}}\u003eClick me\u003c/a\u003e\n```\n\n```hbs\n\u003ca href=\"/\" {{on \"click\" (stop-propagation this.someAction)}}\u003eClick me\u003c/a\u003e\n```\n\n## Related Projects\n\n- **[`ember-on-helper`][ember-on-helper]:** A complimentary `{{on}` template\n  helper that accepts arbitrary event targets.\n\n  ```hbs\n  {{on eventTarget eventName eventListener}}\n  ```\n\n  Also ships with two convenience helpers for adding event listeners to\n  `document` and `window`:\n\n  ```hbs\n  {{on-document eventName eventListener}}\n  {{on-window eventName eventListener}}\n  ```\n\n[ember-on-helper]: https://github.com/buschtoens/ember-on-helper\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fember-polyfills%2Fember-on-modifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fember-polyfills%2Fember-on-modifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fember-polyfills%2Fember-on-modifier/lists"}