Skip to content

Commit

Permalink
[button] Add support for button type attribute (#549)
Browse files Browse the repository at this point in the history
* [button] Add support for button type attribute 

Adds new prop `type` which defaults to "button".

Only applied if neither `href` nor `to` prop are provided.
  • Loading branch information
tmorehouse committed Jun 26, 2017
1 parent 2f95dbd commit acb13b2
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions lib/components/button.vue
Expand Up @@ -2,6 +2,7 @@
<button v-bind="conditionalLinkProps"
:is="componentType"
:class="classList"
:type="btnType"
:disabled="disabled"
@click="onClick">
<slot></slot>
Expand All @@ -23,10 +24,8 @@ const linkProps = Object.assign(omitLinkProps('href', 'to'), {
export default {
components: { bLink },
computed: {
linkProps: computed.linkProps,
classList() {
return [
'btn',
Expand All @@ -36,32 +35,28 @@ export default {
this.btnDisabled
];
},
componentType() {
return (this.href || this.to) ? 'b-link' : 'button';
},
btnBlock() {
return this.block ? `btn-block` : '';
},
btnVariant() {
return this.variant ? `btn-${this.variant}` : `btn-secondary`;
},
btnSize() {
return this.size ? `btn-${this.size}` : '';
},
btnDisabled() {
return this.disabled ? 'disabled' : '';
},
btnType() {
return (this.href || this.to) ? null : this.type;
},
conditionalLinkProps() {
return this.componentType === 'button' ? {} : this.linkProps;
},
}
},
// merge our prepared link props with button props
props: Object.assign(linkProps, {
block: {
Expand All @@ -80,8 +75,11 @@ export default {
type: String,
default: null
},
type: {
type: String,
default: 'button'
}
}),
methods: {
onClick(e) {
if (this.disabled) {
Expand Down

0 comments on commit acb13b2

Please sign in to comment.