From 001e22a2628df869d3e6f57003e7d29b7e730974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tu=C4=9F=C3=A7e=20K=C3=BC=C3=A7=C3=BCko=C4=9Flu?= Date: Tue, 5 Sep 2023 11:03:25 +0300 Subject: [PATCH] Fixed #4383 - OrderList and PickList: Getting error when empty field --- components/lib/orderlist/OrderList.vue | 12 +++++++----- components/lib/picklist/PickList.vue | 13 ++++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/components/lib/orderlist/OrderList.vue b/components/lib/orderlist/OrderList.vue index dd412cbaf..a3681b703 100755 --- a/components/lib/orderlist/OrderList.vue +++ b/components/lib/orderlist/OrderList.vue @@ -141,14 +141,16 @@ export default { onListFocus(event) { const selectedFirstItem = DomHandler.findSingle(this.list, '[data-p-highlight="true"]'); - const findIndex = ObjectUtils.findIndexInList(selectedFirstItem, this.list.children); + if (selectedFirstItem) { + const findIndex = ObjectUtils.findIndexInList(selectedFirstItem, this.list.children); - this.focused = true; + this.focused = true; - const index = this.focusedOptionIndex !== -1 ? this.focusedOptionIndex : selectedFirstItem ? findIndex : -1; + const index = this.focusedOptionIndex !== -1 ? this.focusedOptionIndex : selectedFirstItem ? findIndex : -1; - this.changeFocusedOptionIndex(index); - this.$emit('focus', event); + this.changeFocusedOptionIndex(index); + this.$emit('focus', event); + } }, onListBlur(event) { this.focused = false; diff --git a/components/lib/picklist/PickList.vue b/components/lib/picklist/PickList.vue index 1d9143e8c..d44834f48 100755 --- a/components/lib/picklist/PickList.vue +++ b/components/lib/picklist/PickList.vue @@ -265,14 +265,17 @@ export default { }, onListFocus(event, listType) { const selectedFirstItem = DomHandler.findSingle(this.$refs[listType].$el, '[data-p-highlight="true"]'); - const findIndex = ObjectUtils.findIndexInList(selectedFirstItem, this.$refs[listType].$el.children); - this.focused[listType] = true; + if (selectedFirstItem) { + const findIndex = ObjectUtils.findIndexInList(selectedFirstItem, this.$refs[listType].$el.children); - const index = this.focusedOptionIndex !== -1 ? this.focusedOptionIndex : selectedFirstItem ? findIndex : -1; + this.focused[listType] = true; - this.changeFocusedOptionIndex(index, listType); - this.$emit('focus', event); + const index = this.focusedOptionIndex !== -1 ? this.focusedOptionIndex : selectedFirstItem ? findIndex : -1; + + this.changeFocusedOptionIndex(index, listType); + this.$emit('focus', event); + } }, onListBlur(event, listType) { this.focused[listType] = false;