question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

class for Menu items and use custom JSX (4.20.0)

See original GitHub issue

What problem does this feature solve?

Hi guys. please fix Menu items. In previous version (4.19.5), we could modifiy every single item in Menu and pass them our classes and conditions but in new version (4.20.0), we can’t modify and it is very annoying. In new version (4.20.0) we are totally locked up and we can’t modify Menu items. Please make it ( items={[]} ) optional without any ugly warning in console and allow to add classes and custom JSX to items. I used items as children because I used location.pathname for checking route and base on route, I map on routes array and show different menu with different classes in different conditions to the user.

What does the proposed API look like?

Please remove ugly warning from console and don’t remove children in next version. Thank you a lot. And I know here is not a good place to ask.

<Menu
      theme="light"
      mode="inline"
      className="ml-bg-primary border-r-none"
      defaultOpenKeys={[defaultOpen]}
    >
      {routesName.map((route: Readonly<INavigation>) => {
        //! if we have a route with subMenu, this scope will execute
        if (route.subMenu?.length) {
          return (
            <Menu.SubMenu
              className={
                route.subMenu.find((sub) => sub.path === location.pathname)
                  ? collapsed
                    ? "ml-text-secondary bg-white ml-menu-radius"
                    : "ml-text-secondary bg-white ml-menu-radius max-width-250"
                  : "ml-text-primary max-width-250"
              }
              key={route.path}
              icon={route.icon}
              title={route.title}
            >
              {route.subMenu.map((sub) => (
                <Menu.Item
                  onClick={() => handleOpenSubMenu(route)}
                  className={
                    location.pathname === sub.path
                      ? collapsed
                        ? "ml-text-secondary bg-white ml-menu-radius subMenu-style"
                        : "ml-text-secondary bg-white subMenu-style"
                      : "ml-text-primary"
                  }
                  key={sub.id}
                  icon={sub.icon}
                >
                  <Link
                    to={sub.path}
                    className={
                      location.pathname === sub.path
                        ? "ml-text-secondary font-s-3"
                        : "ml-text-primary font-s-3"
                    }
                  >
                    {sub.name}
                  </Link>
                </Menu.Item>
              ))}
            </Menu.SubMenu>
          );
        } else {
          return (
            <Menu.Item
              className={
                `/${location.pathname.split("/")[1]}` === route.path
                  ? collapsed
                    ? "ml-text-secondary bg-white ml-menu-radius max-width-110"
                    : "ml-text-secondary bg-white ml-menu-radius max-width-250"
                  : "ml-text-primary"
              }
              key={route.id}
              icon={route.icon}
            >
              <Link
                to={route.path}
                className={
                  `/${location.pathname.split("/")[1]}` === route.path
                    ? "ml-text-secondary font-s-3"
                    : "ml-text-primary font-s-3"
                }
              >
                {route.name}
              </Link>
            </Menu.Item>
          );
        }
      })}
      <Menu.Item
        className="ml-text-primary max-width-250 without-style"
        onClick={() => Alert("logout", "Do you want to logout?", handleLogout)}
        key={999999}
        icon={<LogoutOutlined style={{ fontSize: 25 }} />}
      >
        <span className="ml-text-primary font-s-3">Logout</span>
      </Menu.Item>
    </Menu>

🎉 This is my sidemenu code.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:14
  • Comments:20 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
matteosaporiticommented, Apr 26, 2022

Can give me a sample or something ? I couldn’t find anything in documentation to help me to refactor my sidemenu code. I mean to use my JSX code in Menu items.

Sure, I’ve migrated this pretty hackish menu item

<Menu onClick={({ key, keyPath, domEvent }) => { stopPropagation(domEvent); }}>  
  <Menu.Item key={props.languageKey}>  
    <PriceSlider onClose={filterAndHideDropdown} minPrice={minPrice}  maxPrice={maxPrice} />  
  </Menu.Item>
</Menu>

to

<Menu  onClick={({ key, keyPath, domEvent }) => { stopPropagation(domEvent); }}
  items={[{key: props.language, label: <PriceSlider onClose={filterAndHideDropdown} minPrice={minPrice}  maxPrice={maxPrice} />}]}>
</Menu>

and this legacy and ugly code

<Menu className="additional-menu" onClick={({ key, keyPath, domEvent }) => { stopPropagation(domEvent); }} onSelect={({ key, keyPath, domEvent}) => { }}>
        <SubMenu key="filter-submenu" title={renderTranslation(language, TranslationKeys.tableDotsMenuSetFilter)} icon={<FilterIcon cssClassRule="additional-menu-icon filter-icon"/>} className="bordered">
            <Menu.Item key="submenu-empty" icon={<CheckOutlined className="v-hidden" />} onClick={addToDescriptionEmpty}>{renderTranslation(language, TranslationKeys.tableDotsMenuEmpty)}</Menu.Item>
        </SubMenu>
        <SubMenu key="lock-column-submenu" title={renderTranslation(language, TranslationKeys.tableDotsLockColumn)} icon={<PinIcon cssClassRule="additional-menu-icon pin-icon"/>} disabled={props.label === ArticleCode} className="bordered">
            <Menu.Item key="submenu-lock-left" icon={<CheckOutlined className={props.fixed === 'left' ? "" : "v-hidden"} />} className="bordered" onClick={alignLeft}>{renderTranslation(language, TranslationKeys.tableDotsMenuLockLeft)}</Menu.Item>
            <Menu.Item key="submenu-lock-right" icon={<CheckOutlined className={props.fixed === 'right' ? "" : "v-hidden"} />} className="bordered" onClick={alignRight}>{renderTranslation(language, TranslationKeys.tableDotsMenuLockRight)}</Menu.Item>
            <Menu.Item key="submenu-unlock" icon={<CheckOutlined className={!props.fixed ? "" : "v-hidden"} />} className="bordered" onClick={unAlign}>{renderTranslation(language, TranslationKeys.tableDotsMenuUnlocked)}</Menu.Item>
        </SubMenu>
        <Menu.Item key="adapt-single-column" icon={<CheckOutlined className={freeWidthColumns.indexOf(props.label) !== 1 ? "" : "v-hidden"} />} onClick={updateFreeWidthColumn}>{renderTranslation(language, TranslationKeys.tableDotsMenuAdaptColumn)}</Menu.Item>
        <Menu.Item key="adapt-all-column" icon={<CheckOutlined className={freeWidthColumns.indexOf(AllFreeWidthColumn) !== -1 ? "" : "v-hidden"} />} onClick={updateAllFreeWidthColumns}>{renderTranslation(language, TranslationKeys.tableDotsMenuAdaptAllColumns)}</Menu.Item>
        <Menu.Item key="reset-column" icon={<CheckOutlined className="v-hidden" />} onClick={resetAllFreeWidthColumns} className={editTableDisable ? "" : "bordered"}>{renderTranslation(language, TranslationKeys.tableDotsMenuResetFixedColumns)}</Menu.Item>
        {editTableDisable ? null :
            <Popover content={renderTranslation(language, TranslationKeys.tableDotsMenuEditDisableTips)} placement="right" trigger="hover">
                <Menu.Item key="edit-disable" className="edit-menu-item disable" icon={<EditIcon cssClassRule={"additional-menu-icon edit-icon disable"}/>}>
                    {renderTranslation(language, TranslationKeys.tableDotsMenuEditSelection)}
                </Menu.Item>
            </Popover>
        }
 </Menu>

to

<Menu className="additional-menu" onClick={({ key, keyPath, domEvent }) => { stopPropagation(domEvent); }} onSelect={({ key, keyPath, domEvent }) => { }}
            items={[
                {
                    key: "filter-submenu", label: renderTranslation(language, TranslationKeys.tableDotsMenuSetFilter), icon: <FilterIcon cssClassRule="additional-menu-icon filter-icon" />, className: "bordered",
                    children: [
                        { key: "submenu-empty", icon: <CheckOutlined className="v-hidden" />, onClick: addToDescriptionEmpty, label: renderTranslation(language, TranslationKeys.tableDotsMenuEmpty) }]
                },
                {
                    key: "lock-column-submenu", label: renderTranslation(language, TranslationKeys.tableDotsLockColumn), icon: <PinIcon cssClassRule="additional-menu-icon pin-icon" />, disabled: props.label === ArticleCode, className: "bordered",
                    children: [
                        { key: "submenu-lock-left", icon: <CheckOutlined className={props.fixed === 'left' ? "" : "v-hidden"} />, className: "bordered", onClick: alignLeft, label: renderTranslation(language, TranslationKeys.tableDotsMenuLockLeft) },
                        { key: "submenu-lock-right", icon: <CheckOutlined className={props.fixed === 'right' ? "" : "v-hidden"} />, className: "bordered", onClick: alignRight, label: renderTranslation(language, TranslationKeys.tableDotsMenuLockRight) },
                        { key: "submenu-unlock", icon: <CheckOutlined className={!props.fixed ? "" : "v-hidden"} />, className: "bordered", onClick: unAlign, label: renderTranslation(language, TranslationKeys.tableDotsMenuUnlocked) }]
                },
                { key: "adapt-single-column", icon: <CheckOutlined className={freeWidthColumns.indexOf(props.label) !== -1 ? "" : "v-hidden"} />, onClick: updateFreeWidthColumn, label: renderTranslation(language, TranslationKeys.tableDotsMenuAdaptColumn) },
                { key: "adapt-all-column", icon: <CheckOutlined className={freeWidthColumns.indexOf(AllFreeWidthColumn) !== -1 ? "" : "v-hidden"} />, onClick: updateAllFreeWidthColumns, label: renderTranslation(language, TranslationKeys.tableDotsMenuAdaptAllColumns) },
                { key: "reset-column", icon: <CheckOutlined className="v-hidden" />, onClick: resetAllFreeWidthColumns, className: editTableDisable ? "" : "bordered", label: renderTranslation(language, TranslationKeys.tableDotsMenuResetFixedColumns) },
                editTableDisable ? null : {
                    key: "edit", icon: <EditIcon cssClassRule={"additional-menu-icon edit-icon disable"} />, className: "edit-menu-item disable", label: <Popover content={renderTranslation(language, TranslationKeys.tableDotsMenuEditDisableTips)} placement="right" trigger="hover">
                        <div>{renderTranslation(language, TranslationKeys.tableDotsMenuEditSelection)}</div>
                    </Popover>
                }
            ]}>
        </Menu>
5reactions
edmundsjcommented, Nov 15, 2022

This feature deviates strongly from the normal JSX pattern of embedding child nodes within other nodes as JSX components, and is inconsistent with how most of Ant Design itself handles child nodes. This caused me a great deal of confusion. I can’t find anywhere in the docs where it is documented that you can pass in custom JSX to the label key. This is not standard in any other packages I am aware of. I would strongly suggest <Menu.Item> not be deprecated, and that items simply be syntactic sugar for those who want it to internally generate a list of <Menu.Items>s.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ant design 4.20 new Menu item style - Stack Overflow
1 Answer 1 ; import React ; from 'react' ; import 'antd/dist/antd.css' ; import './index.css' ; import · Menu ...
Read more >
Menu - Ant Design
Your customized node should be wrapped by Menu.Item . Menu needs to collect its node structure, so its children should be Menu.* or...
Read more >
How to create Menu Item Component in ReactJS
We can use Menu Component in ReactJS using the following approach. ... Step 1: Create a React application using the following command:
Read more >
Bootstrap Theme Changelog - KendoReact - Telerik
fab: the shape option now supports rectangle and square . fab: themeColor class is now composite - k-fab-{fillMode}-{themeColor} . fab: Add kendo prefix...
Read more >
PySimpleGUI
I've been teaching it in my Python classes instead of Tkinter." ... Add a little color to your windows # All the stuff...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found