feat(Dropdown): add clear input key binding (#4002)

pull/4295/head
Paul Thiel 2023-08-18 03:44:28 +02:00 committed by GitHub
parent 7529764482
commit dd74bcd821
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -89,6 +89,14 @@ describe('clear checks', () => {
it('should have correct icon', () => { it('should have correct icon', () => {
expect(wrapper.find('.p-dropdown-clear-icon').classes()).toContain('pi-discord'); expect(wrapper.find('.p-dropdown-clear-icon').classes()).toContain('pi-discord');
}); });
it('should clear with delete key', async () => {
const updateModelSpy = vi.spyOn(wrapper.vm, 'updateModel');
await wrapper.find('.p-dropdown-label.p-inputtext').trigger('keydown', { code: 'Delete' });
expect(updateModelSpy).toHaveBeenCalledOnce();
expect(updateModelSpy).toHaveBeenCalledWith(expect.any(KeyboardEvent), null);
});
}); });
describe('editable checks', () => { describe('editable checks', () => {

View File

@ -339,6 +339,9 @@ export default {
this.onArrowLeftKey(event, this.editable); this.onArrowLeftKey(event, this.editable);
break; break;
case 'Delete':
this.onDeleteKey(event);
case 'Home': case 'Home':
this.onHomeKey(event, this.editable); this.onHomeKey(event, this.editable);
break; break;
@ -507,6 +510,12 @@ export default {
break; break;
} }
}, },
onDeleteKey(event) {
if (this.showClear) {
this.updateModel(event, null);
event.preventDefault();
}
},
onArrowDownKey(event) { onArrowDownKey(event) {
const optionIndex = this.focusedOptionIndex !== -1 ? this.findNextOptionIndex(this.focusedOptionIndex) : this.findFirstFocusedOptionIndex(); const optionIndex = this.focusedOptionIndex !== -1 ? this.findNextOptionIndex(this.focusedOptionIndex) : this.findFirstFocusedOptionIndex();