Skip to content

Commit 73f2798

Browse files
committed
chore(useAffix): simplify null checks for fixedRows
1 parent e75621e commit 73f2798

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

packages/components/table/_example/fixed-column.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ const statusNameListMap = {
2727
};
2828

2929
export default function TableFixedColumn() {
30+
const tableRef = useRef(null);
31+
3032
const [tableLayout, setTableLayout] = useState<TableProps['tableLayout']>('fixed');
3133
const [emptyData, setEmptyData] = useState(false);
3234
const [leftFixedColumn, setLeftFixedColumn] = useState(2);
3335
const [rightFixedColumn, setReftFixedColumn] = useState(1);
3436

35-
const tableRef = useRef(null);
36-
3737
const scrollToCreateTime = () => {
3838
// 横向滚动到指定列,一般用于列数量较多的场景
3939
tableRef.current.scrollColumnIntoView('createTime');

packages/components/table/hooks/useAffix.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default function useAffix(props: TdBaseTableProps, { showElement }: { sho
8181
toUpdateScrollElement.forEach((el) => {
8282
if (!el) return;
8383
// fixedRows 使用 sticky,吸顶表头使用 absolute,需要考虑页面滚动对定位的影响
84-
if (props.fixedRows && props.fixedRows.length > 0) {
84+
if (props.fixedRows?.length) {
8585
// eslint-disable-next-line no-param-reassign
8686
el.style.marginLeft = `-${pageScrollLeft}px`;
8787
} else if (el.style.marginLeft) {
@@ -242,7 +242,7 @@ export default function useAffix(props: TdBaseTableProps, { showElement }: { sho
242242

243243
const addPageHorizontalScrollListener = () => {
244244
if (typeof window === 'undefined') return;
245-
if (props.fixedRows && props.fixedRows.length > 0 && isAffixed) {
245+
if (props.fixedRows.length && isAffixed) {
246246
onPageHorizontalScroll(); // initial sync
247247
on(window, 'scroll', onPageHorizontalScroll);
248248
}

0 commit comments

Comments
 (0)