Comments (2)
After some trial and error, I managed to create the following React wrapper for my project, and by importing @viselect/vanilla, I was able to workaround the issue mentioned above.
SelectionArea.js
/* eslint-disable no-use-before-define */
import VanillaSelectionArea from '@viselect/vanilla'
import React from 'react'
export default function SelectionArea (props) {
const { onBeforeStart, onBeforeDrag, onStart, onMove, onStop, ...opt } = props
const root = React.createRef()
const onBeforeStartRef = React.useRef()
const onBeforeDragRef = React.useRef()
const onStartRef = React.useRef()
const onMoveRef = React.useRef()
const onStopRef = React.useRef()
React.useEffect(() => {
onBeforeStartRef.current = onBeforeStart
onBeforeDragRef.current = onBeforeDrag
onStartRef.current = onStart
onMoveRef.current = onMove
onStopRef.current = onStop
})
React.useEffect(() => {
const areaBoundaries = root.current
const selection = new VanillaSelectionArea({
boundaries: areaBoundaries,
...opt
})
onBeforeStart && selection.on('beforeStart', (event) => {
if (onBeforeStartRef.current) {
onBeforeStartRef.current(event)
}
})
onBeforeDrag && selection.on('beforedrag', (event) => {
if (onBeforeDragRef.current) {
onBeforeDragRef.current(event)
}
})
onStart && selection.on('start', (event) => {
if (onStartRef.current) {
onStartRef.current(event)
}
})
onMove && selection.on('move', (event) => {
if (onMoveRef.current) {
onMoveRef.current(event)
}
})
onStop && selection.on('stop', (event) => {
if (onStopRef.current) {
onStopRef.current(event)
}
})
return () => selection.destroy()
}, [])
return (
React.createElement('div', { ref: root, className: props.className, id: props.id }, props.children)
)
}
I believe it would look like this in TypeScript:
https://gist.github.com/enawork/84c0d88fb2e34ed232dbeeb603fedd9c#file-selectionarea-tsx
from selection.
Thanks for the elaborative feature request, I'll label this as a bug since I would expect this to be reactive either way... I'll take a look at it :)
from selection.
Related Issues (20)
- Scrolling issues when inside a container that overflows HOT 7
- Specifying document breaks the options HOT 2
- Sequenced selections are buggy HOT 5
- Warning: Invalid hook call. Hooks can only be called inside of the body of a function component HOT 1
- Could not find a declaration file for module '@viselect/react' HOT 3
- How can I use "selection" in VUE2 project? HOT 1
- Already selected items became deselected on page scrolling HOT 3
- How can we stop selection while AltKey pressed ?
- Can I get access to the store so I can clear selection when pressing Escape HOT 5
- TS7016: Could not find a declaration file for module @viselect/react . HOT 1
- Is it possible to change the selection area initial position? HOT 1
- TypeScript Error: Unable to Find Declaration File for @viselect/react Module in Next.js Project HOT 1
- Extend config and implementation to allow for choice of mouse-buttons that activate the selection-area HOT 1
- Selection area does not expand when scrolling with keyboard
- TypeError: n.__ is not a function when rendering the Component HOT 4
- Demos no longer working, codesandbox has no more credits HOT 2
- React package doesn't support changes to props HOT 2
- STOP event triggers twice
- Unselect selected elements on blur HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from selection.