Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add validNumberValue #1182

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}