Skip to content

Commit cd96d25

Browse files
author
xuqingkai
committed
fix: 🐛 修复checkbox-group的shape无法作用到子组件的问题
Closes: #519
1 parent 3def17e commit cd96d25

File tree

2 files changed

+23
-43
lines changed

2 files changed

+23
-43
lines changed

src/uni_modules/wot-design-uni/components/wd-checkbox/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export const checkboxProps = {
1818
/**
1919
* 单选框形状,可选值:circle / square / button
2020
*/
21-
shape: makeStringProp<CheckShape>('circle'),
21+
shape: {
22+
type: String as PropType<CheckShape>
23+
},
2224
/**
2325
* 选中的颜色
2426
*/

src/uni_modules/wot-design-uni/components/wd-checkbox/wd-checkbox.vue

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default {
4646
import { computed, getCurrentInstance, onBeforeMount, watch } from 'vue'
4747
import { useParent } from '../composables/useParent'
4848
import { CHECKBOX_GROUP_KEY } from '../wd-checkbox-group/types'
49-
import { isDef } from '../common/util'
49+
import { getPropByPath, isDef } from '../common/util'
5050
import { checkboxProps, type CheckboxExpose } from './types'
5151
5252
const props = defineProps(checkboxProps)
@@ -90,67 +90,45 @@ watch(
9090
() => props.shape,
9191
(newValue) => {
9292
const type = ['circle', 'square', 'button']
93-
if (type.indexOf(newValue) === -1) console.error(`shape must be one of ${type.toString()}`)
93+
if (isDef(newValue) && type.indexOf(newValue) === -1) console.error(`shape must be one of ${type.toString()}`)
9494
}
9595
)
9696
9797
const innerShape = computed(() => {
98-
if (!props.shape && checkboxGroup && checkboxGroup.props.shape) {
99-
return checkboxGroup.props.shape
100-
} else {
101-
return props.shape
102-
}
98+
return props.shape || getPropByPath(checkboxGroup, 'props.shape') || 'circle'
10399
})
104100
105101
const innerCheckedColor = computed(() => {
106-
if (!props.checkedColor && checkboxGroup && checkboxGroup.props.checkedColor) {
107-
return checkboxGroup.props.checkedColor
108-
} else {
109-
return props.checkedColor
110-
}
102+
return props.checkedColor || getPropByPath(checkboxGroup, 'props.checkedColor')
111103
})
112104
113105
const innerDisabled = computed(() => {
114-
let innerDisabled = props.disabled
115-
if (checkboxGroup) {
116-
if (
117-
// max 生效时,group 已经选满,禁止其它节点再选中。
118-
(checkboxGroup.props.max && checkboxGroup.props.modelValue.length >= checkboxGroup.props.max && !isChecked.value) ||
119-
// min 生效时,group 选中的节点数量仅满足最小值,禁止取消已选中的节点。
120-
(checkboxGroup.props.min && checkboxGroup.props.modelValue.length <= checkboxGroup.props.min && isChecked.value) ||
121-
// 只要子节点自己要求 disabled,那就 disabled。
122-
props.disabled === true ||
123-
// 父节点要求全局 disabled,子节点没吱声,那就 disabled。
124-
(checkboxGroup.props.disabled && props.disabled === null)
125-
) {
126-
innerDisabled = true
127-
}
106+
if (!checkboxGroup) {
107+
return props.disabled
108+
}
109+
const { max, min, modelValue, disabled } = checkboxGroup.props
110+
if (
111+
(max && modelValue.length >= max && !isChecked.value) ||
112+
(min && modelValue.length <= min && isChecked.value) ||
113+
props.disabled === true ||
114+
(disabled && props.disabled === null)
115+
) {
116+
return true
128117
}
129-
return innerDisabled
118+
119+
return props.disabled
130120
})
131121
132122
const innerInline = computed(() => {
133-
if (checkboxGroup && checkboxGroup.props.inline) {
134-
return checkboxGroup.props.inline
135-
} else {
136-
return false
137-
}
123+
return getPropByPath(checkboxGroup, 'props.inline') || false
138124
})
139125
140126
const innerCell = computed(() => {
141-
if (checkboxGroup && checkboxGroup.props.cell) {
142-
return checkboxGroup.props.cell
143-
} else {
144-
return false
145-
}
127+
return getPropByPath(checkboxGroup, 'props.cell') || false
146128
})
147129
148130
const innerSize = computed(() => {
149-
if (!props.size && checkboxGroup && checkboxGroup.props.size) {
150-
return checkboxGroup.props.size
151-
} else {
152-
return props.size
153-
}
131+
return props.size || getPropByPath(checkboxGroup, 'props.size')
154132
})
155133
156134
onBeforeMount(() => {

0 commit comments

Comments
 (0)