React semantic-ui Dropdown onChange not working

前端 未结 2 457
忘了有多久
忘了有多久 2021-01-20 22:26

Here\'s the code:

class MenuContainerComponent extends Component {

    onInputWidgetMenuChange(event, data) {
        console.log(data);
    }

    render()         


        
2条回答
  •  野性不改
    2021-01-20 23:02

    Giri's answer is correct. Change this line

    inputWidgets.push({componentName});

    to

    inputWidgets.push({componentName});

    Where componentId is the actual value of the Dropdown.Item, (as opposed to the text displayed). Given the right circumstances componentId can be the same as the componentName too.

    Another thing is that since you're using Dropdown.Menu inside the Dropdown, clicking the items on the menu won't automatically change the value of the Dropdown. (which is why the onChange of event the Dropdown component isn't fired). You need to save the current value of the Dropdown in the react state and manually set the trigger prop of Dropdown to make it look like the selected item.

提交回复
热议问题