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: 🐛 修复直接使用title插槽不设置closeText时不显示title插槽内容,新增radius属性,header插槽 #760

Open
wants to merge 4 commits into
base: master
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
1 change: 1 addition & 0 deletions docs/component/number-keyboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ const onDelete = () => showToast('删除')
| name | 说明 | 类型 | 最低版本 |
| ----- | ---- | ---- | -------- |
| title | 标题 | - | 1.2.12 |
| header | 顶部 | - | |

## Events

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { PropType } from 'vue'
import { baseProps, makeBooleanProp, makeNumberProp, makeStringProp } from '../common/props'
import { baseProps, makeBooleanProp, makeNumberProp, makeStringProp, numericProp } from '../common/props'

export type KeyboardMode = 'default' | 'custom'
export type KeyType = '' | 'delete' | 'extra' | 'close'
Expand Down Expand Up @@ -75,5 +75,9 @@ export const numberKeyboardProps = {
/**
* 额外按键
*/
extraKey: [String, Array] as PropType<string | Array<string>>
extraKey: [String, Array] as PropType<string | Array<string>>,
/**
* 背景圆角大小,默认单位为px
*/
radius: numericProp
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
:z-index="zIndex"
:safe-area-inset-bottom="safeAreaInsetBottom"
:modal-style="modal ? '' : 'opacity: 0;'"
:custom-style="rootStyle"
:modal="hideOnClickOutside"
:lockScroll="lockScroll"
@click-modal="handleClose"
>
<view :class="`wd-number-keyboard ${customClass}`" :style="customStyle">
<slot name="header"></slot>
<view class="wd-number-keyboard__header" v-if="showTitle">
<slot name="title">
<text class="wd-number-keyboard__title">{{ title }}</text>
Expand Down Expand Up @@ -43,10 +45,11 @@ export default {

<script lang="ts" setup>
import wdPopup from '../wd-popup/wd-popup.vue'
import { computed, ref, watch } from 'vue'
import { computed, ref, watch, useSlots } from 'vue'
import WdKey from './key/index.vue'
import { numberKeyboardProps, type Key } from './types'
import type { NumberKeyType } from './key/types'
import { objToStyle, isDef, addUnit } from '../common/util'

const props = defineProps(numberKeyboardProps)
const emit = defineEmits(['update:visible', 'input', 'close', 'delete', 'update:modelValue'])
Expand All @@ -65,8 +68,18 @@ const showClose = computed(() => {
return props.closeText && props.mode === 'default'
})

const slots = useSlots()
const showTitle = computed(() => {
return props.title || showClose.value
return !!props.title || showClose.value || slots.title
})

const rootStyle = computed(() => {
const style: Record<string, string | number> = {}
if (isDef(props.radius)) {
style['border-radius'] = `${addUnit(props.radius)} ${addUnit(props.radius)} 0 0`
style['overflow'] = 'hidden'
}
return `${objToStyle(style)};`
})

/**
Expand Down