Skip to content

Commit bedfc01

Browse files
authored
refactor: add validNumberValue (#1182)
1 parent b004d1a commit bedfc01

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/Table.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ import Panel from './Panel';
7474
import StickyScrollBar from './stickyScrollBar';
7575
import Column from './sugar/Column';
7676
import ColumnGroup from './sugar/ColumnGroup';
77-
import { getColumnsKey, validateValue } from './utils/valueUtil';
77+
import { getColumnsKey, validateValue, validNumberValue } from './utils/valueUtil';
7878
import { getDOM } from 'rc-util/lib/Dom/findDOMNode';
7979

8080
export const DEFAULT_PREFIX = 'rc-table';
@@ -331,12 +331,8 @@ function Table<RecordType extends DefaultRecordType>(
331331
if (scrollBodyRef.current instanceof HTMLElement) {
332332
// Native scroll
333333
const { index, top, key } = config;
334-
335-
// * 考虑top为0的情况
336-
if (top || top === 0) {
337-
scrollBodyRef.current?.scrollTo({
338-
top,
339-
});
334+
if (validNumberValue(top)) {
335+
scrollBodyRef.current?.scrollTo({ top });
340336
} else {
341337
const mergedKey = key ?? getRowKey(mergedData[index]);
342338
scrollBodyRef.current.querySelector(`[data-row-key="${mergedKey}"]`)?.scrollIntoView();

src/utils/valueUtil.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ export function getColumnsKey<T = any>(columns: readonly GetColumnKeyColumn<T>[]
3636
export function validateValue<T>(val: T) {
3737
return val !== null && val !== undefined;
3838
}
39+
40+
export function validNumberValue(value: any) {
41+
return typeof value === 'number' && !Number.isNaN(value);
42+
}

0 commit comments

Comments
 (0)