Skip to content

Commit 3e392ff

Browse files
patorjkgabrielliwerant
authored andcommitted
Fix for Memory Leak in TableToolbar (#829)
* refactored styled.js out of TableToolbar * removed test code
1 parent 4dc1b5f commit 3e392ff

File tree

4 files changed

+6
-72
lines changed

4 files changed

+6
-72
lines changed

src/MUIDataTable.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ class MUIDataTable extends React.Component {
295295
if (props.options.rowsPerPageOptions) {
296296
this.options.rowsPerPageOptions = props.options.rowsPerPageOptions;
297297
}
298+
if (['scroll', 'stacked'].indexOf(this.options.responsive) === -1) {
299+
console.error('Invalid option value for responsive. Please use string option: stacked | scroll');
300+
}
298301
}
299302

300303
validateOptions(options) {

src/components/TableToolbar.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import PrintIcon from '@material-ui/icons/Print';
1313
import ViewColumnIcon from '@material-ui/icons/ViewColumn';
1414
import FilterIcon from '@material-ui/icons/FilterList';
1515
import ReactToPrint from 'react-to-print';
16-
import styled from '../styled';
16+
import { withStyles } from '@material-ui/core/styles';
1717
import { createCSVDownload } from '../utils';
1818

19-
export const defaultToolbarStyles = (theme, props) => ({
19+
export const defaultToolbarStyles = theme => ({
2020
root: {},
2121
left: {
2222
flex: '1 1 auto',
@@ -43,10 +43,6 @@ export const defaultToolbarStyles = (theme, props) => ({
4343
marginTop: '10px',
4444
marginRight: '8px',
4545
},
46-
...(props.options.responsive ? { ...responsiveToolbarStyles(theme) } : {}),
47-
});
48-
49-
export const responsiveToolbarStyles = theme => ({
5046
[theme.breakpoints.down('sm')]: {
5147
titleRoot: {},
5248
titleText: {
@@ -315,4 +311,4 @@ class TableToolbar extends React.Component {
315311
}
316312
}
317313

318-
export default styled(TableToolbar)(defaultToolbarStyles, { name: 'MUIDataTableToolbar' });
314+
export default withStyles(defaultToolbarStyles, { name: 'MUIDataTableToolbar' })(TableToolbar);

src/styled.js

Lines changed: 0 additions & 53 deletions
This file was deleted.

test/MUIDataTableToolbar.test.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ describe('<TableToolbar />', function() {
130130
const shallowWrapper = shallow(
131131
<TableToolbar columns={columns} data={data} options={newOptions} setTableAction={setTableAction} />,
132132
)
133-
.dive()
134-
.dive()
135133
.dive();
136134
const instance = shallowWrapper.instance();
137135
instance.setActiveIcon('search');
@@ -144,8 +142,6 @@ describe('<TableToolbar />', function() {
144142
const shallowWrapper = shallow(
145143
<TableToolbar columns={columns} data={data} options={options} setTableAction={setTableAction} />,
146144
)
147-
.dive()
148-
.dive()
149145
.dive();
150146
const instance = shallowWrapper.instance();
151147

@@ -167,8 +163,6 @@ describe('<TableToolbar />', function() {
167163
setTableAction={setTableAction}
168164
/>,
169165
)
170-
.dive()
171-
.dive()
172166
.dive();
173167
const instance = shallowWrapper.instance();
174168

@@ -195,8 +189,6 @@ describe('<TableToolbar />', function() {
195189
const shallowWrapper = shallow(
196190
<TableToolbar columns={columns} data={data} options={options} setTableAction={setTableAction} />,
197191
)
198-
.dive()
199-
.dive()
200192
.dive();
201193
const instance = shallowWrapper.instance();
202194

@@ -218,8 +210,6 @@ describe('<TableToolbar />', function() {
218210
/>,
219211
);
220212
const instance = shallowWrapper
221-
.dive()
222-
.dive()
223213
.dive()
224214
.instance();
225215

@@ -247,8 +237,6 @@ describe('<TableToolbar />', function() {
247237
);
248238

249239
const instance = shallowWrapper
250-
.dive()
251-
.dive()
252240
.dive()
253241
.instance();
254242

0 commit comments

Comments
 (0)