diff --git a/components/lib/contextmenu/ContextMenu.vue b/components/lib/contextmenu/ContextMenu.vue index 4c7b87a2b..94cc02ca9 100755 --- a/components/lib/contextmenu/ContextMenu.vue +++ b/components/lib/contextmenu/ContextMenu.vue @@ -44,7 +44,7 @@ export default { name: 'ContextMenu', extends: BaseContextMenu, inheritAttrs: false, - emits: ['focus', 'blur', 'show', 'hide'], + emits: ['focus', 'blur', 'show', 'hide', 'before-show', 'before-hide'], target: null, outsideClickListener: null, resizeListener: null, @@ -125,6 +125,7 @@ export default { this.visible ? this.hide() : this.show(event); }, show(event) { + this.$emit('before-show'); this.activeItemPath = []; this.focusedItemInfo = { index: -1, level: 0, parentKey: '' }; DomHandler.focus(this.list); @@ -137,6 +138,7 @@ export default { event.preventDefault(); }, hide() { + this.$emit('before-hide'); this.visible = false; this.activeItemPath = []; this.focusedItemInfo = { index: -1, level: 0, parentKey: '' }; diff --git a/components/lib/listbox/Listbox.vue b/components/lib/listbox/Listbox.vue index c46f52804..bd76745a9 100755 --- a/components/lib/listbox/Listbox.vue +++ b/components/lib/listbox/Listbox.vue @@ -477,8 +477,14 @@ export default { }, onHomeKey(event, pressedInInputText = false) { if (pressedInInputText) { - event.currentTarget.setSelectionRange(0, 0); - this.focusedOptionIndex = -1; + const target = event.currentTarget; + + if (event.shiftKey) { + target.setSelectionRange(0, event.target.selectionStart); + } else { + target.setSelectionRange(0, 0); + this.focusedOptionIndex = -1; + } } else { let metaKey = event.metaKey || event.ctrlKey; let optionIndex = this.findFirstOptionIndex(); @@ -495,10 +501,15 @@ export default { onEndKey(event, pressedInInputText = false) { if (pressedInInputText) { const target = event.currentTarget; - const len = target.value.length; - target.setSelectionRange(len, len); - this.focusedOptionIndex = -1; + if (event.shiftKey) { + target.setSelectionRange(event.target.selectionStart, target.value.length); + } else { + const len = target.value.length; + + target.setSelectionRange(len, len); + this.focusedOptionIndex = -1; + } } else { let metaKey = event.metaKey || event.ctrlKey; let optionIndex = this.findLastOptionIndex(); diff --git a/components/lib/multiselect/MultiSelect.vue b/components/lib/multiselect/MultiSelect.vue index 8e75632e6..22205de46 100755 --- a/components/lib/multiselect/MultiSelect.vue +++ b/components/lib/multiselect/MultiSelect.vue @@ -610,13 +610,15 @@ export default { pressedInInputText && (this.focusedOptionIndex = -1); }, onHomeKey(event, pressedInInputText = false) { - const { currentTarget } = event; - if (pressedInInputText) { - const len = currentTarget.value.length; + const target = event.currentTarget; - currentTarget.setSelectionRange(0, event.shiftKey ? len : 0); - this.focusedOptionIndex = -1; + if (event.shiftKey) { + target.setSelectionRange(0, event.target.selectionStart); + } else { + target.setSelectionRange(0, 0); + this.focusedOptionIndex = -1; + } } else { let metaKey = event.metaKey || event.ctrlKey; let optionIndex = this.findFirstOptionIndex(); @@ -633,13 +635,17 @@ export default { event.preventDefault(); }, onEndKey(event, pressedInInputText = false) { - const { currentTarget } = event; - if (pressedInInputText) { - const len = currentTarget.value.length; + const target = event.currentTarget; - currentTarget.setSelectionRange(event.shiftKey ? 0 : len, len); - this.focusedOptionIndex = -1; + if (event.shiftKey) { + target.setSelectionRange(event.target.selectionStart, target.value.length); + } else { + const len = target.value.length; + + target.setSelectionRange(len, len); + this.focusedOptionIndex = -1; + } } else { let metaKey = event.metaKey || event.ctrlKey; let optionIndex = this.findLastOptionIndex(); diff --git a/components/lib/select/Select.spec.js b/components/lib/select/Select.spec.js index d866c75d7..8998c1047 100644 --- a/components/lib/select/Select.spec.js +++ b/components/lib/select/Select.spec.js @@ -90,15 +90,6 @@ describe('clear checks', () => { expect(wrapper.find('.p-select-clear-icon').classes()).toContain('pi-discord'); }); - it('should clear with delete key', async () => { - const updateModelSpy = vi.spyOn(wrapper.vm, 'updateModel'); - - await wrapper.find('.p-select-label.p-inputtext').trigger('keydown', { code: 'Delete' }); - expect(updateModelSpy).toHaveBeenCalledOnce(); - expect(updateModelSpy).toHaveBeenCalledWith(expect.any(KeyboardEvent), null); - }); -}); - describe('editable checks', () => { let wrapper; diff --git a/components/lib/select/Select.vue b/components/lib/select/Select.vue index dc46087db..51b7240dd 100755 --- a/components/lib/select/Select.vue +++ b/components/lib/select/Select.vue @@ -376,9 +376,6 @@ export default { this.onArrowLeftKey(event, this.editable); break; - case 'Delete': - this.onDeleteKey(event); - case 'Home': this.onHomeKey(event, this.editable); break; @@ -555,12 +552,6 @@ export default { break; } }, - onDeleteKey(event) { - if (this.showClear) { - this.updateModel(event, null); - event.preventDefault(); - } - }, onArrowDownKey(event) { if (!this.overlayVisible) { this.show(); @@ -595,8 +586,14 @@ export default { }, onHomeKey(event, pressedInInputText = false) { if (pressedInInputText) { - event.currentTarget.setSelectionRange(0, 0); - this.focusedOptionIndex = -1; + const target = event.currentTarget; + + if (event.shiftKey) { + target.setSelectionRange(0, event.target.selectionStart); + } else { + target.setSelectionRange(0, 0); + this.focusedOptionIndex = -1; + } } else { this.changeFocusedOptionIndex(event, this.findFirstOptionIndex()); @@ -608,10 +605,15 @@ export default { onEndKey(event, pressedInInputText = false) { if (pressedInInputText) { const target = event.currentTarget; - const len = target.value.length; - target.setSelectionRange(len, len); - this.focusedOptionIndex = -1; + if (event.shiftKey) { + target.setSelectionRange(event.target.selectionStart, target.value.length); + } else { + const len = target.value.length; + + target.setSelectionRange(len, len); + this.focusedOptionIndex = -1; + } } else { this.changeFocusedOptionIndex(event, this.findLastOptionIndex());