Skip to content

What is the preferred way of preventing the Menu component from going outside the bounds of the screen? #3466

@idiomattic

Description

@idiomattic

Ask your Question

I have a few dropdowns that have a variable number of Menu Item's and I've noticed that they sometimes will run outside the bounds of the bottom of the screen. I've tried setting a maxHeight in the contentStyle prop but that seems to allow the menu items to overflow their container.

My current implementation:

      <Menu
        visible={showDropdown}
        onDismiss={() => setShowDropdown(false)}
        style={{ paddingTop: 50 }}
        anchor={
          <Button
            mode={mode}
            disabled={disabled}
            icon={icon}
            onPress={() => setShowDropdown(true)}
            contentStyle={{ flexDirection: 'row-reverse' }}
            labelStyle={labelStyle}
            >
            {value || placeholder}
          </Button>
        }
        >
        {
          list.map(({ label, value }, i) => (
            <View key={i}>
              <Menu.Item 
                title={label} 
                onPress={() => {
                  onSelect(value)
                  setShowDropdown(false)
                }}
                />
            </View>
          ))
        }
      </Menu>

Metadata

Metadata

Assignees

No one assigned

    Labels

    MenuquestionQuestion related to the library, not an issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions