-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expand all fields in tree mode in ReactJS #266
Comments
Thanks for your PR @nitzcard . I'm not entirely sure I understand the original issue: at the start, the document contents is expanded by default. See for example this basic React example: https://codesandbox.io/s/svelte-jsoneditor-react-59wxz |
At my internal system it doesn't start expanded all the times, |
Can you share a minimal example demonstrating your issue? The only case where I know it happens is if you initially load an empty document, and later update it with actual contents. The editor leaves the expanded state as is when updating a document. When I load a new document, I normally create a new editor with clean state, so it expands the document contents like it should. |
Could be that's what happens at my form infra internally, when the data loads after. Will check and return to you. If that is the case, how can I enforce expanded at the first time the actual data loads? |
Either create a new editor with the document, or use |
I think what should work is:
Alternatively, you can create the editor only after you have the document and can directly pass it during initialization of the editor. |
|
One way or another, you will need to tell the editor when to keep the expanded state or reset it. Only you know the difference between loading a new document versus updating the existing document. The You will need to let the editor know when to reset the state of the editor by either (1) creating a new editor, (2) use the method On a side note: I was thinking that maybe your code in #266 (comment) does not work because you call await refEditor.current.updateProps(props)
//...
if (...) {
await refEditor.current.expand(...)
} |
Good to mention here: we're thinking about exposing the internal state of the editor so you can control that via props, see #163 (comment). That would introduce another option to change/reset the expanded state whenever you want. |
using await inside useEffect is discouraged, but it's not working. |
ok so implementing it for me via set is still very hacky with a lot of edge cases, |
I'm still not sure whether I correctly understand what you're trying to do. Can you create a minimal CodeSandbox example demonstrating the issue? Can be based on https://codesandbox.io/s/svelte-jsoneditor-react-59wxz |
Any more information on this @nitzcard ? If not relevant anymore I'll close this issue. |
Hi, I try to expend all the fields in tree mode in react right from the start,
I saw there is an expand function:
refEditor.current?.expand((path) => true);
I try to do it in the useEffect when initting the library but it doesn't work,
do you have an idea how it can be achieved?
The text was updated successfully, but these errors were encountered: