Skip to content

Scroll bar is gone with using CascadingHoverMenus #37

@Yangeok

Description

@Yangeok

The hover menu was ported with nextjs + typescript.

When hover, scrollbar disappears and occurs under the new css attribute of body padding-right: 20px; overflow: hidden;. I used the example 'CascadingHoverMenus'.

The first status is position: static and when scroll down, position: fixed. I changed it to position: sticky and the symptoms were the same.

Attaching the GIF below:

Kapture 2020-09-02 at 15 02 38

The code i wrote is as follows:

import React, { Fragment } from 'react'
import Link from 'next/link'
import styled from 'styled-components'

import { HoverMenu, MenuItem } from '@Components/Basic'
import { ExpandMore, ChevronRight } from '@Components/Icons'
import PopupState, { bindHover, bindMenu } from 'material-ui-popup-state'

import { IDesktopMenu } from './DesktopMenu'

const getPopupId = (str: string) => str.toLocaleLowerCase().replace(/\s/g, '-')

const TextWrapper = styled.div`
  color: ${(props: any) => props.theme.colors.black};
`

// FIXME: to change ParentPopupState type
const ParentPopupState: any = React.createContext(null)

const CascadingHoverMenus: React.FunctionComponent<IDesktopMenu.IProps> = ({ menuItem, hideOnScroll }): JSX.Element => {
  // TODO: to convert to recursive function
  return (
    <PopupState style={{ overflow: 'hidden' }} variant="popover" popupId={getPopupId(menuItem.name)}>
      {popupState => {
        return (
          <Fragment>
            <MenuItem {...bindHover(popupState)}>
              <TextWrapper>
                {menuItem.name}
                <ExpandMore />
              </TextWrapper>
            </MenuItem>
            <ParentPopupState.Provider value={popupState}>
              <HoverMenu
                {...bindMenu(popupState)}
                anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }}
                transformOrigin={{ vertical: 'top', horizontal: 'left' }}
                getContentAnchorEl={null}
              >
                {menuItem.items.map(lv2 => {
                  if (!lv2.items) {
                    return (
                      <Link href={lv2.link}>
                        <MenuItem onClick={popupState.close}>{lv2.name}</MenuItem>
                      </Link>
                    )
                  }
                  return (
                    <Submenu popupId={getPopupId(lv2.name)} title={lv2.name}>
                      {lv2.items.map(lv3 => {
                        if (!lv3.items) {
                          return (
                            <Link href={lv3.link}>
                              <MenuItem onClick={popupState.close}>{lv3.name}</MenuItem>
                            </Link>
                          )
                        }
                      })}
                    </Submenu>
                  )
                })}
              </HoverMenu>
            </ParentPopupState.Provider>
          </Fragment>
        )
      }}
    </PopupState>
  )
}

export default CascadingHoverMenus

// FIXME: to change Submenu type
const Submenu: any = React.forwardRef(({ title, popupId, children, ...props }: { title: any; popupId: any; children: any }, ref: any) => (
  <ParentPopupState.Consumer>
    {parentPopupState => (
      <PopupState variant="popover" popupId={getPopupId(popupId)} parentPopupState={parentPopupState}>
        {popupState => (
          <ParentPopupState.Provider value={popupState}>
            <MenuItem {...bindHover(popupState)} selected={popupState.isOpen} ref={ref}>
              <span>{title}</span>
              <ChevronRight />
            </MenuItem>
            <HoverMenu
              {...bindMenu(popupState)}
              anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
              transformOrigin={{ vertical: 'top', horizontal: 'left' }}
              getContentAnchorEl={null}
              {...props}
            >
              {children}
            </HoverMenu>
          </ParentPopupState.Provider>
        )}
      </PopupState>
    )}
  </ParentPopupState.Consumer>
))

I'd appreciate it if you could tell me the solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions