Skip to content

Commit 8b28c4b

Browse files
committed
fix pagination dropdown broken for bootstrap@4 beta
1 parent e6c0a43 commit 8b28c4b

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

src/BootstrapTable.js

+1
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,7 @@ class BootstrapTable extends Component {
12681268
<div className='react-bs-table-pagination'>
12691269
<PaginationList
12701270
ref={ node => this.pagination = node }
1271+
version={ this.props.version }
12711272
withFirstAndLast={ withFirstAndLast }
12721273
alwaysShowAllBtns={ options.alwaysShowAllBtns }
12731274
currPage={ this.state.currPage }

src/pagination/PaginationList.js

+23-7
Original file line numberDiff line numberDiff line change
@@ -178,21 +178,36 @@ class PaginationList extends Component {
178178
}
179179

180180
if (dropdownProps || !dropdown) {
181+
const isBootstrap4 = Util.isBootstrap4(this.props.version);
181182
const sizePerPageOptions = sizePerPageList.map((_sizePerPage) => {
182183
const pageText = _sizePerPage.text || _sizePerPage;
183184
const pageNum = _sizePerPage.value || _sizePerPage;
184185
if (sizePerPage === pageNum) sizePerPageText = pageText;
185-
return (
186-
<li key={ pageText } role='presentation' className='dropdown-item'>
187-
<a role='menuitem'
188-
tabIndex='-1' href='#'
189-
data-page={ pageNum }
186+
if (isBootstrap4) {
187+
return (
188+
<a
189+
href='#'
190+
tabIndex='-1'
191+
key={ pageText }
192+
className='dropdown-item'
190193
onMouseDown={ e => {
191194
e.preventDefault();
192195
this.changeSizePerPage(pageNum);
193196
} }>{ pageText }</a>
194-
</li>
195-
);
197+
);
198+
} else {
199+
return (
200+
<li key={ pageText } role='presentation' className='dropdown-item'>
201+
<a role='menuitem'
202+
tabIndex='-1' href='#'
203+
data-page={ pageNum }
204+
onMouseDown={ e => {
205+
e.preventDefault();
206+
this.changeSizePerPage(pageNum);
207+
} }>{ pageText }</a>
208+
</li>
209+
);
210+
}
196211
});
197212
dropdown = (
198213
<SizePerPageDropDown
@@ -202,6 +217,7 @@ class PaginationList extends Component {
202217
options={ sizePerPageOptions }
203218
onClick={ this.toggleDropDown }
204219
onBlur={ this.closeDropDown }
220+
isBootstrap4={ isBootstrap4 }
205221
{ ...dropdownProps }/>
206222
);
207223
}

src/pagination/SizePerPageDropDown.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,31 @@ class SizePerPageDropDown extends Component {
1414
className,
1515
variation,
1616
btnContextual,
17+
isBootstrap4,
1718
currSizePerPage
1819
} = this.props;
1920

2021
const openClass = open ? 'open show' : '';
2122
const dropDownStyle = { visibility: hidden ? 'hidden' : 'visible' };
2223

24+
const renderOptions = () => {
25+
const attrs = {
26+
className: `dropdown-menu ${openClass}`,
27+
role: 'menu',
28+
'aria-labelledby': 'pageDropDown'
29+
};
30+
const type = isBootstrap4 ? 'div' : 'ul';
31+
32+
return React.createElement(type, attrs, options);
33+
};
34+
2335
return (
2436
<span style={ dropDownStyle }
2537
className={ `${variation} ${openClass} ${className} ${sizePerPageDefaultClass}` }>
2638
<button className={ `btn ${btnContextual} dropdown-toggle` }
2739
id='pageDropDown' data-toggle='dropdown'
2840
aria-expanded={ open }
41+
aria-haspopup={ !open }
2942
onClick={ onClick }
3043
onBlur={ onBlur }>
3144
{ currSizePerPage }
@@ -34,9 +47,7 @@ class SizePerPageDropDown extends Component {
3447
<span className='caret'/>
3548
</span>
3649
</button>
37-
<ul className='dropdown-menu' role='menu' aria-labelledby='pageDropDown'>
38-
{ options }
39-
</ul>
50+
{ renderOptions() }
4051
</span>
4152
);
4253
}

0 commit comments

Comments
 (0)