Skip to content

Instantly share code, notes, and snippets.

@amk221
Last active December 11, 2019 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amk221/db7f6e382bd0b1de91447881eebb62a5 to your computer and use it in GitHub Desktop.
Save amk221/db7f6e382bd0b1de91447881eebb62a5 to your computer and use it in GitHub Desktop.
"Modified twice"
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['my-child-component']
});
import Ember from 'ember';
import run from 'ember-runloop';
export default Ember.Component.extend({
classNames: ['my-component'],
classNameBindings: ['isFocused'],
attributeBindings: ['tabindex'],
tabindex: '0',
focusIn() {
this._super(...arguments);
this.set('isFocused', true);
},
focusOut() {
this._super(...arguments);
this.set('isFocused', false);
},
actions: {
open() {
this.set('isOpen', true);
},
close() {
this.set('isOpen', false);
}
}
});
.my-component {
border: 2px solid red;
min-height: 1em;
padding: 1em;
outline: none;
}
.my-child-component {
border: 2px solid blue;
min-height: 1em;
padding: 1em;
}
.my-component.is-focused {
border: 2px solid green;
}
{{#my-component as |mc|}}
<button onclick={{action mc.open}}>open</button>
<button onclick={{action mc.close}}>close</button>
<br><br>
{{#mc.child}}
<button onclick={{action mc.close}}>
close (causes double render error)
</button>
{{/mc.child}}
{{/my-component}}
Focused?: {{this.isFocused}}
<br><br>
{{yield (hash
open=(action 'open')
close=(action 'close')
child=(if this.isOpen (component 'my-child-component'))
)}}
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment