Skip to content

Commit

Permalink
Merge pull request #892 from lmachens/lm-fix-dynamic-remount
Browse files Browse the repository at this point in the history
fix: dynamic isDraggable and isResizable remount
  • Loading branch information
STRML committed Feb 10, 2020
2 parents 98f21c4 + 9c88df5 commit 59b0da6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions css/styles.css
Expand Up @@ -55,3 +55,7 @@
border-right: 2px solid rgba(0, 0, 0, 0.4);
border-bottom: 2px solid rgba(0, 0, 0, 0.4);
}

.react-resizable-hide > .react-resizable-handle {
display: none;
}
17 changes: 13 additions & 4 deletions lib/GridItem.jsx
Expand Up @@ -267,9 +267,13 @@ export default class GridItem extends React.Component<Props, State> {
* @param {Element} child Child element.
* @return {Element} Child wrapped in Draggable.
*/
mixinDraggable(child: ReactElement<any>): ReactElement<any> {
mixinDraggable(
child: ReactElement<any>,
isDraggable: boolean
): ReactElement<any> {
return (
<DraggableCore
disabled={!isDraggable}
onStart={this.onDragStart}
onDrag={this.onDrag}
onStop={this.onDragStop}
Expand All @@ -293,7 +297,8 @@ export default class GridItem extends React.Component<Props, State> {
*/
mixinResizable(
child: ReactElement<any>,
position: Position
position: Position,
isResizable: boolean
): ReactElement<any> {
const { cols, x, minW, minH, maxW, maxH, transformScale } = this.props;
const positionParams = this.getPositionParams();
Expand All @@ -311,6 +316,10 @@ export default class GridItem extends React.Component<Props, State> {
];
return (
<Resizable
draggableOpts={{
disabled: !isResizable
}}
className={isResizable ? undefined : "react-resizable-hide"}
width={position.width}
height={position.height}
minConstraints={minConstraints}
Expand Down Expand Up @@ -552,10 +561,10 @@ export default class GridItem extends React.Component<Props, State> {
});

// Resizable support. This is usually on but the user can toggle it off.
if (isResizable) newChild = this.mixinResizable(newChild, pos);
newChild = this.mixinResizable(newChild, pos, isResizable);

// Draggable support. This is always on, except for with placeholders.
if (isDraggable) newChild = this.mixinDraggable(newChild);
newChild = this.mixinDraggable(newChild, isDraggable);

return newChild;
}
Expand Down

0 comments on commit 59b0da6

Please sign in to comment.