AnyRoad / react-json-view-lite

Lightweight Json view component for React
155 stars 14 forks source link

suggestion: expandable labels should be clickable #26

Closed gregsadetsky closed 4 months ago

gregsadetsky commented 4 months ago

me again :-)

a small thing that I noticed is that expanding nodes can be done by clicking the arrow, or the collapsed { ... } block, but it's not possible to expand a node by clicking the key name. see video below.

OAbWOmFP1DU-z-0-y-662bc07aa4d95544a99236a8

I made a small change locally to this line so that instead of

{field && <span className={style.label} >{field}:</span>}

it reads

{field && <span className={style.label} onClick={toggleExpanded}>{field}:</span>}

and that does exactly what I'm looking for:

4r87iPD5VP8-z-0-y-662bc12efd6a3c0628a0f4bc

there are some small styling issues with this though:


I'd be happy to contribute a fix -- would you prefer a new style to be created, something like expandableLabel, and that (based on label) would have the cursor:pointer declaration..?

thank you!

AnyRoad commented 4 months ago

Hi! Thank you for the fix and suggestion!

I think some users may stil want to just select the field name with double click (for instance to copy it). So it would be good to support both use cases with expandableLabel style and fallback to the label when first is not set. And make expanding by click on the field name optional as well.

gregsadetsky commented 4 months ago

hey, I just took a stab at implementing this in #27 -- feel free to leave comments here or in the PR. I took liberty with the naming (clickToExpandNode for the optional prop and clickableLabel for the style class) -- but obviously let me know what makes sense

I also added tests and was glad to keep the test coverage at 100% :-) cheers!

AnyRoad commented 4 months ago

Thanks! just merged and released version 1.4.0 👍

gregsadetsky commented 4 months ago

thank you!!