Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Menu disappears after item selection and never returns despite open={true} #909

Closed
ndtreviv opened this issue Jun 5, 2019 · 2 comments
Closed

Comments

@ndtreviv
Copy link

ndtreviv commented Jun 5, 2019

What I'm trying to achieve

An autocomplete/select list made up of a TextField and a Menu.

Expected Behaviour

When the user clicks the TextField, or starts typing, it should show the Menu, controlled by a boolean in the state called fieldListOpen.

If the user selects a menu option, the Menu should go away, and if they then click the TextField again it should reappear, as fieldListOpen will be set to true again.

Actual Behaviour

The menu appears the first time. I click an option, the Menu disappears and I can't make it reappear again.

I can confirm that the fieldListOpen state field is set to true:
Screenshot 2019-06-05 at 15 45 46

The Menu element is on the page, but display is set to none:
Screenshot 2019-06-05 at 15 46 41

If I set display to something else, the menu is there, but is a ghost:
Screenshot 2019-06-05 at 15 56 27

Code from my render function:

        <TextField
          ref={this.setAnchorElement}
          trailingIcon={<MaterialIcon role="button" icon="arrow_drop_down" />}
          onTrailingIconSelect={e => {
            this.setState({ fieldListOpen: true });
          }}
        >
          <Input
            onClick={e => {
              this.setState({ fieldListOpen: true });
            }}
            onChange={e => {
              this.setState({
                fieldFilter: e.target.value,
                fieldListOpen: true
              });
            }}
            value={fieldFilter}
          />
        </TextField>
        <Menu
          open={fieldListOpen}
          anchorCorner={Corner.BOTTOM_LEFT}
          anchorElement={anchorElement}
          onSelected={(arg1, arg2) => console.log("select", arg1, arg2)}
        >
          <MenuList>
            {options.map((field, index) => (
              <MenuListItem
                key={index}
                onClick={e => {
                  this.setState({ selectedField: field });
                }}
              >
                <MenuListItemText primaryText={field.label} />
              </MenuListItem>
            ))}
          </MenuList>
        </Menu>

What do I need to do to get my Menu to show up again?

@ndtreviv ndtreviv changed the title Menu disappears after item selection and never returns Menu disappears after item selection and never returns despite open={true} Jun 5, 2019
@ndtreviv
Copy link
Author

ndtreviv commented Jun 5, 2019

#242 mentions a text field associated with a select...I'm wondering if an autocomplete component is in the pipeline?

@ndtreviv
Copy link
Author

ndtreviv commented Jun 5, 2019

Fixed by adding the following property to Menu:

          onClose={(e) => { this.setState({fieldListOpen: false}); }}

@ndtreviv ndtreviv closed this as completed Jun 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant