fix: collapse default position in rtl (#23445)

* fix: collapse default position in rtl

* update snap

* up

* fix

* fix

* fix var

* fix
This commit is contained in:
xrkffgg 2020-04-21 23:23:37 +08:00 committed by GitHub
parent 9a43e439b3
commit 5e09660a3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 10 deletions

View File

@ -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> | string | number;
@ -40,9 +40,16 @@ export default class Collapse extends React.Component<CollapseProps, any> {
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<CollapseProps, any> {
};
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,

View File

@ -51,7 +51,7 @@ exports[`Collapse could override default openAnimation 1`] = `
exports[`Collapse rtl render component should be rendered correctly in RTL direction 1`] = `
<div
class="ant-collapse ant-collapse-icon-position-left ant-collapse-rtl"
class="ant-collapse ant-collapse-icon-position-right ant-collapse-rtl"
/>
`;