Skip to content

Commit 02b8a17

Browse files
fix(steps): inconsistent rendering between string and number when the props of 'current' is a string (#761)
- Character conversion when the props of 'current' is a string
1 parent d1b405a commit 02b8a17

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/steps/StepItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const StepItem: FC<StepItemProps> = (props) => {
6060
const dot = useMemo(() => theme === StepThemeEnum.DOT, [theme]);
6161
const currentStatus = useMemo(() => {
6262
if (status !== 'default') return status;
63-
if (index === current) return stepsStatus;
63+
if (index === +current) return stepsStatus;
6464
if (index < +current) return 'finish';
6565
return status;
6666
}, [index, current, stepsStatus, status]);

src/steps/_example/horizontal.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Steps, StepItem } from 'tdesign-mobile-react';
33
import { CartIcon } from 'tdesign-icons-react';
44

55
export default function StepsDemo() {
6-
const [first, setFirst] = useState(1);
6+
const [first, setFirst] = useState<number | string>('1');
77
const [second, setSecond] = useState(1);
88
const [third, setThird] = useState(1);
99
const options = {
@@ -13,7 +13,7 @@ export default function StepsDemo() {
1313
};
1414

1515
const count = 4;
16-
const onFirstChange = (current: number) => {
16+
const onFirstChange = (current: number | string) => {
1717
setFirst(current);
1818
};
1919
const onSecondChange = (current: number) => {
@@ -23,14 +23,17 @@ export default function StepsDemo() {
2323
setThird(current);
2424
};
2525

26-
const getTitle = (type: 'first' | 'second' | 'third', index: number) => {
27-
if (index === options[type]) {
26+
const getTitle = (type: 'first' | 'second' | 'third', index: number | string) => {
27+
const numIndex = Number(index);
28+
const currentValue = Number(options[type]);
29+
30+
if (numIndex === currentValue) {
2831
return '当前步骤';
2932
}
30-
if (index < options[type]) {
33+
if (numIndex < currentValue) {
3134
return '已完成';
3235
}
33-
if (index > options[type]) {
36+
if (numIndex > currentValue) {
3437
return '未完成';
3538
}
3639
};

0 commit comments

Comments
 (0)