Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

css style doesn't work on top menu across all dashboards and charts #29826

Open
pengpengSir opened this issue Aug 1, 2024 · 3 comments
Open
Labels
dashboard:css Related to the CSS field of the Dashboard

Comments

@pengpengSir
Copy link

Screenshot

image

Description

css style should be horizontal, but now it turns into vertical. I don't know where I just modified because I am updating superset from 2.0 to 4.0, can you tell me how to solve this , Thanks!

Design input

[describe any input/collaboration you'd like from designers, and
tag accordingly. For design review, add the
label design:review. If this includes a design proposal,
include the label design:suggest]

@dosubot dosubot bot added the dashboard:css Related to the CSS field of the Dashboard label Aug 1, 2024
Copy link

dosubot bot commented Aug 1, 2024

Hey @pengpengSir! 👋 I'm here to help you with any bugs, questions, or contributions you have for the repository. Let's squash those bugs together!

To resolve the issue where the CSS style for the top menu in Superset has changed from horizontal to vertical after updating from version 2.0 to 4.0, you need to ensure that the Menu component's showMenu state is correctly set based on the window width. The showMenu state determines whether the menu is displayed in 'horizontal' or 'inline' (vertical) mode.

The useEffect hook in the Menu component handles this by setting the showMenu state based on the window width. If the window width is less than or equal to 767 pixels, the menu is set to 'inline' (vertical); otherwise, it is set to 'horizontal'.

Here is the relevant part of the code:

useEffect(() => {
  function handleResize() {
    if (window.innerWidth <= 767) {
      setMenu('inline');
    } else setMenu('horizontal');
  }
  handleResize();
  const windowResize = debounce(() => handleResize(), 10);
  window.addEventListener('resize', windowResize);
  return () => window.removeEventListener('resize', windowResize);
}, []);

Additionally, ensure that the Menu component and its styles are correctly implemented. The Menu component in Superset uses Ant Design's Menu component, and the styles are defined using the styled function from @superset-ui/core. Here is an example of how the Menu and its items are styled:

import { styled } from '@superset-ui/core';
import { Menu as AntdMenu } from 'antd';

const MenuItem = styled(AntdMenu.Item)`
  > a {
    text-decoration: none;
  }

  &.ant-menu-item {
    height: ${({ theme }) => theme.gridUnit * 8}px;
    line-height: ${({ theme }) => theme.gridUnit * 8}px;
    a {
      border-bottom: none;
      transition: background-color ${({ theme }) => theme.transitionTiming}s;
      &:after {
        content: '';
        position: absolute;
        bottom: -3px;
        left: 50%;
        width: 0;
        height: 3px;
        opacity: 0;
        transform: translateX(-50%);
        transition: all ${({ theme }) => theme.transitionTiming}s;
        background-color: ${({ theme }) => theme.colors.primary.base};
      }
      &:focus {
        border-bottom: none;
        background-color: transparent;
        @media (max-width: 767px) {
          background-color: ${({ theme }) => theme.colors.primary.light5};
        }
      }
    }
  }

  &.ant-menu-item,
  &.ant-dropdown-menu-item {
    span[role='button'] {
      display: inline-block;
      width: 100%;
    }
    transition-duration: 0s;
  }
`;

const StyledNav = styled(AntdMenu)`
  line-height: 51px;
  border: none;

  & > .ant-menu-item,
  & > .ant-menu-submenu {
    vertical-align: inherit;
    &:hover {
      color: ${({ theme }) => theme.colors.grayscale.dark1};
    }
  }

  &:not(.ant-menu-dark) > .ant-menu-submenu,
  &:not(.ant-menu-dark) > .ant-menu-item {
    &:hover {
      border-bottom: none;
    }
  }

  &:not(.ant-menu-dark) > .ant-menu-submenu,
  &:not(.ant-menu-dark) > .ant-menu-item {
    margin: 0px;
  }

  & > .ant-menu-item > a {
    padding: ${({ theme }) => theme.gridUnit * 4}px;
  }
`;

const StyledSubMenu = styled(AntdMenu.SubMenu)`
  color: ${({ theme }) => theme.colors.grayscale.dark1};
  border-bottom: none;
  .ant-menu-submenu-open,
  .ant-menu-submenu-active {
    background-color: ${({ theme }) => theme.colors.primary.light5};
    .ant-menu-submenu-title {
      color: ${({ theme }) => theme.colors.grayscale.dark1};
      background-color: ${({ theme }) => theme.colors.primary.light5};
      border-bottom: none;
      margin: 0;
      &:after {
        opacity: 1;
        width: calc(100% - 1);
      }
    }
  }
  .ant-menu-submenu-title {
    position: relative;
    top: ${({ theme }) => -theme.gridUnit - 3}px;
    &:after {
      content: '';
      position: absolute;
      bottom: -3px;
      left: 50%;
      width: 0;
      height: 3px;
      opacity: 0;
      transform: translateX(-50%);
      transition: all ${({ theme }) => theme.transitionTiming}s;
      background-color: ${({ theme }) => theme.colors.primary.base};
    }
  }
  .ant-menu-submenu-arrow {
    top: 67%;
  }
  & > .ant-menu-submenu-title {
    padding: 0 ${({ theme }) => theme.gridUnit * 6}px 0
      ${({ theme }) => theme.gridUnit * 3}px !important;
    span[role='img'] {
      position: absolute;
      right: ${({ theme }) => -theme.gridUnit   -2}px;
      top: ${({ theme }) => theme.gridUnit * 5.25}px;
      svg {
        font-size: ${({ theme }) => theme.gridUnit * 6}px;
        color: ${({ theme }) => theme.colors.grayscale.base};
      }
    }
    & > span {
      position: relative;
      top: 7px;
    }
    &:hover {
      color: ${({ theme }) => theme.colors.primary.base};
    }
  }
`;

export const Menu = Object.assign(AntdMenu, {
  Item: MenuItem,
});

export const MainNav = Object.assign(StyledNav, {
  Item: MenuItem,
  SubMenu: StyledSubMenu,
  Divider: AntdMenu.Divider,
  ItemGroup: AntdMenu.ItemGroup,
});

Ensure that these styles and the useEffect hook are correctly implemented in your Menu component to maintain the horizontal layout for wider screens and switch to a vertical layout for narrower screens [1][2].

To continue talking to Dosu, mention @dosu.

@rusackas
Copy link
Member

rusackas commented Aug 1, 2024

Sorry, I'm not quite understanding the issue. Are you saying you have some customized CSS that's no longer supported after the upgrade?

@pengpengSir
Copy link
Author

pengpengSir commented Aug 2, 2024

@rusackas thanks for your replay! yesterday it works well, however, I try to add this piece of code (as shown in the picture) in superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/controlPanel.tsx, then the top menu turns in to mess.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dashboard:css Related to the CSS field of the Dashboard
Projects
None yet
Development

No branches or pull requests

2 participants