Browse Source

fix: collapse default position in rtl (#23445)

* fix: collapse default position in rtl

* update snap

* up

* fix

* fix

* fix var

* fix
pull/22956/head
xrkffgg 5 years ago
committed by GitHub
parent
commit
5e09660a3e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      components/collapse/Collapse.tsx
  2. 2
      components/collapse/__tests__/__snapshots__/index.test.js.snap

21
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> | 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,

2
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`] = `
<div
class="ant-collapse ant-collapse-icon-position-left ant-collapse-rtl"
class="ant-collapse ant-collapse-icon-position-right ant-collapse-rtl"
/>
`;

Loading…
Cancel
Save