Skip to content

Instantly share code, notes, and snippets.

@lennyburdette
Last active December 14, 2018 03:45
Show Gist options
  • Select an option

  • Save lennyburdette/33e5d8c305a2d23fd1b161ad69b3f7c3 to your computer and use it in GitHub Desktop.

Select an option

Save lennyburdette/33e5d8c305a2d23fd1b161ad69b3f7c3 to your computer and use it in GitHub Desktop.
Focus In/Out DOM versus Component Methods
import Ember from 'ember';
export default Ember.Component.extend({
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
log: [],
actions: {
domFocusIn({ target }) {
this.set('log', [...this.log, `DOM Focus In: ${target.id}`]);
},
domFocusOut({ target }) {
this.set('log', [...this.log, `DOM Focus Out: ${target.id}`]);
},
componentFocusIn({ target }) {
this.set('log', [...this.log, `Component Focus In: ${target.id}`]);
},
componentFocusOut({ target }) {
this.set('log', [...this.log, `Component Focus Out: ${target.id}`]);
}
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.container {
border: 1px solid lightblue;
padding: 10px;
}
.child {
padding: 10px;
margin: 10px;
}
<h2>onfocusin/onfocusout attributes (doesn't work!)</h2>
<div
class="container"
onfocusin={{action "domFocusIn"}}
onfocusout={{action "domFocusOut"}}
>
<input class="child" id="one-A" value="One A" />
<input class="child" id="one-B" value="One B" />
</div>
<h2>focusIn/focusOut methods (works!)</h2>
<MyComponent
class="container"
@focusIn={{action "componentFocusIn"}}
@focusOut={{action "componentFocusOut"}}
>
<input class="child" id="one-A" value="One A" />
<input class="child" id="one-B" value="One B" />
</MyComponent>
{{#each log as |line|}}
{{line}}<br>
{{/each}}
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment