Skip to content

Commit

Permalink
Merge pull request #333 from react-component/fix-extra-table-header-s…
Browse files Browse the repository at this point in the history
…crollbar

fix(Table): Hide header extra scrollbar
  • Loading branch information
afc163 authored Jun 4, 2019
2 parents f414865 + 810e82b commit 55347a5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 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({ direction: 'horizontal', 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 scroll-div-append-to-body`;
// Append related overflow style
if (isVertical) {
scrollDiv.style.overflowY = 'scroll';
Expand Down
10 changes: 5 additions & 5 deletions tests/__snapshots__/Table.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ exports[`Table custom components renders fixed column and header correctly 1`] =
class="rc-table-scroll"
>
<div
class="rc-table-header"
class="rc-table-header rc-table-hide-scrollbar"
>
<table
class=""
Expand Down Expand Up @@ -338,7 +338,7 @@ exports[`Table custom components renders fixed column and header correctly 1`] =
class="rc-table-fixed-left"
>
<div
class="rc-table-header"
class="rc-table-header rc-table-hide-scrollbar"
>
<table
class="rc-table-fixed"
Expand Down Expand Up @@ -407,7 +407,7 @@ exports[`Table custom components renders fixed column and header correctly 1`] =
class="rc-table-fixed-right"
>
<div
class="rc-table-header"
class="rc-table-header rc-table-hide-scrollbar"
>
<table
class="rc-table-fixed"
Expand Down Expand Up @@ -1213,7 +1213,7 @@ exports[`Table renders fixed header correctly 1`] = `
class="rc-table-content"
>
<div
class="rc-table-header"
class="rc-table-header rc-table-hide-scrollbar"
>
<table
class=""
Expand Down Expand Up @@ -1823,7 +1823,7 @@ exports[`Table scroll renders scroll.y is a number 1`] = `
class="rc-table-scroll"
>
<div
class="rc-table-header"
class="rc-table-header rc-table-hide-scrollbar"
>
<table
class=""
Expand Down

0 comments on commit 55347a5

Please sign in to comment.