You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/release/components/template-lifecycle-dom-and-modifiers.md
+14-8Lines changed: 14 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -293,10 +293,17 @@ The modifier that we're going to build will allow us to say:
293
293
294
294
Pretty nice, right?
295
295
296
-
To accomplish that, we'll create a modifier in `app/modifiers/autofocus.js`. First, install [`ember-modifier`](https://github.com/ember-modifier/ember-modifier) and then generate an `autofocus` modifier for your app:
296
+
New Ember apps ship with a dependency on
297
+
[ember-modifier](https://github.com/ember-modifier/ember-modifier), which
298
+
provides a friendly API for writing your own element modifiers. This library is
299
+
in turn based on a low level API named _modifier managers_. Managers are a
300
+
framework-development level feature, and not something most developers need to
301
+
interact with. You'll see in the following examples that the modifier API is
302
+
imported from the `ember-modifier` package.
303
+
304
+
First generate the `autofocus` modifier for your application:
297
305
298
306
```bash
299
-
ember install ember-modifier
300
307
ember generate modifier autofocus
301
308
```
302
309
@@ -308,9 +315,10 @@ import { modifier } from "ember-modifier";
308
315
exportdefaultmodifier(element=>element.focus());
309
316
```
310
317
311
-
And that's it!
318
+
And that's it! Now we can use our custom `{{autofocus}}` modifier throughout our application.
312
319
313
-
Now we can use our custom `{{autofocus}}` modifier throughout our application.
320
+
Read more about the `ember-modifier` APIs at [ember-modifiers:
That's it for the component: we're translating the user's interactions into _state_. Now we need to build a modifier to translate the state into the appropriate DOM method calls!
The most important difference between this example and the cases we've seen so far is that we need to remove the `click` event handler from the document when this element is destroyed.
450
457
451
-
To accomplish this, we can use [`ember-modifier`](https://github.com/ember-modifier/ember-modifier) to create a `on-click-outside` modifier that sets up the event listener after the element is first inserted and removes the event listener when the element is removed.
458
+
To accomplish this, we can use [`ember-modifier`](https://github.com/ember-modifier/ember-modifier)(which is already installed in newly generated Ember apps) to create a `on-click-outside` modifier that sets up the event listener after the element is first inserted and removes the event listener when the element is removed.
452
459
453
-
Run the following commands to install the addon and generate a new modifier:
0 commit comments