Scrollable drop down lists in react-bootstrap

前端 未结 3 1783
遇见更好的自我
遇见更好的自我 2021-01-17 19:53

I am trying to create some simple birth date dropdowns and would like to have scroll bars on the dropdown lists with a fixed number of items shown. How can I do this with re

3条回答
  •  隐瞒了意图╮
    2021-01-17 20:23

    Here's a possible solution that will scale the max height of the element dynamically based on viewport height:

    import React, { Component } from 'react'
    import { Button, Dropdown, MenuItem } from 'react-bootstrap'
    
    export default class CustomDropdown extends Component {
        constructor(props) {
            super(props);
            this.state = {
                open: false,
            };
        }
        toggle = () => {
            this.setState({ open: !this.state.open });
        }
        onToggle = (isOpen, e, source) => {
            //This closes the menu on toggling the dropdown or hitting esc.
            if (source.source === 'click' || source.source === 'rootClose') {
                this.toggle();
            }
        }
    
        render(){
            
    this.myRef = ref} className='CustomDropdown'> ... add menu items here
    } }

提交回复
热议问题