Git Product home page Git Product logo

react-resizable's Introduction

React-Resizable

View the Demo

A simple widget that can be resized via one or more handles.

You can either use the <Resizable> element directly, or use the much simpler <ResizableBox> element.

See the example and associated code in ExampleLayout and ResizableBox for more details.

Make sure you use the associated styles in /css/styles.css, as without them, you will have problems with handle placement and visibility.

You can pass options directly to the underlying DraggableCore instance by using the prop draggableOpts. See the demo for more on this.

Installation

$ npm install --save react-resizable

Compatibility

React-Resizable 3.x is compatible with React >= 16.3. React-Resizable 2.x has been skipped. React-Resizable 1.x is compatible with React 14-17.

Usage

This package has two major exports:

  • <Resizable>: A raw component that does not have state. Use as a building block for larger components, by listening to its callbacks and setting its props.
  • <ResizableBox>: A simple <div {...props} /> element that manages basic state. Convenient for simple use-cases.

<Resizable>

const {Resizable} = require('react-resizable');

// ES6
import { Resizable } from 'react-resizable';

// ...
class Example extends React.Component {
  state = {
    width: 200,
    height: 200,
  };

  // On top layout
  onResize = (event, {node, size, handle}) => {
    this.setState({width: size.width, height: size.height});
  };

  render() {
    return (
      <Resizable height={this.state.height} width={this.state.width} onResize={this.onResize}>
        <div className="box" style={{width: this.state.width + 'px', height: this.state.height + 'px'}}>
          <span>Contents</span>
        </div>
      </Resizable>
    );
  }
}

<ResizableBox>

const {ResizableBox} = require('react-resizable');

// ES6
import { ResizableBox } from 'react-resizable';

class Example extends React.Component {
  render() {
    return (
      <ResizableBox width={200} height={200} draggableOpts={{grid: [25, 25]}}
          minConstraints={[100, 100]} maxConstraints={[300, 300]}>
        <span>Contents</span>
      </ResizableBox>
    );
  }
}

Props

These props apply to both <Resizable> and <ResizableBox>. Unknown props that are not in the list below will be passed to the child component.

type ResizeCallbackData = {
  node: HTMLElement,
  size: {width: number, height: number},
  handle: ResizeHandleAxis
};
type ResizeHandleAxis = 's' | 'w' | 'e' | 'n' | 'sw' | 'nw' | 'se' | 'ne';

type ResizableProps =
{
  children: React.Element<any>,
  width: number,
  height: number,
  // Either a ReactElement to be used as handle, or a function returning an element that is fed the handle's location as its first argument.
  handle: ReactElement<any> | (resizeHandle: ResizeHandleAxis, ref: ReactRef<HTMLElement>) => ReactElement<any>,
  // If you change this, be sure to update your css
  handleSize: [number, number] = [10, 10],
  lockAspectRatio: boolean = false,
  axis: 'both' | 'x' | 'y' | 'none' = 'both',
  minConstraints: [number, number] = [10, 10],
  maxConstraints: [number, number] = [Infinity, Infinity],
  onResizeStop?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any,
  onResizeStart?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any,
  onResize?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any,
  draggableOpts?: ?Object,
  resizeHandles?: ?Array<ResizeHandleAxis> = ['se']
};

The following props can also be used on <ResizableBox>:

{
  style?: Object // styles the returned <div />
}

If a width or height is passed to <ResizableBox>'s style prop, it will be ignored as it is required for internal function.

Resize Handle

If you override the resize handle, we expect that any ref passed to your new handle with represent the underlying DOM element.

This is required, as react-resizable must be able to access the underlying DOM node to attach handlers and measure position deltas.

There are a few ways to do this:

Native DOM Element

This requires no special treatment.

<Resizable handle={<div className="foo" />} />
Custom React Component

You must forward the ref and props to the underlying DOM element.

Class Components
class MyHandleComponent extends React.Component {
  render() {
    const {handleAxis, innerRef, ...props} = this.props;
    return <div ref={innerRef} className={`foo handle-${handleAxis}`} {...props} />
  }
}
const MyHandle = React.forwardRef((props, ref) => <MyHandleComponent innerRef={ref} {...props} />);

<Resizable handle={<MyHandle />} />
Functional Components
const MyHandle = React.forwardRef((props, ref) => {
  const {handleAxis, ...restProps} = props;
  return <div ref={ref} className={`foo handle-${handleAxis}`} {...restProps} />;
});

<Resizable handle={<MyHandle />} />
Custom Function

You can define a function as a handle, which will simply receive an axis (see above ResizeHandleAxis type) and ref. This may be more clear to read, depending on your coding style.

const MyHandle = (props) => {
  return <div ref={props.innerRef} className="foo" {...props} />;
};

<Resizable handle={(handleAxis, ref) => <MyHandle innerRef={ref} className={`foo handle-${handleAxis}`} {...props} />} />

react-resizable's People

Contributors

amilajack avatar antonsapyanov avatar ardaorkin avatar armedi avatar ayozebarrera avatar cheton avatar conorkelleher avatar danielecina avatar daviferreira avatar dependabot[bot] avatar dnissley-al avatar eden-chan avatar finalfreq avatar frankhassanabad avatar h0jezvgoxfepbq2c avatar kevinahuber avatar mdogadailo avatar mitermayer avatar rnicholus avatar roccoc avatar sanfilippopablo avatar simzar avatar strml avatar urakozz avatar xcqwan avatar zachsa avatar zillding avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-resizable's Issues

onResizeStart event object is invalid

When I try to use the event object on onResizeStart, it throws the following warning

warning.js:19 Warning: This synthetic event is reused for performance reasons. If you're seeing this, you're accessing the method `preventDefault` on a released/nullified synthetic event. This is a no-op function. If you must keep the original synthetic event around, use event.persist(). See https://fb.me/react-event-pooling for more information.

For some reason, the onResizeStart event is a Proxy Event object. So it must be persisted to avoid this kind of problem.

Upgrade to React 0.14

When using with React 0.14.x, we get the findDOMNode deprecation warning:

Warning: React.findDOMNode is deprecated. Please use ReactDOM.findDOMNode from require('react-dom') instead.

This is caused by react-draggable, and it only checks for SVG nodes:

componentDidMount: function() {
    // Check to see if the element passed is an instanceof SVGElement
    if( React.findDOMNode(this) instanceof SVGElement) {
        this.setState({ isElementSVG: true });
    }
}

I already tried to fork and upgrade in order to submit a pull request, however, I am getting the weird duplicate-react-error:

If you're seeing this message, it probably means that you've loaded two copies of React on the page.

I guess I would need to fork both react-draggable and react-resizable, and from what I read about the error, define react as a peerDependency (instead of devDependency).

However, you know your projects way better than I do :) so I hope you will upgrade to react 0.14 soon!

Greater flexibility of react-resizable-handle?

Thanks for opening an issue!

Please select the type of issue you're reporting. For questions.

  • Bug
  • Feature Request
  • Question

Problem Report

I'd like more control over the <span class="react-resizable-handle"></span> element i.e. be able to move it outside the main .react-resizable wrapper, change the HTML/class name.

System Info

Node Version: 8.1.2
Browser: Chrome 58.0
OS: macOS 10.12.5

License

Hello, first of all thank you for awesome work!

Could you please add license and/or license file for this repository?

Width and Height are now opaque

Since 5da49c6 width and height is not passed to the component's children.

I previously used these properties to debounce an heavy operation inside the container and performed some extra transformations as well.

Are you committed to not leaking these properties and only exposing the style with the computed strings?

Demo is broken

Thanks for opening an issue!

Please select the type of issue you're reporting. For questions.

  • Bug
  • Feature Request
  • Question

Problem Report

The demo doesn't work. Browser console gives me the following message.

Error: Module build failed: ReferenceError: Unknown plugin "transform-flow-comments" specified...

System Info

Browser: Firefox and Chrome
OS: Win 10

Reproduction

Just go to the demo page at https://strml.github.io/react-resizable/examples/1.html

Flow error with flow 0.46 and react-resizable 1.7.1

Thanks for opening an issue!

Please select the type of issue you're reporting. For questions.

  • Bug
  • Feature Request
  • Question

Problem Report

I get an error with flow with flow 0.46 (I also checked 0.45 and there are the same errors) and react-resizable 1.7.1. If you'd like I could make a PR to update the flow types in these files. Thanks!

System Info

Node Version: 7.7.4
Browser:
OS: macOS

Reproduction

Here is my flow output:

node_modules/react-resizable/build/ResizableBox.js.flow:55
           v---------
 55:       <Resizable
 56:         handleSize={handleSize}
 57:         width={this.state.width}
...:
 67:         >
             ^ React element `Resizable`
 81:   props: Props;
              ^^^^^ property `children`. Property not found in. See: node_modules/react-resizable/build/Resizable.js.flow:81
           v---------
 55:       <Resizable
 56:         handleSize={handleSize}
 57:         width={this.state.width}
...:
 67:         >
             ^ props of React element `Resizable`

node_modules/react-resizable/build/ResizableBox.js.flow:55
           v---------
 55:       <Resizable
 56:         handleSize={handleSize}
 57:         width={this.state.width}
...:
 67:         >
             ^ props of React element `Resizable`
 56:         handleSize={handleSize}
                         ^^^^^^^^^^ tuple type. This type is incompatible with
 84:     handleSize: [20, 20],
                     ^^^^^^^^ array literal. See: node_modules/react-resizable/build/Resizable.js.flow:84

node_modules/react-resizable/build/ResizableBox.js.flow:55
           v---------
 55:       <Resizable
 56:         handleSize={handleSize}
 57:         width={this.state.width}
...:
 67:         >
             ^ props of React element `Resizable`
 63:         minConstraints={minConstraints}
                             ^^^^^^^^^^^^^^ tuple type. This type is incompatible with
 87:     minConstraints: [20, 20],
                         ^^^^^^^^ array literal. See: node_modules/react-resizable/build/Resizable.js.flow:87

node_modules/react-resizable/build/ResizableBox.js.flow:55
           v---------
 55:       <Resizable
 56:         handleSize={handleSize}
 57:         width={this.state.width}
...:
 67:         >
             ^ props of React element `Resizable`
 64:         maxConstraints={maxConstraints}
                             ^^^^^^^^^^^^^^ tuple type. This type is incompatible with
 88:     maxConstraints: [Infinity, Infinity]
                         ^^^^^^^^^^^^^^^^^^^^ array literal. See: node_modules/react-resizable/build/Resizable.js.flow:88

Update react-draggable dependency?

react-resizable is always providing its own node_modules folder in my build.
In there it keeps the react-draggable dependency. Then I have to manually delete the
node_modules/react-resizable/node_modules folder before my build works.

--> I think updating the react-draggable dependency might fix the problem but I'm quite confused how dependencies work exactly with npm3. Is it possible to update to the latest version of react-draggable?

ResizableBox onResize

I can't get the event firing... how works this?

<ResizableBox height={300} width={350} onResize={this.resize}>
  {content}
</ResizableBox>

my function resize() should log in the console.. but never gets fired

weird behavior when working with the onResizeStart/Stop props

It seem that there is a weird issue where the resizable doesn't correctly resize when using the onResizeStart and onResizeStop props. I use the handle and on the drag it immediately changes the div to a height and width that are way too large.

Here is a minimal test case:

'use strict';
var React = require('react');
var Resizable = require('react-resizable').Resizable;
require('!style!css!./css/style.css');


var Bugtest = React.createClass({
  getInitialState: function() {
    return {
      width: 300,
      height: 300,
      resizing: false
    };
  },
  onResizeStart: function() {
    this.setState({resizing: true});
  },
  onResizeStop: function() {
    this.setState({resizing: false});
  },
  onResize: function(event, {element, size}) {
    this.setState({width: size.width, height: size.height});
  },
  render: function() {
    return (
      <Resizable height={this.state.height} width={this.state.width} 
        style={{
          width: this.state.width + 'px', 
          height: this.state.height + 'px',
          backgroundColor: "blue",
          position: "absolute"
        }} 
        onResize={this.onResize} 
        onResizeStart={this.onResizeStart} 
        onResizeStop={this.onResizeStop}>
          <div> </div>
      </Resizable>
    )
  }

});

React.render(<Bugtest />, document.getElementById('content'));

you have to use the standard css in the package to use this example.

Tested that the same bug occurs in firefox, chrome, opera and internet explorer.

Drag handle can be made semi-non-functional on components with size constraints

Environment:
Chrome 47 on OS X, using a clean checkout & build of HEAD

Steps to reproduce:

  1. on examples/1.html, find the "Resizable box, starting at 200x200. Min size is 150x150, max is 500x300." box
  2. On that box, drag the resize handle up and left until the box no longer shrinks, continuing to drag to about the middle of the box
  3. Repeat step 2 several times
  4. Now, try to drag the resize handle down and right

Expected results:
Box should grow normally

Actual results:
Box does not resize

Workaround:
If you keep repeating step 4 until you've moved roughly the same cumulative distance that you did in step 3, it'll eventually start to work normally again.

Hypothesis:
There's some state internal to Resizable or its Draggable handle that doesn't properly respect state.bounds. However, the source of the bug wasn't obvious within an hour's debugging.

Styles props

Thanks for opening an issue!

Please select the type of issue you're reporting. For questions.

  • Bug
  • Feature Request
  • Question

Problem Report

Would be nice to send dynamic styles props into the box. I have dynamic margins that I cannot set via classes, and I'm stuck.

System Info

Node Version:
Browser:
OS:

Reproduction

If this is a bug report, please provide a reproduction of the issue by going to
http://www.webpackbin.com/41YFBvekG.
Paste a link here to your working reproduction.

Preview of the resize

I'm developing a desktop on a webapp and your components works well.

But, in one of the window of my app, I have a lot of icons (like 300) and when I resize the perfomance isn't good..

So, as suggestion, I'll consider a way to do the resize with a preview (imagine just a div transparent on the top of the window, absoluted, updating the props with state) and on the onResizeStop we could update the window.

Hope I explained.
Tell me what do you think about this.

See ya.

Why is width a required prop?

Thanks for opening an issue!

Please select the type of issue you're reporting. For questions.

  • Bug
  • Feature Request
  • Question

Problem Report

I don't have width set on my Resizable because it is a full-width bar with only the y axis resizable.

It works fine, but I get a React warning about this. I can't set it to '100%' either since it requires a number.

Is this prop actually required in my case (doesn't seem to be) and if not can it be marked as such?

screen shot 2017-06-23 at 15 03 21

System Info

Node Version: v6.11.0
Browser: Chrome 59.0
OS: macOS 10.12.5

Reduce css size (bytes) of resize-handle

  • Bug
  • Feature Request
  • Question

Problem Report

You can reduce the number of bytes of the resize-handle:
https://github.com/STRML/react-resizable/blob/master/css/styles.css#L10

By reducing the extra information encoded inside of it.

Right now when you decoded it using atob:

atob("PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pg08IS0tIEdlbmVyYXRvcjogQWRvYmUgRmlyZXdvcmtzIENTNiwgRXhwb3J0IFNWRyBFeHRlbnNpb24gYnkgQWFyb24gQmVhbGwgKGh0dHA6Ly9maXJld29ya3MuYWJlYWxsLmNvbSkgLiBWZXJzaW9uOiAwLjYuMSAgLS0+DTwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DTxzdmcgaWQ9IlVudGl0bGVkLVBhZ2UlMjAxIiB2aWV3Qm94PSIwIDAgNiA2IiBzdHlsZT0iYmFja2dyb3VuZC1jb2xvcjojZmZmZmZmMDAiIHZlcnNpb249IjEuMSINCXhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHhtbDpzcGFjZT0icHJlc2VydmUiDQl4PSIwcHgiIHk9IjBweCIgd2lkdGg9IjZweCIgaGVpZ2h0PSI2cHgiDT4NCTxnIG9wYWNpdHk9IjAuMzAyIj4NCQk8cGF0aCBkPSJNIDYgNiBMIDAgNiBMIDAgNC4yIEwgNCA0LjIgTCA0LjIgNC4yIEwgNC4yIDAgTCA2IDAgTCA2IDYgTCA2IDYgWiIgZmlsbD0iIzAwMDAwMCIvPg0JPC9nPg08L3N2Zz4=")

You get:

<?xml version="1.0" standalone="no"?>
<!-- Generator: Adobe Fireworks CS6, Export SVG Extension by Aaron Beall (http://fireworks.abeall.com) . Version: 0.6.1  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg id="Untitled-Page%201" viewBox="0 0 6 6" style="background-color:#ffffff00" version="1.1"
	xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve"
	x="0px" y="0px" width="6px" height="6px"
>
	<g opacity="0.302">
		<path d="M 6 6 L 0 6 L 0 4.2 L 4 4.2 L 4.2 4.2 L 4.2 0 L 6 0 L 6 6 L 6 6 Z" fill="#000000"/>
	</g>
</svg>

You can use a more compact version of:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 6 6" style="background-color:#ffffff00" x="0px" y="0px" width="6px" height="6px"><g opacity="0.302"><path d="M 6 6 L 0 6 L 0 4.2 L 4 4.2 L 4.2 4.2 L 4.2 0 L 6 0 L 6 6 L 6 6 Z" fill="#000000"/></g></svg>

which will then give you an encoding of:

PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2IDYiIHN0eWxlPSJiYWNrZ3JvdW5kLWNvbG9yOiNmZmZmZmYwMCIgeD0iMHB4IiB5PSIwcHgiIHdpZHRoPSI2cHgiIGhlaWdodD0iNnB4Ij48ZyBvcGFjaXR5PSIwLjMwMiI+PHBhdGggZD0iTSA2IDYgTCAwIDYgTCAwIDQuMiBMIDQgNC4yIEwgNC4yIDQuMiBMIDQuMiAwIEwgNiAwIEwgNiA2IEwgNiA2IFoiIGZpbGw9IiMwMDAwMDAiLz48L2c+PC9zdmc+

which is much smaller.

PR: horizontal and vertical resize handler supported

Thanks for opening an issue!

Please select the type of issue you're reporting. For questions.

  • Bug
  • Feature Request
  • Question

Problem Report

  • For more friendly interactions, offer horizontal and vertical resize handlers.
  • ResizeCallbackData add an extra param axis, shows which direction that user now resize in.
  •    <ResizableBox onResize={(event, { element, size, axis}) => {...}} />

screen shot 2017-09-11 at 9 53 18 am

Constraints

I'm having a problem with the constraints:

I'm using React DnD (drag'n'drop) + React resizable to make a virtual desktop. When I open a Window, it has the two components and works fine except in the second render. (why a second render?)

When I drag the Window, the component dissapears, because I'm using a custom drag preview. So when we finish the drag, the preview dissapears, giving the place to the Window component.

I have the state of the window (width and height) to update the preview.

So, If I have a minConstraints={[300, 300]} and width={400} height={400} with the first render, works fine, but when I resize the window (lets say to width 800) and then drag, when its re-render if I resize the window, works fine except I can only resize to 800-300..

I think the key is the state bounds object.

Its like in the first render, it calculated how much you can resize to each direction... and I need a minWidth minHeight or something like that..

Maybe I'm totally wrong.. so I want your opinion ^^

Sorry If I didn't talk clearly ๐Ÿ˜„

size constraints take precedence over aspect ratio

Thanks for opening an issue!

Please select the type of issue you're reporting. For questions.

  • Bug
  • Feature Request
  • Question

Problem Report

When you specify both min/max constraints and lockAspectRatio and the constraints are not in the aspect ratio then you can resize the pane to the wrong aspect. That's to say: you can always resize in the full constraint range even if this violates the aspect ratio constraint.
I think intuitively the aspect ratio should always be obeyed even this limits the resizeable range.

In my use case the initial width/height is computed based on the data being displayed (an image) whereas the min/max are computed based on the available space so the min/max will not be in the same ratio. Of course I could manually recalculate min/max such that it has the same ratio but it would be cleaner if react-resizable did that for me.

System Info

Node Version: 6.5
Browser: electron 1.4.3
OS: Windows

Issue with minWidth/minHeight

I've got a problem with changing the size of the panel when the panel has min size.

If you make an item size smaller than the min size and mouse up, then you try to re-change the size - resize occurs only when there is a significant deviation from the original mouse position.

You can see it here http://screencast.com/t/ppth3vi94vj

onResize is not getting the element being resized.

Thanks for opening an issue!

Please select the type of issue you're reporting. For questions.

  • Question

Problem Report

I am using the component to resize three different divs in the same page. How do I get to know which Resizable element is being resized.

onResize(event,{element, size})
The element variable in this callBack is undefined.

System Info

Node Version: 6.5.0
Browser: working with electron app
OS: Win 10

ResizableBox can be resized only once with touch screen

Hi STRML,
First I want to thank you for your great work.
I'm using react-resizable. It works fine with mouse events but ResizableBox can be resized only once with touch screen(tested Chrome49+Windows10, and safari+iOS 9.3.1). I traced the error and it happens in Resizable.js line 125 and 126. When a touch event is ended, deltaX and deltaY are NaN. I simply added some code to convert NaN to 0, then it works fine.
Another issue is that the resize event doesn't prevent default touch event. When I use a touch screen to resize ResizableBox, the page scrolls when the box is been resizing. I used 'react-tappable'() to wrap the ResizableBox, then it works very well with touch screen. I think it's better if you can add a property to ResizableBox which can prevent default touch event.

Remove required "width" prop

I'm intentionally not setting a width prop and receiving (understandably) the warning:

Warning: Failed propType: Required propwidthwas not specified inResizable. Check the render method ofResizableBox.. My use-case is that I only want something vertically resizable so I need the width of the element to span the width of the parent, ie. 100%, so I don't really want/need to pass a width.

How to specify Resizable component on onResize function ?

  • Bug
  • Feture Request
  • Question

Problem Report

Hi,
I am beginner for React though,
I would like to know how to specify the object which is resizing on onResize function
when the React.Component has multiple Resizable components.

onResize handler seems pass event, node and size as arguments in the current implementation,
however, I could not specify the object which is resizing on onResize handler.

To solve this problem, I forked this repo then add new commit on my side.

https://github.com/yayoc/react-resizable/commit/52405a536e7c2f0e0fb6962fbba7915900d4e13c

I'm not sure this implementation is a better way.
Please let me know what your idea about this.

If this commit is satisfied your idea, I will create PR.

Thanks.

Readme Links Not Working

Thanks for opening an issue!

Please select the type of issue you're reporting. For questions.

  • [x ] Bug
  • Feature Request
  • Question

Problem Report

The readme links do not work, because they reference a jsx file, which was probably switched to js without updating the links.

System Info

N/A

Reproduction

Click on the example links in the readme

Update documentation to more clearly describe how to programmatically set height or width in a ResizableBox

I use react-resizable to resize a div vertically and the way I was trying to programmatically set the width and height of the box was to force it's parent to unmount and mount it again by changing the key like this: <ResizableBox ... key={this.props.height} />

This however gave me the following console error on every drag and drop resize: Uncaught Invariant Violation: findDOMNode was called on an unmounted component.

While experimenting, I later realized that the only thing you need to do is set the height and/or width as a css declaration (inline javascript style in my case) and everything was fine. This line solved everything: 'style={{height: this.state.height}}'

I can finally programmatically set the height of the component using a textbox.

My component now looks something like this

<ResizableBox 
    width={defaultWidth}
    height={this.props.height}
    onResizeStop={(e, obj) => this.onResizeStop(e, obj)}
    onResize={(e, obj) => this.onResize(e, obj)}
    draggableOpts={{onMouseDown:(e) => e.preventDefault()}/*to prevent dragging the whole component*/}
    style={{height: this.state.height}}
></ResizableBox>

Flow type errors: handleSize, minConstraints, maxConstraints

Thanks for opening an issue!

Please select the type of issue you're reporting. For questions.

  • Bug
  • Feature Request
  • Question

Problem Report

See reproduction below.

System Info

Node Version: 6.10.2
Browser: n/a
OS: OS X

Reproduction

When trying to use in a flow type enabled project I experience these errors:

node_modules/react-resizable/build/ResizableBox.js.flow:55
           v---------
 55:       <Resizable
 56:         handleSize={handleSize}
 57:         width={this.state.width}
...:
 67:         >
             ^ props of React element `Resizable`
 56:         handleSize={handleSize}
                         ^^^^^^^^^^ tuple type. This type is incompatible with
 84:     handleSize: [20, 20],
                     ^^^^^^^^ array literal. See: node_modules/react-resizable/build/Resizable.js.flow:84

node_modules/react-resizable/build/ResizableBox.js.flow:55
           v---------
 55:       <Resizable
 56:         handleSize={handleSize}
 57:         width={this.state.width}
...:
 67:         >
             ^ props of React element `Resizable`
 63:         minConstraints={minConstraints}
                             ^^^^^^^^^^^^^^ tuple type. This type is incompatible with
 87:     minConstraints: [20, 20],
                         ^^^^^^^^ array literal. See: node_modules/react-resizable/build/Resizable.js.flow:87

node_modules/react-resizable/build/ResizableBox.js.flow:55
           v---------
 55:       <Resizable
 56:         handleSize={handleSize}
 57:         width={this.state.width}
...:
 67:         >
             ^ props of React element `Resizable`
 64:         maxConstraints={maxConstraints}
                             ^^^^^^^^^^^^^^ tuple type. This type is incompatible with
 88:     maxConstraints: [Infinity, Infinity]
                         ^^^^^^^^^^^^^^^^^^^^ array literal. See: node_modules/react-resizable/build/Resizable.js.flow:88

Resizable nested inside of draggable creates drag with resize handler

Given the following code:

<Draggable bounds="parent">
  <Resizable className="box" width={150} height={150} onResizeStart={this.onStart}>
    <div style={{width: '150px', height: '150px' }}>Test</div>
  </Resizable>
</Draggable>

Where <Draggable /> is the react-draggable module, when resizing using the react-resizable-handle, it also triggers the drag of the parent element. Is this an issue or is there a way to 'cancel' the resize from bubbling upwards to the parent draggable?

Supplying percentage to width prop in <Resizable>

Thanks for opening an issue!

Please select the type of issue you're reporting. For questions.

  • Question

Problem Report

How can I supply to a percentage value to the width prop like "50%" as the width only accepts a number and not a string.
Thanks!

Touch screen laptop chrome Cannot read property '0' of undefined

When attempting to resize on the demo page with chrome browser on a laptop that has support for touch screen i get the following error:

I get the error

Uncaught TypeError: Cannot read property '0' of undefined

function getControlPosition(e) {
      var position = !isTouchDevice ? e : e.touches[0];
      return {
        clientX: position.clientX,
        clientY: position.clientY
      }
}

100% or full width

Thanks for opening an issue!

Please select the type of issue you're reporting. For questions.

  • Bug
  • Feature Request
  • Question

Problem Report

Would love a 100% width option. I want my box to start at the full width of the screen.

System Info

Node Version: 6.5.0
Browser: Chrome
OS: macOS 10.12.4

Reproduction

If this is a bug report, please provide a reproduction of the issue by going to
http://www.webpackbin.com/41YFBvekG.
Paste a link here to your working reproduction.

resizing elements on left border causes random jumping

I have a resizable div which is float: right. The handler is on the left side. Everything works fine when the handler is on the right side but I'm having some troubles with the one on the right.

The following gif shows two screens. One, where the resizable is floating left and one where it's floating right. The floating left example is included to show you that it generally works.

jumpingstuff

After some debugging and seeing that it works fine if I scale the inner element only, I believe that the issue is caused because the origin of the element wrapping resizeable (which is top left I guess?) changes:

jumpingstuff3

In pseudocode, the react structure of the borken example is:

<div width="123px" float="right">
  <ReactResizable>
      <children />
  </ReactResizable>
</div>

The react structure of the example without jumping is:

<div float="right">
  <ReactResizable>
    <div width="123px">
      <children />
    </div>
  </ReactResizable>
</div>

The cause for the jumping is that in onResize(event, { size }) { console.log(size) }, size.width fires random widths, as seen in the console:

jumpingstuff4

So - how is it possible to resize an element to the right?

Does not work in IE11

Under IE11, it throws an exception at the line 27158 of bundle.js because touches is undefined:

      var position = !isTouchDevice ? e : e.touches[0];

The problem comes from the fact isTouchDevice is true although I'm not on a touch device. Turning it to false makes everything working fine. I suggest improving the following piece of code using navigator.msMaxTouchPoints:

        var isTouchDevice = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0));

See latest update on http://stackoverflow.com/questions/4817029/whats-the-best-way-to-detect-a-touch-screen-device-using-javascript

Resizable and Draggable

Is it possible to have an element be resizable and generally resizable as well? i.e the width and height can be changed as in the demo, but the element also dragged around?

<ResizableBox
  className={ this.props.className }
  draggableOpts={{
    start: { x: this.props.frame.x, y: this.props.frame.y },

    grid: [25, 25],
    onStop: this.handleDragStop
  }}
  width={ this.props.frame.w }
  height={ this.props.frame.h === 'auto' ? 100 : this.props.frame.h }
  minConstraints={[100, 100]}>
    <span>Some markup</span>
</ResizableBox>

LICENSE available?

Thanks for opening an issue!

Please select the type of issue you're reporting. For questions.

  • [ X] Question

Problem Report

Is there a LICENSE available - similar to react-grid-layout? I need to be able to take a screenshot of the repository showing LICENSE in the file list. Thanks. Or, since I am using react-grid-layout, does having that license cover react-resizable?

ResizeableBox onResize event

I'm trying to handle the onResize event in a ResizableBox

I have it defined like

<ResizableBox onResize={this.resizeHandler} ...

And a function called resizeHandler()

But the event isn't firing. Do I need to handle the events some other way? I couldn't see an example in the tests/docs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.