Skip to content

Commit

Permalink
fix(Table): Hide header extra scrollbar
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Jun 4, 2019
1 parent f414865 commit 4219e21
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
10 changes: 8 additions & 2 deletions assets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@
}

&-fixed-header &-scroll &-header {
overflow-x: scroll;
padding-bottom: 20px;
margin-bottom: -20px;
overflow-y: scroll;
overflow: scroll;
box-sizing: border-box;
}

&-hide-scrollbar {
scrollbar-color: transparent transparent;
&::-webkit-scrollbar {
background-color: transparent;
}
}

// https://github.com/ant-design/ant-design/issues/10828
&-fixed-columns-in-body {
visibility: hidden;
Expand Down
2 changes: 1 addition & 1 deletion src/BodyTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function BodyTable(props, { table }) {
useFixedHeader = true;

// Add negative margin bottom for scroll bar overflow bug
const scrollbarWidth = measureScrollbar();
const scrollbarWidth = measureScrollbar({ prefixCls });
if (scrollbarWidth > 0 && fixed) {
bodyStyle.marginBottom = `-${scrollbarWidth}px`;
bodyStyle.paddingBottom = '0px';
Expand Down
4 changes: 2 additions & 2 deletions src/HeadTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function HeadTable(props, { table }) {
if (scroll.y) {
useFixedHeader = true;
// Add negative margin bottom for scroll bar overflow bug
const scrollbarWidth = measureScrollbar('horizontal');
const scrollbarWidth = measureScrollbar({ direction: 'horizontal', prefixCls });
if (scrollbarWidth > 0 && !fixed) {
headStyle.marginBottom = `-${scrollbarWidth}px`;
headStyle.paddingBottom = '0px';
Expand All @@ -28,7 +28,7 @@ export default function HeadTable(props, { table }) {
<div
key="headTable"
ref={fixed ? null : saveRef('headTable')}
className={`${prefixCls}-header`}
className={`${prefixCls}-header ${prefixCls}-hide-scrollbar`}
style={headStyle}
onScroll={handleBodyScrollLeft}
>
Expand Down
4 changes: 3 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const scrollbarMeasure = {
// This const is used for colgroup.col internal props. And should not provides to user.
export const INTERNAL_COL_DEFINE = 'RC_TABLE_INTERNAL_COL_DEFINE';

export function measureScrollbar(direction = 'vertical') {
export function measureScrollbar({ direction = 'vertical', prefixCls }) {
if (typeof document === 'undefined' || typeof window === 'undefined') {
return 0;
}
Expand All @@ -28,6 +28,8 @@ export function measureScrollbar(direction = 'vertical') {
Object.keys(scrollbarMeasure).forEach(scrollProp => {
scrollDiv.style[scrollProp] = scrollbarMeasure[scrollProp];
});
// apply hide scrollbar className ahead
scrollDiv.className = `${prefixCls}-hide-scrollbar`;
// Append related overflow style
if (isVertical) {
scrollDiv.style.overflowY = 'scroll';
Expand Down

0 comments on commit 4219e21

Please sign in to comment.