From e1e5fa902ba72f69a2f575c70068fc1d3f3b3f2f Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Thu, 16 Nov 2023 12:32:41 +0100 Subject: [PATCH] refactor(Dropdown): move item `click` logic to a proper function --- src/runtime/components/elements/Dropdown.vue | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/runtime/components/elements/Dropdown.vue b/src/runtime/components/elements/Dropdown.vue index 39e07230e1..5a65960962 100644 --- a/src/runtime/components/elements/Dropdown.vue +++ b/src/runtime/components/elements/Dropdown.vue @@ -29,7 +29,7 @@ :rel="rel" :target="target" :class="[ui.item.base, ui.item.padding, ui.item.size, ui.item.rounded, active ? ui.item.active : ui.item.inactive, itemDisabled && ui.item.disabled]" - @click="(e) => [!!item.click && item.click(e), !!href && !isExternal && navigate(e), close()]" + @click="onClick($event, item, { href, navigate, close, isExternal })" > @@ -187,6 +187,18 @@ export default defineComponent({ }, props.closeDelay) } + function onClick (e, item, { href, navigate, close, isExternal }) { + if (item.click) { + item.click(e) + } + + if (href && !isExternal) { + navigate(e) + + close() + } + } + const NuxtLink = resolveComponent('NuxtLink') return { @@ -200,6 +212,7 @@ export default defineComponent({ containerStyle, onMouseOver, onMouseLeave, + onClick, omit, NuxtLink }