Skip to content

Commit

Permalink
fix(Progress): 🐛 fix progress success UI when status is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Apr 8, 2019
1 parent ff23ce7 commit 89351ba
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
11 changes: 11 additions & 0 deletions components/progress/__tests__/index.test.js
Expand Up @@ -86,4 +86,15 @@ describe('Progress', () => {
'test10 10%, test20 20%, test30 30%',
);
});

it('should show success status when percent is 100', () => {
const wrapper = mount(<Progress percent={100} />);
expect(wrapper.find('.ant-progress-status-success')).toHaveLength(1);
});

// https://github.com/ant-design/ant-design/issues/15950
it('should show success status when percent is 100 and status is undefined', () => {
const wrapper2 = mount(<Progress percent={100} status={undefined} />);
expect(wrapper2.find('.ant-progress-status-success')).toHaveLength(1);
});
});
22 changes: 14 additions & 8 deletions components/progress/progress.tsx
Expand Up @@ -61,6 +61,18 @@ export default class Progress extends React.Component<ProgressProps> {
default: PropTypes.oneOf(['default', 'small']),
};

getProgressStatus() {
const { successPercent, percent = 0, status } = this.props;
const percentNumber = parseInt(
successPercent !== undefined ? successPercent.toString() : percent.toString(),
10,
);
if (percentNumber >= 100 && status === undefined) {
return 'success';
}
return status || 'normal';
}

renderProcessInfo(prefixCls: string, progressStatus: (typeof ProgressStatuses)[number]) {
const { showInfo, format, type, percent, successPercent } = this.props;
if (!showInfo) return null;
Expand Down Expand Up @@ -104,15 +116,9 @@ export default class Progress extends React.Component<ProgressProps> {
...restProps
} = props;
const prefixCls = getPrefixCls('progress', customizePrefixCls);
const progressStatus =
parseInt(successPercent !== undefined ? successPercent.toString() : percent.toString(), 10) >=
100 && !('status' in props)
? 'success'
: status || 'normal';
let progress;

const progressStatus = this.getProgressStatus();
const progressInfo = this.renderProcessInfo(prefixCls, progressStatus);

let progress;
// Render progress shape
if (type === 'line') {
progress = (
Expand Down

0 comments on commit 89351ba

Please sign in to comment.