React-sortable-tree: Remove hard coded label

Created on 27 Dec 2017  路  8Comments  路  Source: frontend-collective/react-sortable-tree

Hi, please, make hard coded 'title' and 'subtitle' changeable

For example:

<SortableTree
     title="label"
     subtitle="url"
     treeData={this.props.menu}
     onChange={ treeData => this.props.changeTree(treeData) }
/>

If this field are not fill used default params title="title", subtitle: "subtitle".

This will be more customized, since sometimes other fields are used coherently in the whole product and when using your module in the system, changes that are not standardized will be made. For example, we everywhere use a label instead of a title.

Of course, I can make a copy myself and fill it with npm, but I do not think this is necessary since there is already a ready-made module that is being developed and this small innovation will be pleasant for many developers.

Or maybe i can make merge request?

wontfix

Most helpful comment

Use generateNodeProps. For example, to use label as the title and url as the subtitle

<SortableTree
     ...
     generateNodeProps={({ node }) => ({ title: node.label, subtitle: node.url })}
/>

All 8 comments

I'm not sure i understood what you are trying to do. If you want the title (or subtitle) to be editable you should check out this example.

You should try out the other examples and read up on the generateNodeProps prop

No sorry. I want to 'title' and 'subtitle' can be changed. The name itself

For examle:

My state: {label: 'Hello', url: 'https://lol.com'}

title="label"
subtitle="url"
treeData={this.props.menu}
onChange={ treeData => this.props.changeTree(treeData) }
/>

I want to use a 'label' and 'url' and that it is displayed on the tree instead of title and subtitle

I see - you want to rename the props on the component. In that case suggest forking the repo and making your own version, because title and subtitle are more ubiquitous than the ones you suggested. Perhaps the props names can be improved, but i don't think "label" and "url" are the best options. @fritz-c should add his input here.

Yeah, I think the current approach provides enough ways for the user to set their title/subtitle parts. If you want to avoid adding an extra property to your nodes just to remove it on export, I would recommend setting the title and subtitle via generateNodeProps, as @borisyordanov suggested.

I propose that 'title' and 'subtitle' were not mandatory and they could be changed. If they are specified as parameters ' title="label" ' then you need to use for the tree just 'label'' as the title text description, and if not, use names appropriately 'title'. This will be a more custom solution. If you already have the opportunity to change them, can you give an example?

Use generateNodeProps. For example, to use label as the title and url as the subtitle

<SortableTree
     ...
     generateNodeProps={({ node }) => ({ title: node.label, subtitle: node.url })}
/>

Thank you/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

robhadfield picture robhadfield  路  3Comments

mcolburn picture mcolburn  路  4Comments

oarashi picture oarashi  路  5Comments

vaheqelyan picture vaheqelyan  路  4Comments

kaueDM picture kaueDM  路  3Comments