From 017eb705d35c71aab3182d97cfec8ceec7050d8a Mon Sep 17 00:00:00 2001 From: Aex Date: Wed, 1 Sep 2021 17:38:54 +0800 Subject: [PATCH] fix(utils): improve element.addEventListener (#3173) --- packages/components/dropdown/src/dropdown.vue | 5 ++--- packages/utils/dom.ts | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/components/dropdown/src/dropdown.vue b/packages/components/dropdown/src/dropdown.vue index 28804c7d97..889e4c7198 100644 --- a/packages/components/dropdown/src/dropdown.vue +++ b/packages/components/dropdown/src/dropdown.vue @@ -159,9 +159,8 @@ export default defineComponent({ const triggerVnode = ref>(null) const triggerElm = computed>(() => { - const _: any = - (triggerVnode.value?.$refs.triggerRef as HTMLElement)?.children[0] ?? {} - return !props.splitButton ? _ : _.children?.[1] + const _: any = (triggerVnode.value?.$refs.triggerRef as HTMLElement)?.children[0] + return !props.splitButton ? _ : _?.children?.[1] }) function handleClick() { diff --git a/packages/utils/dom.ts b/packages/utils/dom.ts index 0cc9f9a1c1..77cb61a527 100644 --- a/packages/utils/dom.ts +++ b/packages/utils/dom.ts @@ -17,7 +17,7 @@ export const on = function( useCapture = false, ): void { if (element && event && handler) { - element.addEventListener(event, handler, useCapture) + element?.addEventListener(event, handler, useCapture) } } @@ -29,7 +29,7 @@ export const off = function( useCapture = false, ): void { if (element && event && handler) { - element.removeEventListener(event, handler, useCapture) + element?.removeEventListener(event, handler, useCapture) } }