Skip to content

Commit

Permalink
Added innerRef prop to expose wrapping div (react-grid-layout#1176)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-sachs authored Apr 29, 2020
1 parent 0697252 commit 83251e5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,10 @@ onResize: ItemCallback,
// Calls when resize is complete.
onResizeStop: ItemCallback,
// Calls when some element has been dropped
onDrop: (elemParams: { x: number, y: number, w: number, h: number, e: Event }) => void
onDrop: (elemParams: { x: number, y: number, w: number, h: number, e: Event }) => void,

// Ref for getting a reference for the wrapping div.
innerRef: ?React.Ref
```
### Responsive Grid Layout Props
Expand Down
3 changes: 2 additions & 1 deletion lib/ReactGridLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
};

render() {
const { className, style, isDroppable } = this.props;
const { className, style, isDroppable, innerRef } = this.props;

const mergedClassName = classNames(layoutClassName, className);
const mergedStyle = {
Expand All @@ -693,6 +693,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {

return (
<div
ref={innerRef}
className={mergedClassName}
style={mergedStyle}
onDrop={isDroppable ? this.onDrop : noop}
Expand Down
9 changes: 7 additions & 2 deletions lib/ReactGridLayoutPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import PropTypes from "prop-types";
import React from "react";
import type {
Ref,
ChildrenArray as ReactChildrenArray,
Element as ReactElement
} from "react";
Expand Down Expand Up @@ -45,7 +46,8 @@ export type Props = {|
h: number,
e: Event
}) => void,
children: ReactChildrenArray<ReactElement<any>>
children: ReactChildrenArray<ReactElement<any>>,
innerRef?: Ref<"div">
|};

export default {
Expand Down Expand Up @@ -175,5 +177,8 @@ export default {
}
keys[child.key] = true;
});
}
},

// Optional ref for getting a reference for the wrapping div.
innerRef: PropTypes.any
};

0 comments on commit 83251e5

Please sign in to comment.