Giter VIP home page Giter VIP logo

Comments (12)

chaance avatar chaance commented on August 20, 2024 6

FYI, we have a duplicate issue that is still open dealing with this. I'm tracking the conversation there, but we are aware and working on this. We'll have a rewrite of MenuButton out (hopefully) in the next couple of weeks. #119

from reach-ui.

amberleyromo avatar amberleyromo commented on August 20, 2024 4

I'm still getting this error trying to do the same thing :(

TypeError: Cannot read property 'selectionIndex' of undefined

Tried just copy-pasting from the sandbox. Was this later reverted?

Edit: Yup. https://github.com/reach/reach-ui/blob/master/packages/menu-button/src/index.js#L326

import React, { useState } from "react"
import styled from "react-emotion"
import "@reach/menu-button/styles.css"
import {
  Menu as ReachMenu,
  MenuButton as ReachMenuButton,
  MenuList as ReachMenuList,
  MenuItem as ReachMenuItem,
} from "@reach/menu-button"

const Menu = styled(ReachMenu)``

const MenuButton = styled(ReachMenuButton)`
  background-color: #fff;
  border: 1px solid #ccc;
  padding: 6px 10px;
`

const MenuList = styled(ReachMenuList)`
  background-color: red;
`

const MenuItem = styled(ReachMenuItem)`
  padding: 20px;
  &[data-selected] {
    color: red;
    background: white;
  }
`
const Test = () => {
  return (
    <Menu>
      <MenuButton>Actions</MenuButton>
      <MenuList>
        <MenuItem>Download</MenuItem>
        <MenuItem>Foo</MenuItem>
      </MenuList>
    </Menu>
  )
}

export default Test

from reach-ui.

ryanflorence avatar ryanflorence commented on August 20, 2024 2

Don't forget you'll want to style the selected state probably too :)

const MenuItem = styled(ReachMenuItem)`
  padding: 20px;
  &[data-selected] {
    color: red;
    background: white;
  }
`;

from reach-ui.

ryanflorence avatar ryanflorence commented on August 20, 2024

Ah shoot, I should have thought of this 😑

if (child.type === MenuItem || child.type === MenuLink) {

Gonna allow anything I guess.

from reach-ui.

ryanflorence avatar ryanflorence commented on August 20, 2024

https://codesandbox.io/s/8z3yln1x0l

from reach-ui.

bogdansoare avatar bogdansoare commented on August 20, 2024

awesome, thanks 🙌

from reach-ui.

qoalu avatar qoalu commented on August 20, 2024

Same issue. Using styled-components.

Interestingly documentation page provides an example of styling MenuItems by attribute from MenuList component

https://ui.reach.tech/styling/

let YourMenuList = styled(MenuList)`
  border: solid 2px black;
  background: black;
  color: red;
  > [data-reach-menu-item][data-selected] {
    background: red;
    color: white;
  }
`

from reach-ui.

jamesarosen avatar jamesarosen commented on August 20, 2024

I get this on the latest version. My higher-order component:

export default function withClassName(Component, extraClass) {
  const Wrapped = React.forwardRef(({ className, ...props }, ref) => {
    return <Component {...props} className={classnames(className, extraClass)} ref={ref} />
  })

  Wrapped.propTypes = {
    className: PropTypes.string,
  }

  Wrapped.defaultProps = {
    className: '',
  }

  Wrapped.displayName = `My${Component.displayName}`

  return Wrapped
}

This works:

import { Menu as ReachMenu } from '@reach/menu-button'
export const Menu = withClassName(ReachMenu, 'my-menu')

This doesn't:

import { MenuItem as ReachMenuItem } from '@reach/menu-button'
export const MenuItem = withClassName(ReachMenuItem, 'my-menu-item')

Specifically, state is undefined here.

from reach-ui.

focux avatar focux commented on August 20, 2024

Same here, MenuItem isn't working on styled-components yet. The regression started in v0.1.8, as a workaround, I downgraded to v0.1.7.

from reach-ui.

chukkwagon avatar chukkwagon commented on August 20, 2024

I am having this problem as well. Can we re-open this issue since it appears to have regressed?:
My installed version of @reach/menu-button is 0.3.0.

from reach-ui.

dwilt avatar dwilt commented on August 20, 2024

I'm also seeing this in my puppeteer tests specifically.

ui.getActionMenuButton().simulate('click'); // <-- simulating a click in puppeteer

from reach-ui.

amberleyromo avatar amberleyromo commented on August 20, 2024

Happy to see this update, thanks for all your work @chancestrickland!!

from reach-ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.