Skip to content

Instantly share code, notes, and snippets.

@SarathSantoshDamaraju
Created August 1, 2019 07:01
Show Gist options
  • Select an option

  • Save SarathSantoshDamaraju/a4008594b5e6434540866492ab03a0a8 to your computer and use it in GitHub Desktop.

Select an option

Save SarathSantoshDamaraju/a4008594b5e6434540866492ab03a0a8 to your computer and use it in GitHub Desktop.
Ember Button
// HBS
{{#if label}}
{{label}}
{{else}}
{{yield}}
{{/if}}
// JS
import Component from '@ember/component';
import { htmlSafe } from '@ember/template';
export default Component.extend({
tagName: "button",
classNames: "",
classNameBindings: ["isDisabled:disabled"],
attributeBindings: [
'label',
"type",
"value",
"name",
"disabled",
"autoFocus:autofocus",
"formaction",
"form",
"aria-label",
"aria-labelledby",
"role",
"download",
"target",
"href",
"rel",
"ping"],
type: 'button',
prefix: "btn",
href: null,
target: null,
label: null,
init() {
this._super(...arguments);
if (this.get('href')) {
this.setProperties({
tagName: 'a',
role: 'button'
});
} else {
if (!this.get('name')) {
this.set('name', this.get('aria-label') ? htmlSafe(this.get('aria-label')) : "")
}
}
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment