Skip to content

Commit 0816b19

Browse files
committed
fix(component): should display the unmasked value when mask is falsy
1 parent 8d38604 commit 0816b19

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/component.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ export default {
6060
this.maskedValue = newValue
6161
}
6262
},
63+
mask(newMask) {
64+
if (!newMask) {
65+
// when removing the masking rule, set the displayed value to the unmasked
66+
// to remove any unwanted masking characters from the input
67+
this.maskedValue = this.unmaskedValue
68+
}
69+
},
6370
masked() {
6471
this.refresh()
6572
}

tests/component.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,18 @@ describe('Component', () => {
3535
await wrapper.setProps({ masked: true })
3636
expect(wrapper.vm.emittedValue).toBe('123-4')
3737
})
38+
39+
test('Removing the mask rule should set the value to the unmasked value', async () => {
40+
const value = '444555'
41+
const mask = '(###)###'
42+
43+
const wrapper = createWrapper({ value, mask })
44+
expect(wrapper.vm.maskedValue).toBe('(444)555')
45+
46+
await wrapper.setProps({ mask: null })
47+
expect(wrapper.vm.maskedValue).toBe('444555')
48+
49+
await wrapper.setProps({ mask })
50+
expect(wrapper.vm.maskedValue).toBe('(444)555')
51+
})
3852
})

0 commit comments

Comments
 (0)