From b1bfae01f2b672dba8c7c335711d9351a465d7ec Mon Sep 17 00:00:00 2001 From: Maksim Nedoshev Date: Fri, 7 Jul 2023 13:59:38 +0300 Subject: [PATCH] fix(#3577): introduce useTeleported composable (#3578) * fix(#3577): introduce useTeleported composable * chore(docs): update modal demo * fix(time-input): open on click * chore(docs): change button in example to primary * fix(dropdown): close on keyboard only focus outside --- .../modal/examples/NestedModals.vue | 21 ++++++- .../src/components/va-dropdown/VaDropdown.vue | 6 +- .../src/components/va-modal/VaModal.demo.vue | 14 ++++- .../ui/src/components/va-modal/VaModal.vue | 6 +- .../components/va-time-input/VaTimeInput.vue | 1 + packages/ui/src/composables/index.ts | 1 + .../ui/src/composables/useClickOutside.ts | 18 ++++-- .../ui/src/composables/useFocusOutside.ts | 63 ++++++++++++++----- packages/ui/src/composables/useTeleported.ts | 37 +++++++++++ 9 files changed, 139 insertions(+), 28 deletions(-) create mode 100644 packages/ui/src/composables/useTeleported.ts diff --git a/packages/docs/page-config/ui-elements/modal/examples/NestedModals.vue b/packages/docs/page-config/ui-elements/modal/examples/NestedModals.vue index ee00b355ed..b29d2a23f9 100644 --- a/packages/docs/page-config/ui-elements/modal/examples/NestedModals.vue +++ b/packages/docs/page-config/ui-elements/modal/examples/NestedModals.vue @@ -13,22 +13,27 @@ Nested Modal - +

This example shows how overlapping modals work after you click save.

-
+
Cancel + + Set default + @@ -51,7 +56,17 @@ export default { return { showFirstModal: false, showSecondModal: false, + date: new Date(), }; }, + methods: { + setDefault() { + this.date = new Date(); + this.$vaToast.init({ + message: 'Date was set to default', + color: '#222222', + }) + } + } }; diff --git a/packages/ui/src/components/va-dropdown/VaDropdown.vue b/packages/ui/src/components/va-dropdown/VaDropdown.vue index 7bd73eb60e..8c6a52a866 100644 --- a/packages/ui/src/components/va-dropdown/VaDropdown.vue +++ b/packages/ui/src/components/va-dropdown/VaDropdown.vue @@ -34,6 +34,7 @@ import { DropdownOffsetProp } from './types' import { useDropdown } from './hooks/useDropdown' import { warn } from '../../utils/console' import { useFocusOutside } from '../../composables/useFocusOutside' +import { useTeleported } from '../../composables/useTeleported' export default defineComponent({ name: 'VaDropdown', @@ -194,7 +195,7 @@ export default defineComponent({ if (props.closeOnFocusOutside && valueComputed.value) { emitAndClose('focus-outside', props.closeOnFocusOutside) } - }) + }, { onlyKeyboard: true }) const anchorComputed = computed(() => { return cursorAnchor.value || anchor.value @@ -219,6 +220,7 @@ export default defineComponent({ return { ...useTranslation(), + ...useTeleported(), anchor, anchorClass, floating, @@ -239,6 +241,7 @@ export default defineComponent({ ref: 'floating', class: 'va-dropdown__content-wrapper', style: this.floatingStyles, + ...this.teleportedAttrs, ...this.floatingListeners, }) @@ -250,6 +253,7 @@ export default defineComponent({ 'aria-label': this.tp(this.$props.ariaLabel), 'aria-disabled': this.$props.disabled, 'aria-expanded': !!this.showFloating, + ...this.teleportFromAttrs, ...this.$attrs, }) diff --git a/packages/ui/src/components/va-modal/VaModal.demo.vue b/packages/ui/src/components/va-modal/VaModal.demo.vue index a66eee1bbf..e9a7afcd33 100644 --- a/packages/ui/src/components/va-modal/VaModal.demo.vue +++ b/packages/ui/src/components/va-modal/VaModal.demo.vue @@ -364,6 +364,15 @@ + + + + + + + @@ -373,9 +382,10 @@ import { VaButton } from '../va-button' import { VaCollapse } from '../va-collapse' import { VaInput } from '../va-input' import { VaDatePicker } from '../va-date-picker' +import { VaDateInput } from '../va-date-input' export default { - components: { VaModal, VaButton, VaCollapse, VaInput, VaDatePicker }, + components: { VaModal, VaButton, VaCollapse, VaInput, VaDatePicker, VaDateInput }, data () { return { showModalSizeSmall: false, @@ -411,6 +421,8 @@ export default { showModalFocusTrap1: false, showModalFocusTrap2: false, showBeforeHideModal: false, + showModalCloseOutside: false, + c: false, message: this.$vb.lorem(), longMessage: this.$vb.lorem(5000), collapseValue: false, diff --git a/packages/ui/src/components/va-modal/VaModal.vue b/packages/ui/src/components/va-modal/VaModal.vue index 42c673eb61..eedeccf6ae 100644 --- a/packages/ui/src/components/va-modal/VaModal.vue +++ b/packages/ui/src/components/va-modal/VaModal.vue @@ -7,7 +7,7 @@ :aria-labelledby="title" :class="$props.anchorClass" > -
+
@@ -17,7 +17,7 @@ :isTransition="!$props.withoutTransitions" appear :duration="300" - v-bind="$attrs" + v-bind="{ ...$attrs, ...teleportedAttrs }" @beforeEnter="onBeforeEnterTransition" @afterEnter="onAfterEnterTransition" @beforeLeave="onBeforeLeaveTransition" @@ -140,6 +140,7 @@ import { useTranslation, useClickOutside, useDocument, + useTeleported, } from '../../composables' import { VaButton } from '../va-button' @@ -357,6 +358,7 @@ export default defineComponent({ computedOverlayStyles, slotBind: { show, hide, toggle, cancel, ok }, ...publicMethods, + ...useTeleported(), } }, }) diff --git a/packages/ui/src/components/va-time-input/VaTimeInput.vue b/packages/ui/src/components/va-time-input/VaTimeInput.vue index d049a84e26..800e68eb7c 100644 --- a/packages/ui/src/components/va-time-input/VaTimeInput.vue +++ b/packages/ui/src/components/va-time-input/VaTimeInput.vue @@ -11,6 +11,7 @@ class="va-time-input__anchor" :style="cursorStyleComputed" v-bind="computedInputWrapperProps" + @click.stop="toggleDropdown" >