Skip to content
Open
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
16 changes: 16 additions & 0 deletions packages/primevue/src/inputnumber/InputNumber.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ describe('InputNumber.vue', () => {
expect(wrapper.find('input.p-inputnumber-input').element._value).toBe('$12,345.00');
});

it('should reset value to undefined when meta+backspace is pressed with allow-empty', async () => {
await wrapper.setProps({ modelValue: 20, mode: 'currency', currency: 'USD', allowEmpty: true });

await wrapper.vm.onInputKeyDown({ code: 'Backspace', metaKey: true, target: { value: 100 }, preventDefault: () => {} });

expect(wrapper.find('input.p-inputnumber-input').element._value).toBe(undefined);
});

it('should reset value to 0 when meta+backspace is pressed without allow-empty', async () => {
await wrapper.setProps({ modelValue: 20, mode: 'currency', currency: 'USD', allowEmpty: false });

await wrapper.vm.onInputKeyDown({ code: 'Backspace', metaKey: true, target: { value: 100 }, preventDefault: () => {} });

expect(wrapper.find('input.p-inputnumber-input').element._value).toBe('$0.00');
});

it('should have prefix', async () => {
await wrapper.setProps({ modelValue: 20, prefix: '%' });

Expand Down
11 changes: 10 additions & 1 deletion packages/primevue/src/inputnumber/InputNumber.vue
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,17 @@ export default {
return;
}

const code = event.code || event.key;

if (event.altKey || event.ctrlKey || event.metaKey) {
if (event.metaKey && code === 'Backspace') {
this.lastValue = this.allowEmpty ? null : '0';

this.updateModel(event, this.lastValue);

return;
}

this.isSpecialChar = true;
this.lastValue = this.$refs.input.$el.value;

Expand All @@ -436,7 +446,6 @@ export default {
let selectionRange = selectionEnd - selectionStart;
let inputValue = event.target.value;
let newValueStr = null;
const code = event.code || event.key;

switch (code) {
case 'ArrowUp':
Expand Down