diff --git a/components/_util/hooks/useBreakpoint.ts b/components/_util/hooks/useBreakpoint.ts index 5499ef091..af044b665 100644 --- a/components/_util/hooks/useBreakpoint.ts +++ b/components/_util/hooks/useBreakpoint.ts @@ -1,15 +1,18 @@ import type { Ref } from 'vue'; -import { onMounted, onUnmounted, ref } from 'vue'; +import { getCurrentInstance, onMounted, onUnmounted, ref } from 'vue'; import type { ScreenMap } from '../../_util/responsiveObserve'; import ResponsiveObserve from '../../_util/responsiveObserve'; -function useBreakpoint(): Ref { +function useBreakpoint(refreshOnChange = ref(true)): Ref { const screens = ref({}); let token = null; - + const instance = getCurrentInstance(); onMounted(() => { token = ResponsiveObserve.subscribe(supportScreens => { screens.value = supportScreens; + if (refreshOnChange?.value) { + instance.update(); + } }); }); diff --git a/components/avatar/Avatar.tsx b/components/avatar/Avatar.tsx index b713c5ca1..e14f5ed1e 100644 --- a/components/avatar/Avatar.tsx +++ b/components/avatar/Avatar.tsx @@ -51,8 +51,15 @@ const Avatar = defineComponent({ const { prefixCls } = useConfigInject('avatar', props); const groupSize = useInjectSize(); - - const screens = useBreakpoint(); + const size = computed(() => { + return props.size === 'default' ? groupSize.value : props.size; + }); + const needResponsive = computed(() => + Object.keys(typeof size.value === 'object' ? size.value || {} : {}).some(key => + ['xs', 'sm', 'md', 'lg', 'xl', 'xxl'].includes(key), + ), + ); + const screens = useBreakpoint(needResponsive); const responsiveSize = computed(() => { if (typeof props.size !== 'object') { return undefined; @@ -126,27 +133,26 @@ const Avatar = defineComponent({ }); return () => { - const { shape, size: customSize, src, alt, srcset, draggable, crossOrigin } = props; + const { shape, src, alt, srcset, draggable, crossOrigin } = props; const icon = getPropsSlot(slots, props, 'icon'); const pre = prefixCls.value; - const size = customSize === 'default' ? groupSize.value : customSize; const classString = { [`${attrs.class}`]: !!attrs.class, [pre]: true, - [`${pre}-lg`]: size === 'large', - [`${pre}-sm`]: size === 'small', + [`${pre}-lg`]: size.value === 'large', + [`${pre}-sm`]: size.value === 'small', [`${pre}-${shape}`]: shape, [`${pre}-image`]: src && isImgExist.value, [`${pre}-icon`]: icon, }; const sizeStyle: CSSProperties = - typeof size === 'number' + typeof size.value === 'number' ? { - width: `${size}px`, - height: `${size}px`, - lineHeight: `${size}px`, - fontSize: icon ? `${size / 2}px` : '18px', + width: `${size.value}px`, + height: `${size.value}px`, + lineHeight: `${size.value}px`, + fontSize: icon ? `${size.value / 2}px` : '18px', } : {}; @@ -173,9 +179,9 @@ const Avatar = defineComponent({ transform: transformString, }; const sizeChildrenStyle = - typeof size === 'number' + typeof size.value === 'number' ? { - lineHeight: `${size}px`, + lineHeight: `${size.value}px`, } : {}; childrenToRender = ( diff --git a/components/button/button.tsx b/components/button/button.tsx index 838f56e05..ed66ab872 100644 --- a/components/button/button.tsx +++ b/components/button/button.tsx @@ -12,7 +12,7 @@ import { import Wave from '../_util/wave'; import buttonTypes from './buttonTypes'; import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined'; -import { flattenChildren, getPropsSlot } from '../_util/props-util'; +import { flattenChildren, getPropsSlot, initDefaultProps } from '../_util/props-util'; import useConfigInject from '../_util/hooks/useConfigInject'; import devWarning from '../vc-util/devWarning'; @@ -32,7 +32,7 @@ export default defineComponent({ name: 'AButton', inheritAttrs: false, __ANT_BUTTON: true, - props: buttonTypes(), + props: initDefaultProps(buttonTypes(), { type: 'default' }), slots: ['icon'], emits: ['click', 'mousedown'], setup(props, { slots, attrs, emit }) { diff --git a/components/cascader/demo/multiple.vue b/components/cascader/demo/multiple.vue index 28ff3dc48..eb1f82c54 100644 --- a/components/cascader/demo/multiple.vue +++ b/components/cascader/demo/multiple.vue @@ -18,7 +18,7 @@ Select multiple options