diff --git a/components/_util/reactNode.ts b/components/_util/reactNode.ts new file mode 100644 index 0000000000..200a81da98 --- /dev/null +++ b/components/_util/reactNode.ts @@ -0,0 +1,7 @@ +import * as React from 'react'; + +export function cloneElement(element: React.ReactNode, ...restArgs: any[]) { + if (!React.isValidElement(element)) return element; + + return React.cloneElement(element, ...restArgs); +} \ No newline at end of file diff --git a/components/list/Item.tsx b/components/list/Item.tsx index 5762d61a15..2aadb98358 100644 --- a/components/list/Item.tsx +++ b/components/list/Item.tsx @@ -4,6 +4,7 @@ import classNames from 'classnames'; import { ListGridType, ColumnType } from './index'; import { Col } from '../grid'; import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; +import { cloneElement } from '../_util/reactNode'; export interface ListItemProps extends React.HTMLAttributes { className?: string; @@ -129,11 +130,7 @@ export default class Item extends React.Component { {extra} , ] - : [ - children, - actionsContent, - extra ? React.cloneElement(extra as React.ReactElement, { key: 'extra' }) : null, - ]} + : [children, actionsContent, cloneElement(extra, { key: 'extra' })]} ); diff --git a/components/list/style/index.less b/components/list/style/index.less index f68081f6b2..038ce5d8fb 100644 --- a/components/list/style/index.less +++ b/components/list/style/index.less @@ -43,10 +43,6 @@ align-items: center; padding: @list-item-padding; - &-no-flex { - display: block; - } - &-content { color: @text-color; } @@ -206,6 +202,20 @@ padding-bottom: 0; border-bottom: none; } + + // ============================ without flex ============================ + &-item-no-flex { + display: block; + } + + // Horizontal + &:not(.@{list-prefix-cls}-vertical) { + .@{list-prefix-cls}-item-no-flex { + .@{list-prefix-cls}-item-action { + float: right; + } + } + } } @import './bordered';