mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-01 11:39:28 +08:00
Merge pull request #15951 from ant-design/fix-progress-status
fix(Progress): 🐛 fix progress success UI when status is undefined
This commit is contained in:
commit
6bd76140a4
@ -635,7 +635,7 @@ exports[`renders ./components/progress/demo/format.md correctly 1`] = `
|
||||
exports[`renders ./components/progress/demo/gradient-line.md correctly 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="ant-progress ant-progress-line ant-progress-status-active ant-progress-show-info ant-progress-default"
|
||||
class="ant-progress ant-progress-line ant-progress-status-normal ant-progress-show-info ant-progress-default"
|
||||
>
|
||||
<div>
|
||||
<div
|
||||
|
@ -86,4 +86,23 @@ 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 wrapper = mount(<Progress percent={100} status={undefined} />);
|
||||
expect(wrapper.find('.ant-progress-status-success')).toHaveLength(1);
|
||||
});
|
||||
|
||||
// https://github.com/ant-design/ant-design/pull/15951#discussion_r273062969
|
||||
it('should show success status when status is invalid', () => {
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
const wrapper = mount(<Progress percent={100} status="invalid" />);
|
||||
expect(wrapper.find('.ant-progress-status-success')).toHaveLength(1);
|
||||
errorSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
@ -24,7 +24,6 @@ const Demo = () => (
|
||||
'100%': '#87d068',
|
||||
}}
|
||||
percent={99.9}
|
||||
status="active"
|
||||
/>
|
||||
<Progress
|
||||
strokeColor={{
|
||||
|
@ -61,6 +61,22 @@ export default class Progress extends React.Component<ProgressProps> {
|
||||
default: PropTypes.oneOf(['default', 'small']),
|
||||
};
|
||||
|
||||
getPercentNumber() {
|
||||
const { successPercent, percent = 0 } = this.props;
|
||||
return parseInt(
|
||||
successPercent !== undefined ? successPercent.toString() : percent.toString(),
|
||||
10,
|
||||
);
|
||||
}
|
||||
|
||||
getProgressStatus() {
|
||||
const { status } = this.props;
|
||||
if (ProgressStatuses.indexOf(status!) < 0 && this.getPercentNumber() >= 100) {
|
||||
return 'success';
|
||||
}
|
||||
return status || 'normal';
|
||||
}
|
||||
|
||||
renderProcessInfo(prefixCls: string, progressStatus: (typeof ProgressStatuses)[number]) {
|
||||
const { showInfo, format, type, percent, successPercent } = this.props;
|
||||
if (!showInfo) return null;
|
||||
@ -104,15 +120,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 = (
|
||||
|
Loading…
Reference in New Issue
Block a user