Skip to content

Commit

Permalink
fix: support vue3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou committed Jun 8, 2021
1 parent b45a625 commit 93c2bc1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion components/auto-complete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const AutoComplete = defineComponent({
OptGroup: { ...OptGroup, name: 'AAutoCompleteOptGroup' },
setup(props, { slots }) {
warning(
!('dataSource' in props || 'dataSource' in slots),
!(props.dataSource !== undefined || 'dataSource' in slots),
'AutoComplete',
'`dataSource` is deprecated, please use `options` instead.',
);
Expand Down
9 changes: 4 additions & 5 deletions components/menu/src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default defineComponent({
{ immediate: true },
);
watchEffect(() => {
if ('activeKey' in props) {
if (props.activeKey !== undefined) {
let keys = [];
const menuInfo = props.activeKey
? (keyMapStore.value[props.activeKey] as UnwrapRef<StoreMenuInfo>)
Expand Down Expand Up @@ -194,7 +194,7 @@ export default defineComponent({
selectedKeys: newSelectedKeys,
};
if (!shallowEqual(newSelectedKeys, mergedSelectedKeys.value)) {
if (!('selectedKeys' in props)) {
if (props.selectedKeys === undefined) {
mergedSelectedKeys.value = newSelectedKeys;
}
emit('update:selectedKeys', newSelectedKeys);
Expand Down Expand Up @@ -223,11 +223,10 @@ export default defineComponent({
);

const changeActiveKeys = (keys: Key[]) => {
if ('activeKey' in props) {
emit('update:activeKey', keys[keys.length - 1]);
} else {
if (props.activeKey === undefined) {
activeKeys.value = keys;
}
emit('update:activeKey', keys[keys.length - 1]);
};
const disabled = computed(() => !!props.disabled);
const isRtl = computed(() => direction.value === 'rtl');
Expand Down
16 changes: 12 additions & 4 deletions components/switch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
computed,
onMounted,
nextTick,
watch,
} from 'vue';
import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined';
import PropTypes from '../_util/vue-types';
Expand All @@ -27,7 +28,6 @@ const switchProps = {
checkedChildren: PropTypes.any,
unCheckedChildren: PropTypes.any,
tabindex: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
defaultChecked: PropTypes.looseBool,
autofocus: PropTypes.looseBool,
loading: PropTypes.looseBool,
checked: PropTypes.looseBool,
Expand Down Expand Up @@ -59,6 +59,14 @@ const Switch = defineComponent({
'`value` is not validate prop, do you mean `checked`?',
);
});
const checked = ref(props.checked !== undefined ? !!props.checked : !!attrs.defaultChecked);

watch(
() => props.checked,
() => {
checked.value = !!props.checked;
},
);

const configProvider = inject('configProvider', defaultConfigProvider);
const { getPrefixCls } = configProvider;
Expand All @@ -75,9 +83,6 @@ const Switch = defineComponent({
const prefixCls = computed(() => {
return getPrefixCls('switch', props.prefixCls);
});
const checked = computed(() => {
return 'checked' in props ? !!props.checked : !!props.defaultChecked;
});

onMounted(() => {
nextTick(() => {
Expand All @@ -91,6 +96,9 @@ const Switch = defineComponent({
if (props.disabled) {
return;
}
if (props.checked === undefined) {
checked.value = check;
}
emit('update:checked', check);
emit('change', check, e);
};
Expand Down
4 changes: 2 additions & 2 deletions components/typography/Base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const Base = defineComponent<InternalBlockProps>({
);

watchEffect(() => {
if (!('content' in props)) {
if (props.content === undefined) {
warning(
!props.editable,
'Typography',
Expand Down Expand Up @@ -437,7 +437,7 @@ const Base = defineComponent<InternalBlockProps>({
const { editing } = editable.value;
const children =
props.ellipsis || props.editable
? 'content' in props
? props.content !== undefined
? props.content
: slots.default?.()
: slots.default
Expand Down

0 comments on commit 93c2bc1

Please sign in to comment.