Skip to content

Commit

Permalink
fix(modal): [modal] after the window size is changed, the window is d…
Browse files Browse the repository at this point in the history
…isplayed in the center (#2033)

* fix(modal): [modal]dragging the modal box,will be displayed in the center

* fix: modify review code

* fix(modal): modify review code

* fix: modify renderless of version
  • Loading branch information
James-9696 authored Sep 4, 2024
1 parent 9350f7a commit 49171e2
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="content">
<tiny-button @click="visible = !visible" :reset-time="0">自定义底部</tiny-button>
<tiny-modal v-model="visible" show-footer>
<tiny-modal v-model="visible" footer-dragable show-footer>
<template #footer>
<tiny-button>自定义底部信息</tiny-button>
</template>
Expand Down
2 changes: 1 addition & 1 deletion examples/sites/demos/pc/app/modal/footer-slot.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="content">
<tiny-button @click="visible = !visible" :reset-time="0">自定义底部</tiny-button>
<tiny-modal v-model="visible" show-footer>
<tiny-modal v-model="visible" footer-dragable show-footer>
<template #footer>
<tiny-button>自定义底部信息</tiny-button>
</template>
Expand Down
4 changes: 2 additions & 2 deletions packages/renderless/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentiny/vue-renderless",
"version": "3.18.1",
"version": "3.18.2",
"private": true,
"description": "An enterprise-class UI component library, support both Vue.js 2 and Vue.js 3, as well as PC and mobile.",
"author": "OpenTiny Team",
Expand Down Expand Up @@ -43,4 +43,4 @@
"esno": "^4.7.0",
"tsup": "7.2.0"
}
}
}
11 changes: 10 additions & 1 deletion packages/renderless/src/modal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export const beforeUnmouted =
isMobileFirstMode && off(window, 'resize', api.resetDragStyle)
off(document, 'keydown', api.handleGlobalKeydownEvent)
off(window, 'hashchange', api.handleHashChange)
off(window, 'resize', api.resetModalViewPosition)
api.removeMsgQueue()
api.hideScrollbar()

Expand Down Expand Up @@ -294,13 +295,13 @@ export const open =
} else {
modalBoxElem.style.left = `${clientVisibleWidth / 2 - modalBoxElem.offsetWidth / 2}px`
}

if (
modalBoxElem.offsetHeight + modalBoxElem.offsetTop + (props.marginSize as number) >
clientVisibleHeight
) {
modalBoxElem.style.top = `${props.marginSize}px`
}
on(window, 'resize', api.resetModalViewPosition)
}

if (props.fullscreen) {
Expand Down Expand Up @@ -919,3 +920,11 @@ export const showScrollbar = (lockScrollClass) => () => {
export const hideScrollbar = (lockScrollClass) => () => {
removeClass(document.body, lockScrollClass)
}

export const resetModalViewPosition = (api: IModalApi) => () => {
const modalBoxElement = api.getBox()
const viewportWindow = getViewportWindow()
const clientVisibleWidth =
viewportWindow.document.documentElement.clientWidth || viewportWindow.document.body.clientWidth
modalBoxElement.style.left = `${clientVisibleWidth / 2 - modalBoxElement.offsetWidth / 2}px`
}
5 changes: 4 additions & 1 deletion packages/renderless/src/modal/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
cancelEvent,
open,
resetDragStyle,
resetModalViewPosition,
computedBoxStyle,
handleHashChange,
showScrollbar,
Expand Down Expand Up @@ -64,7 +65,8 @@ export const api = [
'cancelEvent',
'open',
'beforeUnmouted',
'resetDragStyle'
'resetDragStyle',
'resetModalViewPosition'
]

export const renderless = (
Expand Down Expand Up @@ -120,6 +122,7 @@ export const renderless = (
mousedownEvent: mousedownEvent({ api, nextTick, props, state, emit, isMobileFirstMode }),
dragEvent: dragEvent({ api, emit, parent, props, state }),
resetDragStyle: resetDragStyle(api),
resetModalViewPosition: resetModalViewPosition(api),
computedBoxStyle: computedBoxStyle({ props, isMobileFirstMode }),
watchVisible: watchVisible({ api, props }),
hideScrollbar: hideScrollbar(lockScrollClass),
Expand Down
1 change: 1 addition & 0 deletions packages/renderless/types/modal.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface IModalApi {
mousedownEvent: (event: MouseEvent) => void
dragEvent: (event: MouseEvent) => void
resetDragStyle: () => void
resetModalViewPosition: () => void
}

export type IModalRenderlessParamUtils = ISharedRenderlessParamUtils<IModalConstants>
Expand Down

0 comments on commit 49171e2

Please sign in to comment.