Comments (6)
Hi @mooijtech thanks for the question. I think you can accomplish what you want by using the tree.selectById(id, true) method, and the state.isSelected parts of the NodeRenderer's state.
The tree instance is passed to the node renderer so you can use like so.
function NodeRenderer({data, state, tree}) {
return (
...
<input type="checkbox" checked={state.isSelected} onClick={() => tree.selectById(data.id, true)} />
...
}
When I have more time, I'll put up an example of checkboxes on the demo site.
from react-arborist.
Hi James,
Finally got around to implementing this.
Using the Tree API works but doesn't allow shift-clicking to select everything between the first and last selected node (even when setting shift
to true).
React wants to use the onChange
event for checkboxes otherwise will show this console warning:
Warning: You provided a checked
prop to a form field without an onChange
handler. This will render a read-only field. If the field should be mutable use defaultChecked
. Otherwise, set either onChange
or readOnly
.
I ended up fixing the shift-clicking by calling the handlers
passed to the node renderer:
<input
id="row"
name="row"
type="checkbox"
checked={state.isSelected}
onClick={handlers.select}
onChange={() => {}}
/>
I also needed to listen for the selection change, can we expose an onSelect
event?
from react-arborist.
I think defaultChecked will work for you case. And this seems like an okay workaround. I'm working on a version 2 that will clean this up.
from react-arborist.
Using defaultChecked
will break keyboard up/down.
My onChange
wasn't getting fired for keyboard events.
I just figured it out via facebook/react#13477
Edit: Actually it's still broken, my onChange
won't fire.
from react-arborist.
I think I've found the root cause of the onChange
not firing: facebook/react#13424
from react-arborist.
Closed as this is solved by react-arborist v2: #49 (comment)
from react-arborist.
Related Issues (20)
- Inifinite Scrolling within Branches? HOT 2
- Item count increases randomly HOT 1
- Property 'select' does not exist on type 'never' HOT 1
- Hidden flag for nodes HOT 1
- Doesn't work on remix HOT 1
- React Aborist ScrollTo bug with deep nested nodes HOT 1
- [HELP] Multiple selection from array of ids
- Render 1 million root elements on different screen sizes
- Deselect not firing event HOT 2
- How to drag a node INTO a leaf node
- Better scrolling while user is dragging
- [Question] How to build a tree with some folders open and some closed? HOT 1
- There is a bug in using the tree.update method to set height.
- Duplicate HTML5 backend error HOT 3
- Deletion behavior can be unintuitive HOT 4
- Lack of control over delete leads to some weird scenarios HOT 2
- Should we be able to focus the entire tree? HOT 2
- Using react-arborist in an app seems to break file & folder drop on <input type="file" multiple /> elements HOT 2
- How rename `name` to `node_name` and create node with name
- Drag and Drop should be handled within the level hierarchy
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 react-arborist.