Skip to content

Commit

Permalink
refactor: add validNumberValue
Browse files Browse the repository at this point in the history
  • Loading branch information
li-jia-nan committed Aug 25, 2024
1 parent b004d1a commit 14ecd3e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import Panel from './Panel';
import StickyScrollBar from './stickyScrollBar';
import Column from './sugar/Column';
import ColumnGroup from './sugar/ColumnGroup';
import { getColumnsKey, validateValue } from './utils/valueUtil';
import { getColumnsKey, validateValue, validNumberValue } from './utils/valueUtil';
import { getDOM } from 'rc-util/lib/Dom/findDOMNode';

export const DEFAULT_PREFIX = 'rc-table';
Expand Down Expand Up @@ -331,12 +331,8 @@ function Table<RecordType extends DefaultRecordType>(
if (scrollBodyRef.current instanceof HTMLElement) {
// Native scroll
const { index, top, key } = config;

// * 考虑top为0的情况
if (top || top === 0) {
scrollBodyRef.current?.scrollTo({
top,
});
if (validNumberValue(top)) {
scrollBodyRef.current?.scrollTo({ top });
} else {
const mergedKey = key ?? getRowKey(mergedData[index]);
scrollBodyRef.current.querySelector(`[data-row-key="${mergedKey}"]`)?.scrollIntoView();
Expand Down
4 changes: 4 additions & 0 deletions src/utils/valueUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ export function getColumnsKey<T = any>(columns: readonly GetColumnKeyColumn<T>[]
export function validateValue<T>(val: T) {
return val !== null && val !== undefined;
}

export function validNumberValue(value: any) {
return typeof value === 'number' && !Number.isNaN(value);
}

0 comments on commit 14ecd3e

Please sign in to comment.