Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: collapse default position in rtl #23445

Merged
merged 7 commits into from
Apr 21, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions components/collapse/Collapse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,6 +42,13 @@ export default class Collapse extends React.Component<CollapseProps, any> {
bordered: true,
};

getIconPosition(isRTL: boolean, expandIconPosition: ExpandIconPosition) {
if (expandIconPosition !== undefined) {
return expandIconPosition;
}
return isRTL ? 'right' : 'left';
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isRTLexpandIconPosition 从 this.props 中计算,不要作为参数传递。


renderExpandIcon = (panelProps: PanelProps = {}, prefixCls: string) => {
const { expandIcon } = this.props;
const icon = (expandIcon ? (
Expand All @@ -65,16 +72,13 @@ export default class Collapse extends React.Component<CollapseProps, any> {
expandIconPosition,
} = this.props;
const prefixCls = getPrefixCls('collapse', customizePrefixCls);
let iconPosition;
if (expandIconPosition !== undefined) {
iconPosition = expandIconPosition;
} else {
iconPosition = direction === 'rtl' ? 'right' : 'left';
}
const collapseClassName = classNames(
{
[`${prefixCls}-borderless`]: !bordered,
[`${prefixCls}-icon-position-${iconPosition}`]: true,
[`${prefixCls}-icon-position-${this.getIconPosition(
direction === 'rtl',
expandIconPosition,
)}`]: true,
[`${prefixCls}-rtl`]: direction === 'rtl',
},
className,
Expand Down