This commit is contained in:
oneao committed 2025-09-17 14:49:15 +08:00
1 parent 104e0a78c6
commit 4d0d2f875e
13 files changed
+802 -226

No files matched your search

@@ -74,7 +74,7 @@ $radio-group-prefix: '#{$prefix}-radio-group';
}
.#{$radio-prefix}-content {
font-size: 12px;
font-size: 14px;
margin-left: 8px;
display: inline-block;
flex-direction: column;
@@ -465,12 +465,12 @@ $radio-group-prefix: '#{$prefix}-radio-group';
}
.#{$radio-prefix}-content {
font-size: 12px;
margin-left: 8px;
display: inline-block;
flex-direction: column;
.#{$radio-prefix}-label {
font-size: 14px;
line-height: 16px;
display: flex;
align-items: center;
@@ -513,11 +513,11 @@ $radio-group-prefix: '#{$prefix}-radio-group';
}
.#{$radio-prefix}-content {
font-size: 12px;
display: inline-block;
flex-direction: column;
.#{$radio-prefix}-label {
font-size: 14px;
line-height: 16px;
display: flex;
align-items: center;
@@ -72,13 +72,15 @@ export default defineComponent({
_value.value = newVal ?? undefined
})
const groupDisabled = computed(() => props.disabled)
const groupType = computed(() => props.type)
const handleChange = (val: string | number | boolean | undefined, e: Event) => {
_value.value = val
emit('update:modelValue', val)
emit('change', val, e)
}
const groupDisabled = computed(() => props.disabled)
const groupType = computed(() => props.type)
// 提供 context 给 Radio 使用
provide(radioGroupKey, reactive({
name: 'AoRadioGroup' as const,
@@ -1,6 +1,6 @@
import type { PropType, VNode } from 'vue'
import type { RadioGroupContext } from './context'
import { computed, defineComponent, inject, ref } from 'vue'
import { computed, defineComponent, inject, ref, watch } from 'vue'
import { getPrefixCls } from '../_utils/getPrefixCls'
import { radioGroupKey } from './context'
@@ -11,6 +11,14 @@ export default defineComponent({
type: Boolean,
default: undefined,
},
checked: {
type: Boolean,
default: undefined,
},
value: {
type: [String, Number, Boolean] as PropType<string | number | boolean>,
default: undefined,
},
defaultChecked: {
type: Boolean,
default: false,
@@ -19,10 +27,6 @@ export default defineComponent({
type: Boolean,
default: false,
},
value: {
type: [String, Number, Boolean] as PropType<string | number | boolean>,
default: true,
},
allowUncheck: {
type: Boolean,
default: true,
@@ -36,7 +40,7 @@ export default defineComponent({
default: 'default',
},
},
emits: ['update:modelValue', 'change'],
emits: ['update:modelValue', 'update:checked', 'change'],
setup(props, { slots, emit }) {
const prefixCls = getPrefixCls('radio')
@@ -46,10 +50,14 @@ export default defineComponent({
const isDisabled = computed(() => props.disabled || radioGroupCtx?.disabled)
const _checked = ref(props.defaultChecked)
const mergedType = computed(() =>
props.type || radioGroupCtx?.type || 'default',
)
const isChecked = computed(() => {
if (inGroup.value)
return props.value === radioGroupCtx!.value
return props.modelValue ?? _checked.value
return props.checked ?? props.modelValue ?? _checked.value
})
const isAllowUncheck = computed(() => props.allowUncheck || radioGroupCtx?.allowUncheck)
@@ -66,12 +74,21 @@ export default defineComponent({
}
else {
const newValue = isAllowUncheck.value ? !isChecked.value : true
_checked.value = newValue
if (props.checked === undefined) {
_checked.value = newValue
}
emit('update:modelValue', newValue)
emit('change', props.value, e)
}
}
watch(() => props.checked, (val) => {
if (val !== undefined) {
_checked.value = val
}
})
const renderDefault = () => (
<label
class={[
@@ -211,7 +228,7 @@ export default defineComponent({
)
return () => {
switch (props.type) {
switch (mergedType.value) {
case 'filled':
return renderFilled()
case 'primaryFilled':