react-menu-popup

0.7.9 • Public • Published

React Menu popup

Simple React Menu popup

How to use

import MenuPopup from 'react-menu-popup'
import 'react-menu-popup/lib/react-menu-popup.css'

let menuData = [
            {
                name:"Hot Chocolate",
                value:1
            },
            {
                name:"Cookie Ice Cream",
                value:2
            },
            {
                name:"Ice Matcha Latte",
                value:3
            }
        ]

let handleItemClick = (item)=>{
    console.log(item);
}        


<MenuPopup
        defaultValue={2}
        items = {menuData} 
        labelKey ='name' 
        valueKey = 'value'
        inputRef={(el) => { this.inputEl = el }}
        menuRef = { (menuEl) => { this.menuEl = menuEl } }
        onItemClick = { (item) => handleItemClick(item)}
        direction = 'up'  // 'down' (default) or null
        offsetX = {20}  //20px, optional
        offsetY = {-5}  //-5px, optional
        minWidth = {200}  //minWidth:200px, optional

        
    />

When specify the children inside MenuPopup, this will work as a normal popup menu, it will not work as a select element.


let onOpen = (menuEl) =>{ ... }

let onClose = () => { ... }

...
    <MenuPopup 
            items = {menuData} 
            onItemClick = { (item)=> this.onMenuItemClick(item)}
            labelKey = 'name'
            direction = 'up'
            align ='right' // 'left' (default)
            onOpen = { onOpen }
            onClose  = { onClose } 
        >
        <span>Click here </span>
    </MenuPopup>

Prevent close the popup on item click:

let menuData = [
            {
                name:"Hot Chocolate",
                value:1
            },
            {
                name:"Cookie Ice Cream",
                value:2,
                keepOpen:true
            },
            {
                name:"Ice Matcha Latte",
                value:3
            }
        ]

Pass in the menu item as custom component

let menuData = [
            {
                name:"Hot Chocolate",
                value:1
            },
            {
                component: <div>
                                You can put whatever your custom component here, instead of div
                            </div>,
                keepOpen:true
            },
            {
                name:"Ice Matcha Latte",
                value:3
            }
        ]

Show Filter: this will show an input, let you filter the dropdown list

     <MenuPopup 
            items = {menuData} 
            onItemClick = { (item)=> this.onMenuItemClick(item)}
            getItemText = { item => item.name }  //this will override the labelKey
            showFilter = { true }  //default false
            filterFn = { (item, text) => { return item.name.startsWith(text)} } // you can passcustom filter function here
        >
        <span>Click here </span>
    </MenuPopup>

If you got any issues, or want additional features, just let me know. hoangthai0302@gmail.com skype: thaihn_85

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.7.91latest

Version History

VersionDownloads (Last 7 Days)Published
0.7.91
0.7.80
0.7.70
0.7.60
0.7.50
0.7.40
0.7.30
0.7.20
0.7.10
0.7.00
0.6.00
0.5.70
0.5.60
0.5.50
0.5.41
0.5.30
0.5.20
0.5.10
0.5.00
0.4.50
0.4.40
0.4.30
0.4.20
0.4.10
0.4.01
0.3.20
0.3.10
0.3.00
0.2.20
0.2.10
0.2.00
0.1.90
0.1.80
0.1.70
0.1.60
0.1.50
0.1.40
0.1.30
0.1.20
0.1.10
0.1.00

Package Sidebar

Install

npm i react-menu-popup

Weekly Downloads

3

Version

0.7.9

License

MIT

Unpacked Size

1.19 MB

Total Files

12

Last publish

Collaborators

  • hoangthai