javascript - Nested dropdown in react-select - Stack Overflow

I am using react-select to render the dropdown. The options to render the dropdown looks like this[{

I am using react-select to render the dropdown. The options to render the dropdown looks like this

 [
    {   
        text:'Fruit',
        value:'mango'
        level: 0
    },
    {   
        text:'Seasonal',
        slug: 'saasonal',
        level: 1
    },
    {   
        text:'Orange',
        slug: 'orange',
        level: 2
    },
    {   
        text:'Mango',
        slug: 'mango',
        level: 2
    },
    {
        text: 'Winter',
        slug:'winter',
        level:1
    },
    {
        text: 'Plum',
        slug:'plum',
        level:2
    }

]

I would like the dropdown to be like

Fruit   
    Seasonal
        Orange
        Mango
    Winter
        Plum

I have tried adding a group to the react-select, but then the group heading is not clickable. I have also referred to the stackoverflow link

[][1]
and tried creating a recursive dropdown in the same manner it is posted on the link above by passing my options as the data but was not successful.

The order of the within nested dropdown is based on the level.

I am using react-select to render the dropdown. The options to render the dropdown looks like this

 [
    {   
        text:'Fruit',
        value:'mango'
        level: 0
    },
    {   
        text:'Seasonal',
        slug: 'saasonal',
        level: 1
    },
    {   
        text:'Orange',
        slug: 'orange',
        level: 2
    },
    {   
        text:'Mango',
        slug: 'mango',
        level: 2
    },
    {
        text: 'Winter',
        slug:'winter',
        level:1
    },
    {
        text: 'Plum',
        slug:'plum',
        level:2
    }

]

I would like the dropdown to be like

Fruit   
    Seasonal
        Orange
        Mango
    Winter
        Plum

I have tried adding a group to the react-select, but then the group heading is not clickable. I have also referred to the stackoverflow link

[https://stackoverflow./questions/53119912/how-can-i-create-nested-option-groups-in-react-select-v2][1]
and tried creating a recursive dropdown in the same manner it is posted on the link above by passing my options as the data but was not successful.

The order of the within nested dropdown is based on the level.

Share Improve this question edited Sep 16, 2020 at 13:17 Erick asked Sep 16, 2020 at 13:08 ErickErick 1,1461 gold badge11 silver badges24 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 2

react-select actually just got this feature builtin in July.

Here's the pull request where they implemented it.

Here's a working example from the pull request page.

I'm not sure if it has made its way into the master branch yet or not but you can always pull from the version listed in the package.json file in the sample above if the sample code doesn't work with the version you're using.

EDIT: Scratch that, you want group headings to be clickable. I don't think that was part of this mit.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745667442a4639202.html

相关推荐

  • javascript - Nested dropdown in react-select - Stack Overflow

    I am using react-select to render the dropdown. The options to render the dropdown looks like this[{

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信