Skip to content

Commit

Permalink
fix: Customize scroll bar size of table (#616)
Browse files Browse the repository at this point in the history
* fix: customize scrollbar size should not break

* fix: Test case
  • Loading branch information
zombieJ committed May 20, 2021
1 parent d2ed97d commit 9cbf0db
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@babel/runtime": "^7.10.1",
"classnames": "^2.2.5",
"rc-resize-observer": "^1.0.0",
"rc-util": "^5.4.0",
"rc-util": "^5.13.0",
"shallowequal": "^1.1.0"
},
"devDependencies": {
Expand Down
16 changes: 8 additions & 8 deletions src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import classNames from 'classnames';
import shallowEqual from 'shallowequal';
import warning from 'rc-util/lib/warning';
import ResizeObserver from 'rc-resize-observer';
import getScrollBarSize from 'rc-util/lib/getScrollBarSize';
import { getTargetScrollBarSize } from 'rc-util/lib/getScrollBarSize';

This comment has been minimized.

Copy link
@afc163

afc163 May 24, 2021

Member

ant-design/ant-design#30651 (comment) 这个例子报错了。

图片

import ColumnGroup from './sugar/ColumnGroup';
import Column from './sugar/Column';
import FixedHeader from './Header/FixedHeader';
Expand Down Expand Up @@ -199,13 +199,6 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
const mergedData = data || EMPTY_DATA;
const hasData = !!mergedData.length;

// ===================== Effects ======================
const [scrollbarSize, setScrollbarSize] = React.useState(0);

React.useEffect(() => {
setScrollbarSize(getScrollBarSize());
});

// ===================== Warning ======================
if (process.env.NODE_ENV !== 'production') {
[
Expand Down Expand Up @@ -496,6 +489,13 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
}
}, [horizonScroll]);

// ===================== Effects ======================
const [scrollbarSize, setScrollbarSize] = React.useState(0);

React.useEffect(() => {
setScrollbarSize(getTargetScrollBarSize(scrollBodyRef.current).width);
}, []);

// ================== INTERNAL HOOKS ==================
React.useEffect(() => {
if (internalHooks === INTERNAL_HOOKS && internalRefs) {
Expand Down
2 changes: 2 additions & 0 deletions tests/__mocks__/rc-util/lib/getScrollBarSize.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export default () => 15;

export const getTargetScrollBarSize = () => ({ width: 15, height: 15 });

1 comment on commit 9cbf0db

@vercel
Copy link

@vercel vercel bot commented on 9cbf0db May 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.