Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(web): 修复 uni.showActionSheet 的参数 popover.width 设置无效的问题 (question/189745) #4849

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions packages/uni-h5/src/helpers/usePopupStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type popupStyleType = {
left: string
top: string
bottom: string
width?: string
}
triangle: {
'border-width': string
Expand All @@ -24,7 +25,7 @@ export type popupStyleType = {
}
}

export function usePopupStyle(props: Data) {
export function usePopupStyle(props: Data, dynamicWidth = false) {
const popupWidth = ref(0)
const popupHeight = ref(0)

Expand Down Expand Up @@ -62,15 +63,22 @@ export function usePopupStyle(props: Data) {
'border-style': 'solid',
})
const popoverLeft = getNumber(popover.left)
const popoverWidth = getNumber(popover.width)
const defaultWidth = 300
const popoverWidth = getNumber(
popover.width ? popover.width : defaultWidth
)
const popoverTop = getNumber(popover.top)
const popoverHeight = getNumber(popover.height)
const layerWidth = dynamicWidth ? popoverWidth : defaultWidth
const center = popoverLeft + popoverWidth / 2
contentStyle.transform = 'none !important'
const contentLeft = Math.max(0, center - 300 / 2)
const contentLeft = Math.max(0, center - layerWidth / 2)
contentStyle.left = `${contentLeft}px`
if (dynamicWidth) {
contentStyle.width = `${layerWidth}px`
}
let triangleLeft = Math.max(12, center - contentLeft)
triangleLeft = Math.min(300 - 12, triangleLeft)
triangleLeft = Math.min(layerWidth - 12, triangleLeft)
triangleStyle.left = `${triangleLeft}px`
const vcl = popupHeight.value / 2
if (popoverTop + popoverHeight - vcl > vcl - popoverTop) {
Expand Down
2 changes: 1 addition & 1 deletion packages/uni-h5/src/service/api/ui/popup/actionSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default /*#__PURE__*/ defineComponent({
const main: Ref<HTMLElement | null> = ref(null)
const { t } = useI18n()
const { _close } = useActionSheetLoader(props, emit as SetupContext['emit'])
const { popupStyle } = usePopupStyle(props)
const { popupStyle } = usePopupStyle(props, true)

let scroller: Scroller

Expand Down
Loading