Skip to content

Added disabled prop to render a disabled input rather than a span #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/vue-numeric.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
v-if="!readOnly"
ref="numeric"
:placeholder="placeholder"
:disabled="disabled"
v-model="amount"
type="tel"
@blur="onBlurHandler"
Expand Down Expand Up @@ -154,6 +155,12 @@ export default {
required: false
},

disabled: {
type: Boolean,
default: false,
required: false,
},

/**
* Position of currency symbol
* Symbol position props accept either 'suffix' or 'prefix' (default).
Expand All @@ -162,7 +169,7 @@ export default {
type: String,
default: 'prefix',
required: false
}
},
},

data: () => ({
Expand Down
22 changes: 22 additions & 0 deletions test/specs/vue-numeric.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,28 @@ describe('vue-numeric.vue', () => {
})
})

it('is is not disabled when disabled mode is disabled', done => {
const propsData = { value: 3000, disabled: true }
const wrapper = mount(VueNumeric, { propsData })

wrapper.setProps({ disabled: false })
wrapper.instance().$nextTick(() => {
expect(wrapper.instance().$el.hasAttribute('disabled')).to.equal(false)
done()
})
})

it('is disabled in disabled mode', done => {
const propsData = { value: 3000, disabled: false }
const wrapper = mount(VueNumeric, { propsData })

wrapper.setProps({ disabled: true })
wrapper.instance().$nextTick(() => {
expect(wrapper.instance().$el.hasAttribute('disabled')).to.equal(true)
done()
})
});

it('cannot exceed max props', () => {
const component = Vue.extend({
data: () => ({ total: 150 }),
Expand Down