Skip to content

Commit 93c2bc1

Browse files
committed
fix: support vue3.1
1 parent b45a625 commit 93c2bc1

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

components/auto-complete/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const AutoComplete = defineComponent({
4242
OptGroup: { ...OptGroup, name: 'AAutoCompleteOptGroup' },
4343
setup(props, { slots }) {
4444
warning(
45-
!('dataSource' in props || 'dataSource' in slots),
45+
!(props.dataSource !== undefined || 'dataSource' in slots),
4646
'AutoComplete',
4747
'`dataSource` is deprecated, please use `options` instead.',
4848
);

components/menu/src/Menu.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export default defineComponent({
123123
{ immediate: true },
124124
);
125125
watchEffect(() => {
126-
if ('activeKey' in props) {
126+
if (props.activeKey !== undefined) {
127127
let keys = [];
128128
const menuInfo = props.activeKey
129129
? (keyMapStore.value[props.activeKey] as UnwrapRef<StoreMenuInfo>)
@@ -194,7 +194,7 @@ export default defineComponent({
194194
selectedKeys: newSelectedKeys,
195195
};
196196
if (!shallowEqual(newSelectedKeys, mergedSelectedKeys.value)) {
197-
if (!('selectedKeys' in props)) {
197+
if (props.selectedKeys === undefined) {
198198
mergedSelectedKeys.value = newSelectedKeys;
199199
}
200200
emit('update:selectedKeys', newSelectedKeys);
@@ -223,11 +223,10 @@ export default defineComponent({
223223
);
224224

225225
const changeActiveKeys = (keys: Key[]) => {
226-
if ('activeKey' in props) {
227-
emit('update:activeKey', keys[keys.length - 1]);
228-
} else {
226+
if (props.activeKey === undefined) {
229227
activeKeys.value = keys;
230228
}
229+
emit('update:activeKey', keys[keys.length - 1]);
231230
};
232231
const disabled = computed(() => !!props.disabled);
233232
const isRtl = computed(() => direction.value === 'rtl');

components/switch/index.tsx

+12-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
computed,
88
onMounted,
99
nextTick,
10+
watch,
1011
} from 'vue';
1112
import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined';
1213
import PropTypes from '../_util/vue-types';
@@ -27,7 +28,6 @@ const switchProps = {
2728
checkedChildren: PropTypes.any,
2829
unCheckedChildren: PropTypes.any,
2930
tabindex: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
30-
defaultChecked: PropTypes.looseBool,
3131
autofocus: PropTypes.looseBool,
3232
loading: PropTypes.looseBool,
3333
checked: PropTypes.looseBool,
@@ -59,6 +59,14 @@ const Switch = defineComponent({
5959
'`value` is not validate prop, do you mean `checked`?',
6060
);
6161
});
62+
const checked = ref(props.checked !== undefined ? !!props.checked : !!attrs.defaultChecked);
63+
64+
watch(
65+
() => props.checked,
66+
() => {
67+
checked.value = !!props.checked;
68+
},
69+
);
6270

6371
const configProvider = inject('configProvider', defaultConfigProvider);
6472
const { getPrefixCls } = configProvider;
@@ -75,9 +83,6 @@ const Switch = defineComponent({
7583
const prefixCls = computed(() => {
7684
return getPrefixCls('switch', props.prefixCls);
7785
});
78-
const checked = computed(() => {
79-
return 'checked' in props ? !!props.checked : !!props.defaultChecked;
80-
});
8186

8287
onMounted(() => {
8388
nextTick(() => {
@@ -91,6 +96,9 @@ const Switch = defineComponent({
9196
if (props.disabled) {
9297
return;
9398
}
99+
if (props.checked === undefined) {
100+
checked.value = check;
101+
}
94102
emit('update:checked', check);
95103
emit('change', check, e);
96104
};

components/typography/Base.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ const Base = defineComponent<InternalBlockProps>({
155155
);
156156

157157
watchEffect(() => {
158-
if (!('content' in props)) {
158+
if (props.content === undefined) {
159159
warning(
160160
!props.editable,
161161
'Typography',
@@ -437,7 +437,7 @@ const Base = defineComponent<InternalBlockProps>({
437437
const { editing } = editable.value;
438438
const children =
439439
props.ellipsis || props.editable
440-
? 'content' in props
440+
? props.content !== undefined
441441
? props.content
442442
: slots.default?.()
443443
: slots.default

0 commit comments

Comments
 (0)