Skip to content

Commit 5e32a68

Browse files
committed
Fix onWidthChange only being called on breakpoint changes
1 parent f5a092c commit 5e32a68

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/ResponsiveReactGridLayout.jsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ export default class ResponsiveReactGridLayout extends React.Component<
188188
getBreakpointFromWidth(nextProps.breakpoints, nextProps.width);
189189

190190
const lastBreakpoint = this.state.breakpoint;
191+
const newCols: number = getColsFromBreakpoint(newBreakpoint, cols);
191192

192193
// Breakpoint change
193194
if (
@@ -200,7 +201,6 @@ export default class ResponsiveReactGridLayout extends React.Component<
200201
layouts[lastBreakpoint] = cloneLayout(this.state.layout);
201202

202203
// Find or generate a new layout.
203-
const newCols: number = getColsFromBreakpoint(newBreakpoint, cols);
204204
let layout = findOrGenerateResponsiveLayout(
205205
layouts,
206206
breakpoints,
@@ -224,19 +224,20 @@ export default class ResponsiveReactGridLayout extends React.Component<
224224
// callbacks
225225
this.props.onLayoutChange(layout, layouts);
226226
this.props.onBreakpointChange(newBreakpoint, newCols);
227-
this.props.onWidthChange(
228-
nextProps.width,
229-
nextProps.margin,
230-
newCols,
231-
nextProps.containerPadding
232-
);
233227

234228
this.setState({
235229
breakpoint: newBreakpoint,
236230
layout: layout,
237231
cols: newCols
238232
});
239233
}
234+
//call onWidthChange on every change of width, not only on breakpoint changes
235+
this.props.onWidthChange(
236+
nextProps.width,
237+
nextProps.margin,
238+
newCols,
239+
nextProps.containerPadding
240+
);
240241
}
241242

242243
render() {

0 commit comments

Comments
 (0)