diff --git a/components/breadcrumb/Breadcrumb.tsx b/components/breadcrumb/Breadcrumb.tsx index 638865842..3caf72ac5 100644 --- a/components/breadcrumb/Breadcrumb.tsx +++ b/components/breadcrumb/Breadcrumb.tsx @@ -1,6 +1,6 @@ import { cloneVNode, defineComponent, PropType, ExtractPropTypes } from 'vue'; import PropTypes from '../_util/vue-types'; -import { filterEmpty, getPropsSlot } from '../_util/props-util'; +import { flattenChildren, getPropsSlot } from '../_util/props-util'; import warning from '../_util/warning'; import BreadcrumbItem from './BreadcrumbItem'; import Menu from '../menu'; @@ -17,7 +17,7 @@ const breadcrumbProps = { prefixCls: PropTypes.string, routes: { type: Array as PropType }, params: PropTypes.any, - separator: PropTypes.VNodeChild, + separator: PropTypes.any, itemRender: { type: Function as PropType< (opt: { route: Route; params: unknown; routes: Route[]; paths: string[] }) => VueNode @@ -53,6 +53,7 @@ function defaultItemRender(opt: { export default defineComponent({ name: 'ABreadcrumb', props: breadcrumbProps, + slots: ['separator', 'itemRender'], setup(props, { slots }) { const { prefixCls, direction } = useConfigInject('breadcrumb', props); @@ -122,10 +123,10 @@ export default defineComponent({ const { routes, params = {} } = props; - const children = filterEmpty(getPropsSlot(slots, props)); - const separator = getPropsSlot(slots, props, 'separator'); + const children = flattenChildren(getPropsSlot(slots, props)); + const separator = getPropsSlot(slots, props, 'separator') ?? '/'; - const itemRender = getPropsSlot(slots, props, 'itemRender') || defaultItemRender; + const itemRender = props.itemRender || slots.itemRender || defaultItemRender; if (routes && routes.length > 0) { // generated by route crumbs = genForRoutes({ @@ -153,5 +154,4 @@ export default defineComponent({ return
{crumbs}
; }; }, - methods: {}, }); diff --git a/components/breadcrumb/BreadcrumbItem.tsx b/components/breadcrumb/BreadcrumbItem.tsx index 6cfa00285..a675e57db 100644 --- a/components/breadcrumb/BreadcrumbItem.tsx +++ b/components/breadcrumb/BreadcrumbItem.tsx @@ -8,8 +8,8 @@ import useConfigInject from '../_util/hooks/useConfigInject'; const breadcrumbItemProps = { prefixCls: PropTypes.string, href: PropTypes.string, - separator: PropTypes.VNodeChild.def('/'), - overlay: PropTypes.VNodeChild, + separator: PropTypes.any, + overlay: PropTypes.any, }; export type BreadcrumbItemProps = Partial>; @@ -17,6 +17,7 @@ export default defineComponent({ name: 'ABreadcrumbItem', __ANT_BREADCRUMB_ITEM: true, props: breadcrumbItemProps, + slots: ['separator', 'overlay'], setup(props, { slots }) { const { prefixCls } = useConfigInject('breadcrumb', props); /** @@ -39,11 +40,11 @@ export default defineComponent({ }; return () => { - const separator = getPropsSlot(slots, props, 'separator'); + const separator = getPropsSlot(slots, props, 'separator') ?? '/'; const children = getPropsSlot(slots, props); let link: JSX.Element; - if ('href' in props) { + if (props.href !== undefined) { link = {children}; } else { link = {children}; @@ -54,9 +55,7 @@ export default defineComponent({ return ( {link} - {separator && separator !== '' && ( - {separator} - )} + {separator && {separator}} ); } diff --git a/components/breadcrumb/BreadcrumbSeparator.tsx b/components/breadcrumb/BreadcrumbSeparator.tsx index f5c70f09d..119e2dbbc 100644 --- a/components/breadcrumb/BreadcrumbSeparator.tsx +++ b/components/breadcrumb/BreadcrumbSeparator.tsx @@ -1,6 +1,6 @@ import { defineComponent, ExtractPropTypes } from 'vue'; import PropTypes from '../_util/vue-types'; -import { getPropsSlot } from '../_util/props-util'; +import { flattenChildren } from '../_util/props-util'; import useConfigInject from '../_util/hooks/useConfigInject'; const breadcrumbSeparator = { @@ -18,8 +18,7 @@ export default defineComponent({ return () => { const { separator, class: className, ...restAttrs } = attrs; - const children = getPropsSlot(slots, props) || []; - + const children = flattenChildren(slots.default?.()); return ( {children.length > 0 ? children : '/'} diff --git a/components/breadcrumb/style/index.less b/components/breadcrumb/style/index.less index 1777e3de0..52bba1202 100644 --- a/components/breadcrumb/style/index.less +++ b/components/breadcrumb/style/index.less @@ -38,7 +38,8 @@ } &-link { - > .@{iconfont-css-prefix} + span { + > .@{iconfont-css-prefix} + span, + > .@{iconfont-css-prefix} + a { margin-left: 4px; } } @@ -49,3 +50,5 @@ } } } + +@import './rtl'; diff --git a/components/breadcrumb/style/rtl.less b/components/breadcrumb/style/rtl.less new file mode 100644 index 000000000..c1141c993 --- /dev/null +++ b/components/breadcrumb/style/rtl.less @@ -0,0 +1,29 @@ +.@{breadcrumb-prefix-cls} { + &-rtl { + .clearfix(); + direction: rtl; + + > span { + float: right; + } + } + + &-link { + > .@{iconfont-css-prefix} + span, + > .@{iconfont-css-prefix} + a { + .@{breadcrumb-prefix-cls}-rtl & { + margin-right: 4px; + margin-left: 0; + } + } + } + + &-overlay-link { + > .@{iconfont-css-prefix} { + .@{breadcrumb-prefix-cls}-rtl & { + margin-right: 4px; + margin-left: 0; + } + } + } +}