diff --git a/components/collapse/Collapse.tsx b/components/collapse/Collapse.tsx index 0fe9c53221..7317c77aea 100644 --- a/components/collapse/Collapse.tsx +++ b/components/collapse/Collapse.tsx @@ -7,7 +7,7 @@ import CollapsePanel from './CollapsePanel'; import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; import animation from '../_util/openAnimation'; -export type ExpandIconPosition = 'left' | 'right'; +export type ExpandIconPosition = 'left' | 'right' | undefined; export interface CollapseProps { activeKey?: Array | string | number; @@ -40,9 +40,16 @@ export default class Collapse extends React.Component { static defaultProps = { bordered: true, - expandIconPosition: 'left' as CollapseProps['expandIconPosition'], }; + getIconPosition(direction: string = 'ltr') { + const { expandIconPosition } = this.props; + if (expandIconPosition !== undefined) { + return expandIconPosition; + } + return direction === 'rtl' ? 'right' : 'left'; + } + renderExpandIcon = (panelProps: PanelProps = {}, prefixCls: string) => { const { expandIcon } = this.props; const icon = (expandIcon ? ( @@ -59,17 +66,13 @@ export default class Collapse extends React.Component { }; renderCollapse = ({ getPrefixCls, direction }: ConfigConsumerProps) => { - const { - prefixCls: customizePrefixCls, - className = '', - bordered, - expandIconPosition, - } = this.props; + const { prefixCls: customizePrefixCls, className = '', bordered } = this.props; const prefixCls = getPrefixCls('collapse', customizePrefixCls); + const iconPosition = this.getIconPosition(direction); const collapseClassName = classNames( { [`${prefixCls}-borderless`]: !bordered, - [`${prefixCls}-icon-position-${expandIconPosition}`]: true, + [`${prefixCls}-icon-position-${iconPosition}`]: true, [`${prefixCls}-rtl`]: direction === 'rtl', }, className, diff --git a/components/collapse/__tests__/__snapshots__/index.test.js.snap b/components/collapse/__tests__/__snapshots__/index.test.js.snap index a99a2e8047..f530d2a4ef 100644 --- a/components/collapse/__tests__/__snapshots__/index.test.js.snap +++ b/components/collapse/__tests__/__snapshots__/index.test.js.snap @@ -51,7 +51,7 @@ exports[`Collapse could override default openAnimation 1`] = ` exports[`Collapse rtl render component should be rendered correctly in RTL direction 1`] = `
`;