Dropdown 下拉菜单
定义/Definition
下拉菜单是由其他控件触发上的,可以通过列表项进行选择、操作。规则 / Rule
点击背景的任一位置时,可以隐藏菜单
下拉菜单项可以是选择也可以是行为(筛选、跳转…)
代码演示
// 此处用作demo展示,不要用在生产环境this.customNavFlag = true;import { Dropdown, Button, Menu } from 'antd-mobile';const SelectorDataForDropdown = [{label: '中餐',value: '21',}, {label: '还没生效',value: '22',disabled: true,}, {label: '关闭浮层',value: 'qx',}, {label: '自助餐',value: '24',}, {label: '快餐',value: '25',}, {label: '小吃',value: '26',}, {label: '面包甜点',value: '27',}, {label: '生鲜水果',value: '28',}, {label: '面食',value: '29',}, {label: '休闲食品',value: '210',}, {label: '日韩料理',value: '211',}, {label: '咖啡',value: '212',}, {label: '粤菜',value: '213',},];const Test = React.createClass({getInitialState() {return {sel: '',};},onClick() {Dropdown.show(<div style={{ padding: 8 }}><Button type="primary" onClick={() => { this.onClose('opt 1'); }}>创建层叠Dropdown</Button><div style={{ height: 8 }} /><Button type="primary" ghost onClick={() => { this.onClose('opt 2'); }}>opt 2</Button><div style={{ height: 8 }} /><Button onClick={() => { this.onClose('cancel'); }}>取消</Button></div>, { maskClosable: false });},onClose(sel) {if (sel === 'opt 1') {this.newInstance();return;}this.setState({ sel });Dropdown.hide();},newInstance() {const ins = Dropdown.newInstance();const hide = (value) => {if (value[0] === 'qx') {ins.hide();}};ins.show(<Menulevel={1}value={[SelectorDataForDropdown[0]]}data={SelectorDataForDropdown}onChange={hide}/>, { maskClosable: false });},render() {return (<div style={{ padding: 8 }}><Button type="primary" onClick={this.onClick}>show Dropdown</Button>已选项目:{this.state.sel}</div>);},});ReactDOM.render(<Test />, mountNode);

API (web)
static show(content: React.Element, options: Object):
options可选项:
maskClosable (bool) - 点击蒙层是否允许关闭,默认允许
transitionName (string) 自定义显示隐藏变换动画
maskTransitionName (string) 自定义遮罩层变换动画
static hide(): 关闭 Dropdown
static newInstance():
有些情况下,页面需要多处出现 Dropdown ,或在 Dropdown 里再产生 Dropdown。 返回 Dropdown 实例对象。对象包括:show (function) - 同 static show
hide (function) - 同 static hide
API (ios/android)
visible (bool) - 是否显示 dropdown
maskClosable (bool) - 点击蒙层是否允许关闭,默认允许
onShow (function) - 显示 dropdown 时调用
onClose (function) - 隐藏 dropdown 时调用
