Gathering detailed insights and metrics for react-rnd
Gathering detailed insights and metrics for react-rnd
Gathering detailed insights and metrics for react-rnd
Gathering detailed insights and metrics for react-rnd
@types/react-rnd
Stub TypeScript definitions entry for react-rnd, which provides its own types definitions
react-rnd-dragline
这是一个基于 react-rnd 实现的拖拽组件,在rnd的功能基础上增加了拖拽时显示辅助线及吸附的功能。
react-rnd-dragline-enhancement
这是一个基于 react-rnd 实现的拖拽组件,在rnd的功能基础上增加了拖拽时显示辅助线及吸附的功能。
react-rnd-mp
Based on react-rnd 9.1.2
🖱 A resizable and draggable component for React.
npm install react-rnd
Typescript
Module System
Node Version
NPM Version
92
Supply Chain
93.9
Quality
81.1
Maintenance
100
Vulnerability
99.6
License
TypeScript (90.81%)
JavaScript (7.95%)
Shell (0.54%)
HTML (0.41%)
CSS (0.29%)
Total Downloads
33,487,329
Last Day
12,286
Last Week
249,162
Last Month
1,060,817
Last Year
11,506,913
MIT License
4,093 Stars
791 Commits
333 Forks
22 Watchers
47 Branches
45 Contributors
Updated on May 02, 2025
Minified
Minified + Gzipped
Latest Version
10.5.2
Package Id
react-rnd@10.5.2
Unpacked Size
84.58 kB
Size
15.51 kB
File Count
9
NPM Version
10.8.2
Node Version
20.17.0
Published on
Feb 26, 2025
Cumulative downloads
Total Downloads
Last Day
1.9%
12,286
Compared to previous day
Last Week
-2.3%
249,162
Compared to previous week
Last Month
-9.2%
1,060,817
Compared to previous month
Last Year
56.3%
11,506,913
Compared to previous year
3
50
A resizable and draggable component for React.
https://codesandbox.io/s/xpm699v4lp
CodeSandbox(with default)
CodeSandbox(with size and position)
CodeSandbox(with typescript)
CodeSandbox(with hooks)
1npm i -S react-rnd
1yarn add react-rnd
default
1<Rnd 2 default={{ 3 x: 0, 4 y: 0, 5 width: 320, 6 height: 200, 7 }} 8> 9 Rnd 10</Rnd>
position
and size
1<Rnd 2 size={{ width: this.state.width, height: this.state.height }} 3 position={{ x: this.state.x, y: this.state.y }} 4 onDragStop={(e, d) => { this.setState({ x: d.x, y: d.y }) }} 5 onResizeStop={(e, direction, ref, delta, position) => { 6 this.setState({ 7 width: ref.style.width, 8 height: ref.style.height, 9 ...position, 10 }); 11 }} 12> 13 001 14</Rnd>
default: { x: number; y: number; width?: number | string; height?: number | string; };
The width
and height
property is used to set the default size of the component.
For example, you can set 300
, '300px'
, 50%
.
If omitted, set 'auto'
.
The x
and y
property is used to set the default position of the component.
size?: { width: (number | string), height: (number | string) };
The size
property is used to set size of the component.
For example, you can set 300, '300px', 50%.
Use size
if you need to control size state by yourself.
position?: { x: number, y: number };
The position
property is used to set position of the component.
Use position
if you need to control size state by yourself.
see, following example.
1<Rnd 2 size={{ width: this.state.width, height: this.state.height }} 3 position={{ x: this.state.x, y: this.state.y }} 4 onDragStop={(e, d) => { this.setState({ x: d.x, y: d.y }) }} 5 onResize={(e, direction, ref, delta, position) => { 6 this.setState({ 7 width: ref.offsetWidth, 8 height: ref.offsetHeight, 9 ...position, 10 }); 11 }} 12> 13 001 14</Rnd>
className?: string;
The className
property is used to set the custom className
of the component.
style?: { [key: string]: string };
The style
property is used to set the custom style
of the component.
minWidth?: number | string;
The minWidth
property is used to set the minimum width of the component.
For example, you can set 300
, '300px'
, 50%
.
minHeight?: number | string;
The minHeight
property is used to set the minimum height of the component.
For example, you can set 300
, '300px'
, 50%
.
maxWidth?: number | string;
The maxWidth
property is used to set the maximum width of the component.
For example, you can set 300
, '300px'
, 50%
.
maxHeight?: number | string
;The maxHeight
property is used to set the maximum height of the component.
For example, you can set 300
, '300px'
, 50%
.
resizeGrid?: [number, number];
The resizeGrid
property is used to specify the increments that resizing should snap to. Defaults to [1, 1]
.
dragGrid?: [number, number];
The dragGrid
property is used to specify the increments that moving should snap to. Defaults to [1, 1]
.
lockAspectRatio?: boolean | number;
The lockAspectRatio
property is used to lock aspect ratio.
Set to true
to lock the aspect ratio based on the initial size.
Set to a numeric value to lock a specific aspect ratio (such as 16/9
).
If set to numeric, make sure to set initial height/width to values with correct aspect ratio.
If omitted, set false
.
lockAspectRatioExtraWidth?: number;
The lockAspectRatioExtraWidth
property enables a resizable component to maintain an aspect ratio plus extra width.
For instance, a video could be displayed 16:9 with a 50px side bar.
If omitted, set 0
.
scale?: number;
Specifies the scale of the canvas you are dragging or resizing this element on. This allows
you to, for example, get the correct drag / resize deltas while you are zoomed in or out via
a transform or matrix in the parent of this element.
If omitted, set 1
.
lockAspectRatioExtraHeight?: number;
The lockAspectRatioExtraHeight
property enables a resizable component to maintain an aspect ratio plus extra height.
For instance, a video could be displayed 16:9 with a 50px header bar.
If omitted, set 0
.
dragHandleClassName?: string;
Specifies a selector to be used as the handle that initiates drag.
Example: handle
.
resizeHandleStyles?: HandleStyles;
The resizeHandleStyles
property is used to override the style of one or more resize handles.
Only the axis you specify will have its handle style replaced.
If you specify a value for right
it will completely replace the styles for the right
resize handle,
but other handle will still use the default styles.
1 2export type HandleStyles = { 3 bottom?: React.CSSProperties, 4 bottomLeft?: React.CSSProperties, 5 bottomRight?: React.CSSProperties, 6 left?: React.CSSProperties, 7 right?: React.CSSProperties, 8 top?: React.CSSProperties, 9 topLeft?: React.CSSProperties, 10 topRight?: React.CSSProperties 11}
resizeHandleClasses?: HandleClasses;
The resizeHandleClasses
property is used to set the className of one or more resize handles.
1type HandleClasses = { 2 bottom?: string; 3 bottomLeft?: string; 4 bottomRight?: string; 5 left?: string; 6 right?: string; 7 top?: string; 8 topLeft?: string; 9 topRight?: string; 10}
resizeHandleComponent?
: HandleCompoent;`The resizeHandleComponent
allows you to pass a custom React component as the resize handle.
1type HandleComponent = { 2 top?: React.ReactElement<any>; 3 right?: React.ReactElement<any>; 4 bottom?: React.ReactElement<any>; 5 left?: React.ReactElement<any>; 6 topRight?: React.ReactElement<any>; 7 bottomRight?: React.ReactElement<any>; 8 bottomLeft?: React.ReactElement<any>; 9 topLeft?: React.ReactElement<any>; 10}
resizeHandleWrapperClass?: string;
The resizeHandleWrapperClass
property is used to set css class name of resize handle wrapper(span
) element.
resizeHandleWrapperStyle?: Style;
The resizeHandleWrapperStyle
property is used to set css class name of resize handle wrapper(span
) element.
enableResizing?: ?Enable;
The enableResizing
property is used to set the resizable permission of the component.
The permission of top
, right
, bottom
, left
, topRight
, bottomRight
, bottomLeft
, topLeft
direction resizing.
If omitted, all resizer are enabled.
If you want to permit only right direction resizing, set { top:false, right:true, bottom:false, left:false, topRight:false, bottomRight:false, bottomLeft:false, topLeft:false }
.
1export type Enable = { 2 bottom?: boolean; 3 bottomLeft?: boolean; 4 bottomRight?: boolean; 5 left?: boolean; 6 right?: boolean; 7 top?: boolean; 8 topLeft?: boolean; 9 topRight?: boolean; 10} | boolean
disableDragging?: boolean;
The disableDragging
property disables dragging completely.
cancel?: string;
The cancel
property disables specifies a selector to be used to prevent drag initialization (e.g. .body
).
dragAxis?: 'x' | 'y' | 'both' | 'none'
The direction of allowed movement (dragging) allowed ('x','y','both','none').
bounds?: string; | Element
Specifies movement boundaries. Accepted values:
parent
restricts movement within the node's offsetParent
(nearest node with position relative or absolute)window
, body
, Selector like .fooClassName
orElement
.enableUserSelectHack?: boolean;
By default, we add 'user-select:none' attributes to the document body
to prevent ugly text selection during drag. If this is causing problems
for your app, set this to false
.
scale?: number;
Specifies the scale of the canvas your are resizing and dragging this element on. This allows
you to, for example, get the correct resize and drag deltas while you are zoomed in or out via
a transform or matrix in the parent of this element.
If omitted, set 1
.
onResizeStart?: RndResizeStartCallback;
RndResizeStartCallback
type is below.
1export type RndResizeStartCallback = ( 2 e: SyntheticMouseEvent<HTMLDivElement> | SyntheticTouchEvent<HTMLDivElement>, 3 dir: ResizeDirection, 4 refToElement: React.ElementRef<'div'>, 5) => void;
Calls when resizable component resize start.
onResize?: RndResizeCallback;
RndResizeCallback
type is below.
1export type RndResizeCallback = ( 2 e: MouseEvent | TouchEvent, 3 dir: ResizeDirection, 4 refToElement: React.ElementRef<'div'>, 5 delta: ResizableDelta, 6 position: Position, 7) => void;
Calls when resizable component resizing.
onResizeStop?: RndResizeCallback;
RndResizeCallback
type is below.
1export type RndResizeCallback = ( 2 e: MouseEvent | TouchEvent, 3 dir: ResizeDirection, 4 refToElement: React.ElementRef<'div'>, 5 delta: ResizableDelta, 6 position: Position, 7) => void;
Calls when resizable component resize stop.
onDragStart: DraggableEventHandler;
Callback called on dragging start.
1type DraggableData = { 2 node: HTMLElement, 3 x: number, 4 y: number, 5 deltaX: number, deltaY: number, 6 lastX: number, lastY: number 7}; 8 9type DraggableEventHandler = ( 10 e: SyntheticMouseEvent | SyntheticTouchEvent, data: DraggableData, 11) => void | false;
onDrag: DraggableEventHandler;
onDrag
called with the following parameters:
1type DraggableData = { 2 node: HTMLElement, 3 x: number, 4 y: number, 5 deltaX: number, deltaY: number, 6 lastX: number, lastY: number 7}; 8 9type DraggableEventHandler = ( 10 e: SyntheticMouseEvent | SyntheticTouchEvent, data: DraggableData, 11) => void | false;
onDragStop: DraggableEventHandler;
onDragStop
called on dragging stop.
1type DraggableData = { 2 node: HTMLElement, 3 x: number, 4 y: number, 5 deltaX: number, deltaY: number, 6 lastX: number, lastY: number 7}; 8 9type DraggableEventHandler = ( 10 e: SyntheticMouseEvent | SyntheticTouchEvent, data: DraggableData, 11) => void | false;
updateSize(size: { width: string | number, height: string | number })
Update component size.
For example, you can set 300
, '300px'
, 50%
.
1class YourComponent extends Component { 2 3 ... 4 5 update() { 6 this.rnd.updateSize({ width: 200, height: 300 }); 7 } 8 9 render() { 10 return ( 11 <Rnd ref={c => { this.rnd = c; }} ...rest > 12 example 13 </Rnd> 14 ); 15 } 16 ... 17}
updatePosition({ x: number, y: number }): void
Update component position.
grid
bounds
props is ignored, when this method called.
1class YourComponent extends Component { 2 3 ... 4 5 update() { 6 this.rnd.updatePosition({ x: 200, y: 300 }); 7 } 8 9 render() { 10 return ( 11 <Rnd ref={c => { this.rnd = c; }} ...rest > 12 example 13 </Rnd> 14 ); 15 } 16 17 ... 18}
allowAnyClick?: boolean
If set to true
, will allow dragging on non left-button clicks.
1npm t
If you have a feature request, please add it as an issue or make a pull request.
If you have a bug to report, please reproduce the bug in CodeSandbox to help us easily isolate it.
re-resizable
to 6.11.0
re-resizable
to 6.10.3
re-resizable
to 6.10.0
Fixes $945, When using vite and resizing from other than right and bottom - the element is shaking weirdly.
Upgrade re-resizable
to 6.9.17
Fixes #942, define callback refs inline to work with latest versions of Next.js / React.
re-resizable
to 6.9.14
maxHeight
does not work with %
#914re-resizable
to 6.9.11
react-draggable
to 4.4.6
onDrag
#910re-resizable
to 6.9.6
re-resizable
to 6.9.2
react-draggable
to v4.4.4re-resizable
to 6.9.1
px
, reize dowes not work. #739react-draggable
to v4.4.3allowAnyClick
props.nodeRef
props.react-draggable
to v4.2.0 #690react-draggable
to v4.3.1re-resizable
to v6.3.2onMouseUp
callback.React.pureComponent
re-resizablev5
scale
props to index.js.flow.scale
props. #482default export
to export
#405bounds
is ignored when lock aspect ratio set.body
to bounds props.window
. you can check here.<Rnd onMouseDown={...} />
dragHandleClassName
automatically, Please pass string (i.e handle
.extendsProps
. Please add extends props directly. i.e) <Rnd data-foo="42" />
z
props. Please add zIndex
via style
props. i.e) <Rnd style={{ zIndex: 9 }} />
re-resizable
to fix percentage size and bare behavior.typescript
instead of flowype
.<div />
, isMounted
state and setParentPosition()
.props,children
to dummy <div>
to render children in first.fix: isMounted
and (!this.state.isMounted) return <div />
line #356
enableUserSelectHack?: boolean;
.extendProps
is not passed correctly.bounds
is not work correctly. (#162)size
.position
.default
instead of x
, y
, width
, height
.resizeHandleWrapperClass
and resizeHandleWrapperStyle
.default
and add x
, y
, width
, height
.dragHandlersXXXX
and resizeHandlersXXXX
props to dragHandleXXXX
and resizeHandleXXXX
.normal
to cursor style when dragHandlerClassName
is not empty.relative
when component will update.top: 0
, left: 0
.relative
when parent position equals static
.react-draggable v3
, flow-bin v0.53
, and other...)z
props is not applied to state.extendsProps
. #129disableDragging
props.updateZIndex
.updateSize
.react-draggable
.updateZIndex
, method to updated component zIndex
state.react-rnd
.canUpdatePositionByParent
property.canUpdateSizeByParent
property.initiAsResizing
property.x
, y
, width
and height
property to initial
.updateSize
, updatePosition
, method to updated conponent state.lockAspectRatio
property to lock aspect ratio when resizing.canUpdatePositionByParent
property.grid
props to snap grid. (thanks @paulyoung)canUpdateSizeByParent
props #38require
The MIT License (MIT)
Copyright (c) 2018 bokuweb
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
7 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5
Reason
Found 5/23 approved changesets -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
51 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-04-28
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More