Skip to content

Commit 49171e2

Browse files
authored
fix(modal): [modal] after the window size is changed, the window is displayed 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
1 parent 9350f7a commit 49171e2

File tree

6 files changed

+19
-6
lines changed

6 files changed

+19
-6
lines changed

examples/sites/demos/pc/app/modal/footer-slot-composition-api.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="content">
33
<tiny-button @click="visible = !visible" :reset-time="0">自定义底部</tiny-button>
4-
<tiny-modal v-model="visible" show-footer>
4+
<tiny-modal v-model="visible" footer-dragable show-footer>
55
<template #footer>
66
<tiny-button>自定义底部信息</tiny-button>
77
</template>

examples/sites/demos/pc/app/modal/footer-slot.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="content">
33
<tiny-button @click="visible = !visible" :reset-time="0">自定义底部</tiny-button>
4-
<tiny-modal v-model="visible" show-footer>
4+
<tiny-modal v-model="visible" footer-dragable show-footer>
55
<template #footer>
66
<tiny-button>自定义底部信息</tiny-button>
77
</template>

packages/renderless/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opentiny/vue-renderless",
3-
"version": "3.18.1",
3+
"version": "3.18.2",
44
"private": true,
55
"description": "An enterprise-class UI component library, support both Vue.js 2 and Vue.js 3, as well as PC and mobile.",
66
"author": "OpenTiny Team",
@@ -43,4 +43,4 @@
4343
"esno": "^4.7.0",
4444
"tsup": "7.2.0"
4545
}
46-
}
46+
}

packages/renderless/src/modal/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export const beforeUnmouted =
140140
isMobileFirstMode && off(window, 'resize', api.resetDragStyle)
141141
off(document, 'keydown', api.handleGlobalKeydownEvent)
142142
off(window, 'hashchange', api.handleHashChange)
143+
off(window, 'resize', api.resetModalViewPosition)
143144
api.removeMsgQueue()
144145
api.hideScrollbar()
145146

@@ -294,13 +295,13 @@ export const open =
294295
} else {
295296
modalBoxElem.style.left = `${clientVisibleWidth / 2 - modalBoxElem.offsetWidth / 2}px`
296297
}
297-
298298
if (
299299
modalBoxElem.offsetHeight + modalBoxElem.offsetTop + (props.marginSize as number) >
300300
clientVisibleHeight
301301
) {
302302
modalBoxElem.style.top = `${props.marginSize}px`
303303
}
304+
on(window, 'resize', api.resetModalViewPosition)
304305
}
305306

306307
if (props.fullscreen) {
@@ -919,3 +920,11 @@ export const showScrollbar = (lockScrollClass) => () => {
919920
export const hideScrollbar = (lockScrollClass) => () => {
920921
removeClass(document.body, lockScrollClass)
921922
}
923+
924+
export const resetModalViewPosition = (api: IModalApi) => () => {
925+
const modalBoxElement = api.getBox()
926+
const viewportWindow = getViewportWindow()
927+
const clientVisibleWidth =
928+
viewportWindow.document.documentElement.clientWidth || viewportWindow.document.body.clientWidth
929+
modalBoxElement.style.left = `${clientVisibleWidth / 2 - modalBoxElement.offsetWidth / 2}px`
930+
}

packages/renderless/src/modal/vue.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
cancelEvent,
3838
open,
3939
resetDragStyle,
40+
resetModalViewPosition,
4041
computedBoxStyle,
4142
handleHashChange,
4243
showScrollbar,
@@ -64,7 +65,8 @@ export const api = [
6465
'cancelEvent',
6566
'open',
6667
'beforeUnmouted',
67-
'resetDragStyle'
68+
'resetDragStyle',
69+
'resetModalViewPosition'
6870
]
6971

7072
export const renderless = (
@@ -120,6 +122,7 @@ export const renderless = (
120122
mousedownEvent: mousedownEvent({ api, nextTick, props, state, emit, isMobileFirstMode }),
121123
dragEvent: dragEvent({ api, emit, parent, props, state }),
122124
resetDragStyle: resetDragStyle(api),
125+
resetModalViewPosition: resetModalViewPosition(api),
123126
computedBoxStyle: computedBoxStyle({ props, isMobileFirstMode }),
124127
watchVisible: watchVisible({ api, props }),
125128
hideScrollbar: hideScrollbar(lockScrollClass),

packages/renderless/types/modal.type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export interface IModalApi {
6363
mousedownEvent: (event: MouseEvent) => void
6464
dragEvent: (event: MouseEvent) => void
6565
resetDragStyle: () => void
66+
resetModalViewPosition: () => void
6667
}
6768

6869
export type IModalRenderlessParamUtils = ISharedRenderlessParamUtils<IModalConstants>

0 commit comments

Comments
 (0)