I am using Semantic UI React and trying to create a multilevel menu component or a nested menu.
I was able to create a static menu component like below:
<Menu>
<Menu.Item>
<Dropdown text='MCU' pointing className='link item'>
<Dropdown.Menu>
<Dropdown.Item>
</Dropdown.Item>
<Dropdown.Item>
</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
</Menu.Item>
<Menu.Item>
</Menu.Item>
<Menu.Item>
Dropdown Menu
</Menu.Item>
</Menu>
Check out the output here
I was trying to create a dynamic component for that menu like below -
export class RecursiveMenu extends Component {
render() {
const { children, textToShow } = this.props;
return (
<Dropdown key={children.wbMenuId} text={textToShow} pointing={children.childMenu ? true : false} className='link item'>
<Dropdown.Menu>
{
children.map(child => <Dropdown.Item>{child.userMenuName}</Dropdown.Item>)
}
</Dropdown.Menu>
</Dropdown>
);
}
}
But it's not showing properly. This is example data.
You can use Dropdown's
optionsprop to pass your dropdown items instead of creating them yourself.Here is an example in the Semantic UI docs:
https://react.semantic-ui.com/modules/dropdown#dropdown-example-item-content