Files
ant-design/components/select/index.html
T
2016-03-07 23:38:41 +08:00

1788 lines
68 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<meta name="description" content="一个 UI 设计语言"/>
<title>
Select 选择器 - Ant Design
</title>
<link rel="icon" href="https://t.alipayobjects.com/images/T1QUBfXo4fXXXXXXXX.png" type="image/x-icon">
<link rel="shortcut icon" href="https://t.alipayobjects.com/images/T1QUBfXo4fXXXXXXXX.png" type="image/x-icon">
<link rel="stylesheet" href="../../dist/demo.css?20160114">
<script src="https://as.alipayobjects.com/g/component/??console-polyfill/0.2.2/index.js,es5-shim/4.1.14/es5-shim.min.js,es5-shim/4.1.14/es5-sham.min.js,html5shiv/3.7.2/html5shiv.min.js,media-match/2.0.2/media.match.min.js,jquery/1.11.3/jquery.min.js,bluebird/3.1.1/bluebird.min.js"></script>
<script>
(function() {
window.ANT_COMPONENTS = [];
window.InstantClickChangeFns = [];
ANT_COMPONENTS.push({
title: 'Pagination',
desc: '分页'
});
ANT_COMPONENTS.push({
title: 'Affix',
desc: '固钉'
});
ANT_COMPONENTS.push({
title: 'Badge',
desc: '徽标数'
});
ANT_COMPONENTS.push({
title: 'Breadcrumb',
desc: '面包屑'
});
ANT_COMPONENTS.push({
title: 'Button',
desc: '按钮'
});
ANT_COMPONENTS.push({
title: 'Calendar',
desc: '日历'
});
ANT_COMPONENTS.push({
title: 'Carousel',
desc: '走马灯'
});
ANT_COMPONENTS.push({
title: 'Cascader',
desc: '级联选择'
});
ANT_COMPONENTS.push({
title: 'Checkbox',
desc: '多选框'
});
ANT_COMPONENTS.push({
title: 'Collapse',
desc: '折叠面板'
});
ANT_COMPONENTS.push({
title: 'DatePicker',
desc: '日期选择框'
});
ANT_COMPONENTS.push({
title: 'Dropdown',
desc: '下拉菜单'
});
ANT_COMPONENTS.push({
title: 'Form',
desc: '表单'
});
ANT_COMPONENTS.push({
title: 'Icon',
desc: '图标'
});
ANT_COMPONENTS.push({
title: 'InputNumber',
desc: '数字输入框'
});
ANT_COMPONENTS.push({
title: 'Layout',
desc: '布局'
});
ANT_COMPONENTS.push({
title: 'Menu',
desc: '导航菜单'
});
ANT_COMPONENTS.push({
title: 'Message',
desc: '全局提示'
});
ANT_COMPONENTS.push({
title: 'Modal',
desc: '对话框'
});
ANT_COMPONENTS.push({
title: 'Notification',
desc: '通知提醒框'
});
ANT_COMPONENTS.push({
title: 'Alert',
desc: '警告提示'
});
ANT_COMPONENTS.push({
title: 'Popconfirm',
desc: '气泡确认框'
});
ANT_COMPONENTS.push({
title: 'Popover',
desc: '气泡卡片'
});
ANT_COMPONENTS.push({
title: 'Progress',
desc: '进度条'
});
ANT_COMPONENTS.push({
title: 'QueueAnim',
desc: '进出场动画'
});
ANT_COMPONENTS.push({
title: 'Radio',
desc: '单选框'
});
ANT_COMPONENTS.push({
title: 'Select',
desc: '选择器'
});
ANT_COMPONENTS.push({
title: 'Slider',
desc: '滑动输入条'
});
ANT_COMPONENTS.push({
title: 'Spin',
desc: '加载中'
});
ANT_COMPONENTS.push({
title: 'Steps',
desc: '步骤条'
});
ANT_COMPONENTS.push({
title: 'Switch',
desc: '开关'
});
ANT_COMPONENTS.push({
title: 'Table',
desc: '表格'
});
ANT_COMPONENTS.push({
title: 'Tabs',
desc: '标签页'
});
ANT_COMPONENTS.push({
title: 'Tag',
desc: '标签'
});
ANT_COMPONENTS.push({
title: 'TimePicker',
desc: '时间选择框'
});
ANT_COMPONENTS.push({
title: 'Timeline',
desc: '时间轴'
});
ANT_COMPONENTS.push({
title: 'Tooltip',
desc: '文字提示'
});
ANT_COMPONENTS.push({
title: 'Transfer',
desc: '穿梭框'
});
ANT_COMPONENTS.push({
title: 'Tree',
desc: '树形控件'
});
ANT_COMPONENTS.push({
title: 'TreeSelect',
desc: '树选择'
});
ANT_COMPONENTS.push({
title: 'Upload',
desc: '文件上传'
});
// fix ie location origin
// http://stackoverflow.com/questions/22564167/window-location-origin-gives-wrong-value-when-using-ie
if (!window.location.origin) {
window.location.origin = window.location.protocol + "//"
+ window.location.hostname
+ (window.location.port ? ':' + window.location.port : '');
}
var i = location.pathname.split('/').lastIndexOf('ant-design');
if (i > 0) {
window.rootUrl = location.origin + location.pathname.split('/').slice(0, 2+1).join('/');
} else {
window.rootUrl = location.origin;
}
})();
</script>
<script>
window.antdVersion = {
latest: '0.12.8'
};
</script>
<script src="../../dist/demo.js?20160114"></script>
</head>
<body >
<header id="header" class="clearfix">
<a class="logo" href="../..">
<img width="60" src="https://t.alipayobjects.com/images/rmsweb/T1B9hfXcdvXXXXXXXX.svg">
Ant Design
</a>
<div class="search">
<div id="autoComplete"></div>
</div>
<nav class="nav" tabindex="-1">
<span class="bar"></span>
<ul>
<li class="">
<a href="../..">首页</a>
</li>
<li class="">
<a href="../../docs/practice/cases">实践</a>
</li>
<li class="">
<a href="../../docs/pattern/navigation">模式</a>
</li>
<li class="current">
<a href="../../docs/react/introduce">组件</a>
</li>
<li class="">
<a href="../../docs/spec/introduce">语言</a>
</li>
<li class="">
<a href="../../docs/resource/download">资源</a>
</li>
</ul>
</nav>
<div class="nav-phone-icon"></div>
</header>
<div class="main-wrapper">
<aside class="aside-container">
<ul>
<li class="">
<a href="../../docs/react/introduce"
class="">
Ant Design of React
<span class="chinese"></span>
</a>
</li>
<li class="">
<a href="../../docs/react/getting-started"
class="">
快速上手
<span class="chinese"></span>
</a>
</li>
<li class="">
<a href="../../docs/react/install"
class="">
安装
<span class="chinese"></span>
</a>
</li>
<li class="">
<a href="../../docs/react/upgrade-notes"
class="">
升级指南
<span class="chinese"></span>
</a>
</li>
<li class="">
<a href="../../changelog"
class="">
更新日志
<span class="chinese"></span>
</a>
</li>
<li open="open">
<h4>Components</h4>
<ul class="">
<li class="type-divider">基本</li>
<li class="">
<a href="../button/"
class="">
Button
<span class="chinese">按钮</span>
</a>
</li>
<li class="">
<a href="../icon/"
class="">
Icon
<span class="chinese">图标</span>
</a>
</li>
<li class="">
<a href="../layout/"
class="">
Layout
<span class="chinese">布局</span>
</a>
</li>
<li class="type-divider">表单</li>
<li class="">
<a href="../cascader/"
class="">
Cascader
<span class="chinese">级联选择</span>
</a>
</li>
<li class="">
<a href="../checkbox/"
class="">
Checkbox
<span class="chinese">多选框</span>
</a>
</li>
<li class="">
<a href="../date-picker/"
class="">
DatePicker
<span class="chinese">日期选择框</span>
</a>
</li>
<li class="">
<a href="../form/"
class="">
Form
<span class="chinese">表单</span>
</a>
</li>
<li class="">
<a href="../input-number/"
class="">
InputNumber
<span class="chinese">数字输入框</span>
</a>
</li>
<li class="">
<a href="../radio/"
class="">
Radio
<span class="chinese">单选框</span>
</a>
</li>
<li class="current">
<a href="./"
class="">
Select
<span class="chinese">选择器</span>
</a>
</li>
<li class="">
<a href="../slider/"
class="">
Slider
<span class="chinese">滑动输入条</span>
</a>
</li>
<li class="">
<a href="../switch/"
class="">
Switch
<span class="chinese">开关</span>
</a>
</li>
<li class="">
<a href="../time-picker/"
class="">
TimePicker
<span class="chinese">时间选择框</span>
</a>
</li>
<li class="">
<a href="../transfer/"
class="">
Transfer
<span class="chinese">穿梭框</span>
</a>
</li>
<li class="">
<a href="../tree-select/"
class="">
TreeSelect
<span class="chinese">树选择</span>
</a>
</li>
<li class="">
<a href="../upload/"
class="">
Upload
<span class="chinese">文件上传</span>
</a>
</li>
<li class="type-divider">展示</li>
<li class="">
<a href="../alert/"
class="">
Alert
<span class="chinese">警告提示</span>
</a>
</li>
<li class="">
<a href="../badge/"
class="">
Badge
<span class="chinese">徽标数</span>
</a>
</li>
<li class="">
<a href="../calendar/"
class="">
Calendar
<span class="chinese">日历</span>
</a>
</li>
<li class="">
<a href="../carousel/"
class="">
Carousel
<span class="chinese">走马灯</span>
</a>
</li>
<li class="">
<a href="../collapse/"
class="">
Collapse
<span class="chinese">折叠面板</span>
</a>
</li>
<li class="">
<a href="../dropdown/"
class="">
Dropdown
<span class="chinese">下拉菜单</span>
</a>
</li>
<li class="">
<a href="../message/"
class=""data-no-instant>
Message
<span class="chinese">全局提示</span>
</a>
</li>
<li class="">
<a href="../modal/"
class="">
Modal
<span class="chinese">对话框</span>
</a>
</li>
<li class="">
<a href="../notification/"
class=""data-no-instant>
Notification
<span class="chinese">通知提醒框</span>
</a>
</li>
<li class="">
<a href="../popconfirm/"
class="">
Popconfirm
<span class="chinese">气泡确认框</span>
</a>
</li>
<li class="">
<a href="../popover/"
class="">
Popover
<span class="chinese">气泡卡片</span>
</a>
</li>
<li class="">
<a href="../progress/"
class="">
Progress
<span class="chinese">进度条</span>
</a>
</li>
<li class="">
<a href="../table/"
class="">
Table
<span class="chinese">表格</span>
</a>
</li>
<li class="">
<a href="../tag/"
class="">
Tag
<span class="chinese">标签</span>
</a>
</li>
<li class="">
<a href="../timeline/"
class="">
Timeline
<span class="chinese">时间轴</span>
</a>
</li>
<li class="">
<a href="../tooltip/"
class="">
Tooltip
<span class="chinese">文字提示</span>
</a>
</li>
<li class="">
<a href="../tree/"
class="">
Tree
<span class="chinese">树形控件</span>
</a>
</li>
<li class="type-divider">导航</li>
<li class="">
<a href="../breadcrumb/"
class="">
Breadcrumb
<span class="chinese">面包屑</span>
</a>
</li>
<li class="">
<a href="../menu/"
class="">
Menu
<span class="chinese">导航菜单</span>
</a>
</li>
<li class="">
<a href="../pagination/"
class="">
Pagination
<span class="chinese">分页</span>
</a>
</li>
<li class="">
<a href="../steps/"
class="">
Steps
<span class="chinese">步骤条</span>
</a>
</li>
<li class="">
<a href="../tabs/"
class="">
Tabs
<span class="chinese">标签页</span>
</a>
</li>
<li class="type-divider">其他</li>
<li class="">
<a href="../affix/"
class="">
Affix
<span class="chinese">固钉</span>
</a>
</li>
<li class="">
<a href="../queue-anim/"
class="">
QueueAnim
<span class="chinese">进出场动画</span>
</a>
</li>
<li class="">
<a href="../spin/"
class="">
Spin
<span class="chinese">加载中</span>
</a>
</li>
</ul>
</li>
</ul>
</aside>
<section class="main-container">
<article class="markdown">
<h1>
Select 选择器
</h1>
<p>类似 Select2 的选择器。</p>
<h2 id="何时使用">何时使用<a href="#何时使用" class="anchor">#</a> </h2><p>弹出一个下拉菜单给用户选择操作,用于代替原生的选择器,或者需要一个更优雅的多选器时。</p>
<div class="highlight"><pre><code class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">Select</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"lucy"</span>&gt;</span>lucy<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">Select</span>&gt;</span></code></pre></div><h2 id="api">API<a href="#api" class="anchor">#</a> </h2><h3 id="select-props">Select props<a href="#select-props" class="anchor">#</a> </h3><table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
<th>类型</th>
<th>默认值</th>
</tr>
</thead>
<tbody>
<tr>
<td>value</td>
<td>指定当前选中的条目</td>
<td>string/Array<String></td>
<td></td>
</tr>
<tr>
<td>defaultValue</td>
<td>指定默认选中的条目</td>
<td>string/Array<String></td>
<td></td>
</tr>
<tr>
<td>multiple</td>
<td>支持多选</td>
<td>boolean</td>
<td>false</td>
</tr>
<tr>
<td>allowClear</td>
<td>支持清除, 单选模式有效</td>
<td>boolean</td>
<td>false</td>
</tr>
<tr>
<td>filterOption</td>
<td>是否根据输入项进行筛选,可为一个函数,返回满足要求的 option 即可</td>
<td>boolean or function(inputValue, option)</td>
<td>true</td>
</tr>
<tr>
<td>tags</td>
<td>可以把随意输入的条目作为 tag,输入项不需要与下拉选项匹配</td>
<td>boolean</td>
<td>false</td>
</tr>
<tr>
<td>onSelect</td>
<td>被选中时调用,参数为选中项的 value 值</td>
<td>function(value, option)</td>
<td></td>
</tr>
<tr>
<td>onDeselect</td>
<td>取消选中时调用,参数为选中项的 option value 值,仅在 multiple 或 tags 模式下生效</td>
<td>function(value, option)</td>
<td></td>
</tr>
<tr>
<td>onChange</td>
<td>选中option,或input的value变化(combobox 模式下)时,调用此函数</td>
<td>function(value, label)</td>
<td></td>
</tr>
<tr>
<td>onSearch</td>
<td>文本框值变化时回调</td>
<td>function(value: String)</td>
<td></td>
</tr>
<tr>
<td>placeholder</td>
<td>选择框默认文字</td>
<td>string</td>
<td></td>
</tr>
<tr>
<td>searchPlaceholder</td>
<td>搜索框默认文字</td>
<td>string</td>
<td></td>
</tr>
<tr>
<td>notFoundContent</td>
<td>当下拉列表为空时显示的内容</td>
<td>string</td>
<td>&#39;Not Found&#39;</td>
</tr>
<tr>
<td>dropdownMatchSelectWidth</td>
<td>下拉菜单和选择器同宽</td>
<td>boolean</td>
<td>true</td>
</tr>
<tr>
<td>optionFilterProp</td>
<td>搜索时过滤对应的 option 属性,如设置为 children 表示对内嵌内容进行搜索</td>
<td>string</td>
<td>value</td>
</tr>
<tr>
<td>combobox</td>
<td>输入框自动提示模式</td>
<td>boolean</td>
<td>false</td>
</tr>
<tr>
<td>size</td>
<td>选择框大小,可选 <code>large</code> <code>small</code></td>
<td>String</td>
<td>default</td>
</tr>
<tr>
<td>showSearch</td>
<td>在下拉中显示搜索框</td>
<td>boolean</td>
<td>false</td>
</tr>
<tr>
<td>disabled</td>
<td>是否禁用</td>
<td>boolean</td>
<td>false</td>
</tr>
</tbody>
</table>
<h3 id="option-props">Option props<a href="#option-props" class="anchor">#</a> </h3><table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
<th>类型</th>
<th>默认值</th>
</tr>
</thead>
<tbody>
<tr>
<td>disabled</td>
<td>是否禁用</td>
<td>Boolean</td>
<td>false</td>
</tr>
<tr>
<td>key</td>
<td>如果 react 需要你设置此项,此项值与 value 的值相同,然后可以省略 value 设置</td>
<td>String</td>
<td></td>
</tr>
<tr>
<td>value</td>
<td>默认根据此属性值进行筛选</td>
<td>String</td>
<td>-</td>
</tr>
</tbody>
</table>
<h3 id="optgroup-props">OptGroup props<a href="#optgroup-props" class="anchor">#</a> </h3><table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
<th>类型</th>
<th>默认值</th>
</tr>
</thead>
<tbody>
<tr>
<td>label</td>
<td>组名</td>
<td>String/React.Element</td>
<td></td>
</tr>
<tr>
<td>key</td>
<td></td>
<td>String</td>
<td>-</td>
</tr>
</tbody>
</table>
</article>
<h2 class="component-demos">
代码演示
<i class="anticon anticon-appstore icon-all" title="展开全部代码"></i>
</h2>
<div class="code-boxes">
<div class="code-boxes-col-2-1"><div class="code-box" id="demo-basic">
<div class="code-box-demo">
<div id="components-select-demo-basic"></div>
<script>mountNode = document.getElementById('components-select-demo-basic');</script>
<script>(function(){"use strict";
var _antd = require("antd");
var Option = _antd.Select.Option;
function handleChange(value) {
console.log("selected " + value);
}
ReactDOM.render(React.createElement(
"div",
null,
React.createElement(
_antd.Select,
{ defaultValue: "lucy", style: { width: 120 }, onChange: handleChange },
React.createElement(
Option,
{ value: "jack" },
"Jack"
),
React.createElement(
Option,
{ value: "lucy" },
"Lucy"
),
React.createElement(
Option,
{ value: "disabled", disabled: true },
"Disabled"
),
React.createElement(
Option,
{ value: "yiminghe" },
"yiminghe"
)
),
React.createElement(
_antd.Select,
{ defaultValue: "lucy", style: { width: 120 }, disabled: true },
React.createElement(
Option,
{ value: "lucy" },
"Lucy"
)
)
), mountNode);})()</script><div class="highlight"><pre><code class="javascript"><span class="hljs-keyword">import</span> { Select } <span class="hljs-keyword">from</span> <span class="hljs-string">'antd'</span>;
<span class="hljs-keyword">const</span> Option = Select.Option;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handleChange</span>(<span class="hljs-params">value</span>) </span>{
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">`selected <span class="hljs-subst">${value}</span>`</span>);
}
ReactDOM.render(
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Select</span> <span class="hljs-attribute">defaultValue</span>=<span class="hljs-value">"lucy"</span> <span class="hljs-attribute">style</span>=<span class="hljs-value">{{</span> <span class="hljs-attribute">width:</span> <span class="hljs-attribute">120</span> }} <span class="hljs-attribute">onChange</span>=<span class="hljs-value">{handleChange}</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"jack"</span>&gt;</span>Jack<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"lucy"</span>&gt;</span>Lucy<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"disabled"</span> <span class="hljs-attribute">disabled</span>&gt;</span>Disabled<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"yiminghe"</span>&gt;</span>yiminghe<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">Select</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Select</span> <span class="hljs-attribute">defaultValue</span>=<span class="hljs-value">"lucy"</span> <span class="hljs-attribute">style</span>=<span class="hljs-value">{{</span> <span class="hljs-attribute">width:</span> <span class="hljs-attribute">120</span> }} <span class="hljs-attribute">disabled</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"lucy"</span>&gt;</span>Lucy<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">Select</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
, mountNode);</span></code></pre></div>
</div>
<div class="code-box-meta markdown">
<div class="code-box-title">
<a href="#demo-basic">基本使用</a>
</div>
<p>基本使用。</p>
<span class="collapse anticon anticon-circle-o-right" unselectable="none"></span>
</div>
</div><div class="code-box" id="demo-search">
<div class="code-box-demo">
<div id="components-select-demo-search"></div>
<script>mountNode = document.getElementById('components-select-demo-search');</script>
<script>(function(){"use strict";
var _antd = require("antd");
var Option = _antd.Select.Option;
function handleChange(value) {
console.log("selected " + value);
}
ReactDOM.render(React.createElement(
_antd.Select,
{ showSearch: true,
style: { width: 200 },
placeholder: "请选择人员",
optionFilterProp: "children",
notFoundContent: "无法找到",
searchPlaceholder: "输入关键词",
onChange: handleChange },
React.createElement(
Option,
{ value: "jack" },
"杰克"
),
React.createElement(
Option,
{ value: "lucy" },
"露西"
),
React.createElement(
Option,
{ value: "tom" },
"汤姆"
)
), mountNode);})()</script><div class="highlight"><pre><code class="javascript"><span class="hljs-keyword">import</span> { Select } <span class="hljs-keyword">from</span> <span class="hljs-string">'antd'</span>;
<span class="hljs-keyword">const</span> Option = Select.Option;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handleChange</span>(<span class="hljs-params">value</span>) </span>{
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">`selected <span class="hljs-subst">${value}</span>`</span>);
}
ReactDOM.render(
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">Select</span> <span class="hljs-attribute">showSearch</span>
<span class="hljs-attribute">style</span>=<span class="hljs-value">{{</span> <span class="hljs-attribute">width:</span> <span class="hljs-attribute">200</span> }}
<span class="hljs-attribute">placeholder</span>=<span class="hljs-value">"请选择人员"</span>
<span class="hljs-attribute">optionFilterProp</span>=<span class="hljs-value">"children"</span>
<span class="hljs-attribute">notFoundContent</span>=<span class="hljs-value">"无法找到"</span>
<span class="hljs-attribute">searchPlaceholder</span>=<span class="hljs-value">"输入关键词"</span>
<span class="hljs-attribute">onChange</span>=<span class="hljs-value">{handleChange}</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"jack"</span>&gt;</span>杰克<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"lucy"</span>&gt;</span>露西<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"tom"</span>&gt;</span>汤姆<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">Select</span>&gt;</span>
, mountNode);</span></code></pre></div>
</div>
<div class="code-box-meta markdown">
<div class="code-box-title">
<a href="#demo-search">带搜索框</a>
</div>
<p>在浮层内顶部有搜索框的单项选择器。</p>
<span class="collapse anticon anticon-circle-o-right" unselectable="none"></span>
</div>
</div><div class="code-box" id="demo-tags">
<div class="code-box-demo">
<div id="components-select-demo-tags"></div>
<script>mountNode = document.getElementById('components-select-demo-tags');</script>
<script>(function(){'use strict';
var _antd = require('antd');
var Option = _antd.Select.Option;
var children = [];
for (var i = 10; i < 36; i++) {
children.push(React.createElement(
Option,
{ key: i.toString(36) + i },
i.toString(36) + i
));
}
function handleChange(value) {
console.log('selected ' + value);
}
ReactDOM.render(React.createElement(
_antd.Select,
{ tags: true,
style: { width: '100%' },
searchPlaceholder: '标签模式',
onChange: handleChange },
children
), mountNode);})()</script><div class="highlight"><pre><code class="javascript"><span class="hljs-keyword">import</span> { Select } <span class="hljs-keyword">from</span> <span class="hljs-string">'antd'</span>;
<span class="hljs-keyword">const</span> Option = Select.Option;
<span class="hljs-keyword">let</span> children = [];
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">10</span>; i &lt; <span class="hljs-number">36</span>; i++) {
children.push(<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">key</span>=<span class="hljs-value">{i.toString(36)</span> + <span class="hljs-attribute">i</span>}&gt;</span>{i.toString(36) + i}<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>)</span>;
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handleChange</span>(<span class="hljs-params">value</span>) </span>{
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">`selected <span class="hljs-subst">${value}</span>`</span>);
}
ReactDOM.render(
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">Select</span> <span class="hljs-attribute">tags</span>
<span class="hljs-attribute">style</span>=<span class="hljs-value">{{</span> <span class="hljs-attribute">width:</span> '<span class="hljs-attribute">100</span>%' }}
<span class="hljs-attribute">searchPlaceholder</span>=<span class="hljs-value">"标签模式"</span>
<span class="hljs-attribute">onChange</span>=<span class="hljs-value">{handleChange}</span>&gt;</span>
{children}
<span class="hljs-tag">&lt;/<span class="hljs-title">Select</span>&gt;</span>
, mountNode);</span></code></pre></div>
</div>
<div class="code-box-meta markdown">
<div class="code-box-title">
<a href="#demo-tags">标签</a>
</div>
<p>tags select,随意输入的内容(scroll the menu</p>
<span class="collapse anticon anticon-circle-o-right" unselectable="none"></span>
</div>
</div><div class="code-box" id="demo-optgroup">
<div class="code-box-demo">
<div id="components-select-demo-optgroup"></div>
<script>mountNode = document.getElementById('components-select-demo-optgroup');</script>
<script>(function(){"use strict";
var _antd = require("antd");
var Option = _antd.Select.Option;
var OptGroup = _antd.Select.OptGroup;
function handleChange(value) {
console.log("selected " + value);
}
ReactDOM.render(React.createElement(
_antd.Select,
{ defaultValue: "lucy",
style: { width: 200 },
showSearch: false,
onChange: handleChange },
React.createElement(
OptGroup,
{ label: "Manager" },
React.createElement(
Option,
{ value: "jack" },
"jack"
),
React.createElement(
Option,
{ value: "lucy" },
"lucy"
)
),
React.createElement(
OptGroup,
{ label: "Engineer" },
React.createElement(
Option,
{ value: "yiminghe" },
"yiminghe"
)
)
), mountNode);})()</script><div class="highlight"><pre><code class="javascript"><span class="hljs-keyword">import</span> { Select } <span class="hljs-keyword">from</span> <span class="hljs-string">'antd'</span>;
<span class="hljs-keyword">const</span> Option = Select.Option;
<span class="hljs-keyword">const</span> OptGroup = Select.OptGroup;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handleChange</span>(<span class="hljs-params">value</span>) </span>{
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">`selected <span class="hljs-subst">${value}</span>`</span>);
}
ReactDOM.render(
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">Select</span> <span class="hljs-attribute">defaultValue</span>=<span class="hljs-value">"lucy"</span>
<span class="hljs-attribute">style</span>=<span class="hljs-value">{{</span> <span class="hljs-attribute">width:</span> <span class="hljs-attribute">200</span> }}
<span class="hljs-attribute">showSearch</span>=<span class="hljs-value">{false}</span>
<span class="hljs-attribute">onChange</span>=<span class="hljs-value">{handleChange}</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">OptGroup</span> <span class="hljs-attribute">label</span>=<span class="hljs-value">"Manager"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"jack"</span>&gt;</span>jack<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"lucy"</span>&gt;</span>lucy<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">OptGroup</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">OptGroup</span> <span class="hljs-attribute">label</span>=<span class="hljs-value">"Engineer"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"yiminghe"</span>&gt;</span>yiminghe<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">OptGroup</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">Select</span>&gt;</span>
, mountNode);</span></code></pre></div>
</div>
<div class="code-box-meta markdown">
<div class="code-box-title">
<a href="#demo-optgroup">分组</a>
</div>
<p><code>OptGroup</code> 进行选项分组。</p>
<span class="collapse anticon anticon-circle-o-right" unselectable="none"></span>
</div>
</div><div class="code-box" id="demo-search-box">
<div class="code-box-demo">
<div id="components-select-demo-search-box"></div>
<script>mountNode = document.getElementById('components-select-demo-search-box');</script>
<script>(function(){'use strict';
var _antd = require('antd');
var _jsonp = require('jsonp');
var _jsonp2 = _interopRequireDefault(_jsonp);
var _querystring = require('querystring');
var _querystring2 = _interopRequireDefault(_querystring);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Option = _antd.Select.Option;
var timeout = void 0;
var currentValue = void 0;
function fetch(value, callback) {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
currentValue = value;
function fake() {
var str = _querystring2.default.encode({
code: 'utf-8',
q: value
});
(0, _jsonp2.default)('http://suggest.taobao.com/sug?' + str, function (err, d) {
if (currentValue === value) {
(function () {
var result = d.result;
var data = [];
result.forEach(function (r) {
data.push({
value: r[0],
text: r[0]
});
});
callback(data);
})();
}
});
}
timeout = setTimeout(fake, 300);
}
var SearchInput = React.createClass({
displayName: 'SearchInput',
getInitialState: function getInitialState() {
return {
data: [],
value: '',
focus: false
};
},
handleChange: function handleChange(value) {
var _this = this;
this.setState({ value: value });
fetch(value, function (data) {
return _this.setState({ data: data });
});
},
handleSubmit: function handleSubmit() {
console.log('输入框内容是: ', this.state.value);
},
handleFocusBlur: function handleFocusBlur(e) {
this.setState({
focus: e.target === document.activeElement
});
},
render: function render() {
var btnCls = (0, _classnames2.default)({
'ant-search-btn': true,
'ant-search-btn-noempty': !!this.state.value.trim()
});
var searchCls = (0, _classnames2.default)({
'ant-search-input': true,
'ant-search-input-focus': this.state.focus
});
var options = this.state.data.map(function (d) {
return React.createElement(
Option,
{ key: d.value },
d.text
);
});
return React.createElement(
_antd.Input.Group,
{ className: searchCls, style: this.props.style },
React.createElement(
_antd.Select,
{
combobox: true,
value: this.state.value,
searchPlaceholder: this.props.placeholder,
notFoundContent: '',
defaultActiveFirstOption: false,
showArrow: false,
filterOption: false,
onChange: this.handleChange,
onFocus: this.handleFocusBlur,
onBlur: this.handleFocusBlur },
options
),
React.createElement(
'div',
{ className: 'ant-input-group-wrap' },
React.createElement(
_antd.Button,
{ className: btnCls, onClick: this.handleSubmit },
React.createElement(_antd.Icon, { type: 'search' })
)
)
);
}
});
ReactDOM.render(React.createElement(SearchInput, { placeholder: 'input search text', style: { width: 200 } }), mountNode);})()</script><div class="highlight"><pre><code class="javascript"><span class="hljs-keyword">import</span> { Input, Select, Button, Icon } <span class="hljs-keyword">from</span> <span class="hljs-string">'antd'</span>;
<span class="hljs-keyword">import</span> jsonp <span class="hljs-keyword">from</span> <span class="hljs-string">'jsonp'</span>;
<span class="hljs-keyword">import</span> querystring <span class="hljs-keyword">from</span> <span class="hljs-string">'querystring'</span>;
<span class="hljs-keyword">import</span> classNames <span class="hljs-keyword">from</span> <span class="hljs-string">'classnames'</span>;
<span class="hljs-keyword">const</span> Option = Select.Option;
<span class="hljs-keyword">let</span> timeout;
<span class="hljs-keyword">let</span> currentValue;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fetch</span>(<span class="hljs-params">value, callback</span>) </span>{
<span class="hljs-keyword">if</span> (timeout) {
clearTimeout(timeout);
timeout = <span class="hljs-literal">null</span>;
}
currentValue = value;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fake</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-keyword">const</span> str = querystring.encode({
code: <span class="hljs-string">'utf-8'</span>,
q: value,
});
jsonp(<span class="hljs-string">`http://suggest.taobao.com/sug?<span class="hljs-subst">${str}</span>`</span>, (err, d) =&gt; {
<span class="hljs-keyword">if</span> (currentValue === value) {
<span class="hljs-keyword">const</span> result = d.result;
<span class="hljs-keyword">const</span> data = [];
result.forEach((r) =&gt; {
data.push({
value: r[<span class="hljs-number">0</span>],
text: r[<span class="hljs-number">0</span>],
});
});
callback(data);
}
});
}
timeout = setTimeout(fake, <span class="hljs-number">300</span>);
}
<span class="hljs-keyword">const</span> SearchInput = React.createClass({
getInitialState() {
<span class="hljs-keyword">return</span> {
data: [],
value: <span class="hljs-string">''</span>,
focus: <span class="hljs-literal">false</span>,
};
},
handleChange(value) {
<span class="hljs-keyword">this</span>.setState({ value });
fetch(value, (data) =&gt; <span class="hljs-keyword">this</span>.setState({ data }));
},
handleSubmit() {
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'输入框内容是: '</span>, <span class="hljs-keyword">this</span>.state.value);
},
handleFocusBlur(e) {
<span class="hljs-keyword">this</span>.setState({
focus: e.target === <span class="hljs-built_in">document</span>.activeElement,
});
},
render() {
<span class="hljs-keyword">const</span> btnCls = classNames({
<span class="hljs-string">'ant-search-btn'</span>: <span class="hljs-literal">true</span>,
<span class="hljs-string">'ant-search-btn-noempty'</span>: !!<span class="hljs-keyword">this</span>.state.value.trim(),
});
<span class="hljs-keyword">const</span> searchCls = classNames({
<span class="hljs-string">'ant-search-input'</span>: <span class="hljs-literal">true</span>,
<span class="hljs-string">'ant-search-input-focus'</span>: <span class="hljs-keyword">this</span>.state.focus,
});
<span class="hljs-keyword">const</span> options = <span class="hljs-keyword">this</span>.state.data.map(d =&gt; <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">key</span>=<span class="hljs-value">{d.value}</span>&gt;</span>{d.text}<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>)</span>;
<span class="hljs-keyword">return</span> (
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">Input.Group</span> <span class="hljs-attribute">className</span>=<span class="hljs-value">{searchCls}</span> <span class="hljs-attribute">style</span>=<span class="hljs-value">{this.props.style}</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Select</span>
<span class="hljs-attribute">combobox</span>
<span class="hljs-attribute">value</span>=<span class="hljs-value">{this.state.value}</span>
<span class="hljs-attribute">searchPlaceholder</span>=<span class="hljs-value">{this.props.placeholder}</span>
<span class="hljs-attribute">notFoundContent</span>=<span class="hljs-value">""</span>
<span class="hljs-attribute">defaultActiveFirstOption</span>=<span class="hljs-value">{false}</span>
<span class="hljs-attribute">showArrow</span>=<span class="hljs-value">{false}</span>
<span class="hljs-attribute">filterOption</span>=<span class="hljs-value">{false}</span>
<span class="hljs-attribute">onChange</span>=<span class="hljs-value">{this.handleChange}</span>
<span class="hljs-attribute">onFocus</span>=<span class="hljs-value">{this.handleFocusBlur}</span>
<span class="hljs-attribute">onBlur</span>=<span class="hljs-value">{this.handleFocusBlur}</span>&gt;</span>
{options}
<span class="hljs-tag">&lt;/<span class="hljs-title">Select</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">className</span>=<span class="hljs-value">"ant-input-group-wrap"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Button</span> <span class="hljs-attribute">className</span>=<span class="hljs-value">{btnCls}</span> <span class="hljs-attribute">onClick</span>=<span class="hljs-value">{this.handleSubmit}</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Icon</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">"search"</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">Button</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">Input.Group</span>&gt;</span>
)</span>;
},
});
ReactDOM.render(
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">SearchInput</span> <span class="hljs-attribute">placeholder</span>=<span class="hljs-value">"input search text"</span> <span class="hljs-attribute">style</span>=<span class="hljs-value">{{</span> <span class="hljs-attribute">width:</span> <span class="hljs-attribute">200</span> }} /&gt;</span>
, mountNode);</span></code></pre></div>
</div>
<div class="code-box-meta markdown">
<div class="code-box-title">
<a href="#demo-search-box">搜索框</a>
</div>
<p>带有搜索按钮的自动补全输入框。</p>
<span class="collapse anticon anticon-circle-o-right" unselectable="none"></span>
</div>
</div>
</div>
<div class="code-boxes-col-2-1"><div class="code-box" id="demo-size">
<div class="code-box-demo">
<div id="components-select-demo-size"></div>
<script>mountNode = document.getElementById('components-select-demo-size');</script>
<script>(function(){"use strict";
var _antd = require("antd");
var Option = _antd.Select.Option;
function handleChange(value) {
console.log("selected " + value);
}
ReactDOM.render(React.createElement(
"div",
null,
React.createElement(
_antd.Select,
{ size: "large", defaultValue: "lucy", style: { width: 200 }, onChange: handleChange },
React.createElement(
Option,
{ value: "jack" },
"Jack"
),
React.createElement(
Option,
{ value: "lucy" },
"Lucy"
),
React.createElement(
Option,
{ value: "disabled", disabled: true },
"Disabled"
),
React.createElement(
Option,
{ value: "yiminghe" },
"yiminghe"
)
),
React.createElement(
_antd.Select,
{ defaultValue: "lucy", style: { width: 200 }, onChange: handleChange },
React.createElement(
Option,
{ value: "jack" },
"Jack"
),
React.createElement(
Option,
{ value: "lucy" },
"Lucy"
),
React.createElement(
Option,
{ value: "disabled", disabled: true },
"Disabled"
),
React.createElement(
Option,
{ value: "yiminghe" },
"yiminghe"
)
),
React.createElement(
_antd.Select,
{ size: "small", defaultValue: "lucy", style: { width: 200 }, onChange: handleChange },
React.createElement(
Option,
{ value: "jack" },
"Jack"
),
React.createElement(
Option,
{ value: "lucy" },
"Lucy"
),
React.createElement(
Option,
{ value: "disabled", disabled: true },
"Disabled"
),
React.createElement(
Option,
{ value: "yiminghe" },
"yiminghe"
)
)
), mountNode);})()</script><div class="highlight"><pre><code class="javascript"><span class="hljs-keyword">import</span> { Select } <span class="hljs-keyword">from</span> <span class="hljs-string">'antd'</span>;
<span class="hljs-keyword">const</span> Option = Select.Option;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handleChange</span>(<span class="hljs-params">value</span>) </span>{
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">`selected <span class="hljs-subst">${value}</span>`</span>);
}
ReactDOM.render(
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Select</span> <span class="hljs-attribute">size</span>=<span class="hljs-value">"large"</span> <span class="hljs-attribute">defaultValue</span>=<span class="hljs-value">"lucy"</span> <span class="hljs-attribute">style</span>=<span class="hljs-value">{{</span> <span class="hljs-attribute">width:</span> <span class="hljs-attribute">200</span> }} <span class="hljs-attribute">onChange</span>=<span class="hljs-value">{handleChange}</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"jack"</span>&gt;</span>Jack<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"lucy"</span>&gt;</span>Lucy<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"disabled"</span> <span class="hljs-attribute">disabled</span>&gt;</span>Disabled<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"yiminghe"</span>&gt;</span>yiminghe<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">Select</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Select</span> <span class="hljs-attribute">defaultValue</span>=<span class="hljs-value">"lucy"</span> <span class="hljs-attribute">style</span>=<span class="hljs-value">{{</span> <span class="hljs-attribute">width:</span> <span class="hljs-attribute">200</span> }} <span class="hljs-attribute">onChange</span>=<span class="hljs-value">{handleChange}</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"jack"</span>&gt;</span>Jack<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"lucy"</span>&gt;</span>Lucy<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"disabled"</span> <span class="hljs-attribute">disabled</span>&gt;</span>Disabled<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"yiminghe"</span>&gt;</span>yiminghe<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">Select</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Select</span> <span class="hljs-attribute">size</span>=<span class="hljs-value">"small"</span> <span class="hljs-attribute">defaultValue</span>=<span class="hljs-value">"lucy"</span> <span class="hljs-attribute">style</span>=<span class="hljs-value">{{</span> <span class="hljs-attribute">width:</span> <span class="hljs-attribute">200</span> }} <span class="hljs-attribute">onChange</span>=<span class="hljs-value">{handleChange}</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"jack"</span>&gt;</span>Jack<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"lucy"</span>&gt;</span>Lucy<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"disabled"</span> <span class="hljs-attribute">disabled</span>&gt;</span>Disabled<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"yiminghe"</span>&gt;</span>yiminghe<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">Select</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
, mountNode);</span></code></pre></div><style type="text/css">.code-box-demo .ant-select {
margin: 0 8px 10px 0;
}</style><div class="highlight"><pre><code class="css"><span class="hljs-class">.code-box-demo</span> <span class="hljs-class">.ant-select</span> <span class="hljs-rules">{
<span class="hljs-rule"><span class="hljs-attribute">margin</span>:<span class="hljs-value"> <span class="hljs-number">0</span> <span class="hljs-number">8px</span> <span class="hljs-number">10px</span> <span class="hljs-number">0</span></span></span>;
}</span></code></pre></div>
</div>
<div class="code-box-meta markdown">
<div class="code-box-title">
<a href="#demo-size">三种大小</a>
</div>
<p>三种大小的选择框,当 size 分别为 <code>large</code><code>small</code> 时,输入框高度为 <code>32px</code><code>22px</code> ,默认高度为 <code>28px</code></p>
<span class="collapse anticon anticon-circle-o-right" unselectable="none"></span>
</div>
</div><div class="code-box" id="demo-multiple">
<div class="code-box-demo">
<div id="components-select-demo-multiple"></div>
<script>mountNode = document.getElementById('components-select-demo-multiple');</script>
<script>(function(){'use strict';
var _antd = require('antd');
var Option = _antd.Select.Option;
var children = [];
for (var i = 10; i < 36; i++) {
children.push(React.createElement(
Option,
{ key: i.toString(36) + i },
i.toString(36) + i
));
}
function handleChange(value) {
console.log('selected ' + value);
}
ReactDOM.render(React.createElement(
_antd.Select,
{ multiple: true,
style: { width: 400 },
defaultValue: ['a10', 'c12'], onChange: handleChange },
children
), mountNode);})()</script><div class="highlight"><pre><code class="javascript"><span class="hljs-keyword">import</span> { Select } <span class="hljs-keyword">from</span> <span class="hljs-string">'antd'</span>;
<span class="hljs-keyword">const</span> Option = Select.Option;
<span class="hljs-keyword">let</span> children = [];
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">10</span>; i &lt; <span class="hljs-number">36</span>; i++) {
children.push(<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">key</span>=<span class="hljs-value">{i.toString(36)</span> + <span class="hljs-attribute">i</span>}&gt;</span>{i.toString(36) + i}<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>)</span>;
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handleChange</span>(<span class="hljs-params">value</span>) </span>{
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">`selected <span class="hljs-subst">${value}</span>`</span>);
}
ReactDOM.render(
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">Select</span> <span class="hljs-attribute">multiple</span>
<span class="hljs-attribute">style</span>=<span class="hljs-value">{{</span> <span class="hljs-attribute">width:</span> <span class="hljs-attribute">400</span> }}
<span class="hljs-attribute">defaultValue</span>=<span class="hljs-value">{['a10',</span> '<span class="hljs-attribute">c12</span>']} <span class="hljs-attribute">onChange</span>=<span class="hljs-value">{handleChange}</span>&gt;</span>
{children}
<span class="hljs-tag">&lt;/<span class="hljs-title">Select</span>&gt;</span>
, mountNode);</span></code></pre></div>
</div>
<div class="code-box-meta markdown">
<div class="code-box-title">
<a href="#demo-multiple">多选</a>
</div>
<p>多选,从已有条目中选择(scroll the menu</p>
<span class="collapse anticon anticon-circle-o-right" unselectable="none"></span>
</div>
</div><div class="code-box" id="demo-combobox">
<div class="code-box-demo">
<div id="components-select-demo-combobox"></div>
<script>mountNode = document.getElementById('components-select-demo-combobox');</script>
<script>(function(){'use strict';
var _antd = require('antd');
var Option = _antd.Select.Option;
var Test = React.createClass({
displayName: 'Test',
getInitialState: function getInitialState() {
return {
options: []
};
},
handleChange: function handleChange(value) {
var options = void 0;
if (!value || value.indexOf('@') >= 0) {
options = [];
} else {
options = ['gmail.com', '163.com', 'qq.com'].map(function (domain) {
var email = value + '@' + domain;
return React.createElement(
Option,
{ key: email },
email
);
});
}
this.setState({ options: options });
},
render: function render() {
// filterOption 需要设置为 false,数据是动态设置的
return React.createElement(
_antd.Select,
{ combobox: true,
style: { width: 200 },
onChange: this.handleChange,
filterOption: false,
placeholder: '请输入账户名' },
this.state.options
);
}
});
ReactDOM.render(React.createElement(Test, null), mountNode);})()</script><div class="highlight"><pre><code class="javascript"><span class="hljs-keyword">import</span> { Select } <span class="hljs-keyword">from</span> <span class="hljs-string">'antd'</span>;
<span class="hljs-keyword">const</span> Option = Select.Option;
<span class="hljs-keyword">const</span> Test = React.createClass({
getInitialState() {
<span class="hljs-keyword">return</span> {
options: []
};
},
handleChange(value) {
<span class="hljs-keyword">let</span> options;
<span class="hljs-keyword">if</span> (!value || value.indexOf(<span class="hljs-string">'@'</span>) &gt;= <span class="hljs-number">0</span>) {
options = [];
} <span class="hljs-keyword">else</span> {
options = [<span class="hljs-string">'gmail.com'</span>, <span class="hljs-string">'163.com'</span>, <span class="hljs-string">'qq.com'</span>].map((domain) =&gt; {
<span class="hljs-keyword">const</span> email = <span class="hljs-string">`<span class="hljs-subst">${value}</span>@<span class="hljs-subst">${domain}</span>`</span>;
<span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">key</span>=<span class="hljs-value">{email}</span>&gt;</span>{email}<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>;</span>
});
}
<span class="hljs-keyword">this</span>.setState({ options });
},
render() {
<span class="hljs-comment">// filterOption 需要设置为 false,数据是动态设置的</span>
<span class="hljs-keyword">return</span> (
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">Select</span> <span class="hljs-attribute">combobox</span>
<span class="hljs-attribute">style</span>=<span class="hljs-value">{{</span> <span class="hljs-attribute">width:</span> <span class="hljs-attribute">200</span> }}
<span class="hljs-attribute">onChange</span>=<span class="hljs-value">{this.handleChange}</span>
<span class="hljs-attribute">filterOption</span>=<span class="hljs-value">{false}</span>
<span class="hljs-attribute">placeholder</span>=<span class="hljs-value">"请输入账户名"</span>&gt;</span>
{this.state.options}
<span class="hljs-tag">&lt;/<span class="hljs-title">Select</span>&gt;</span>
)</span>;
}
});
ReactDOM.render(<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">Test</span> /&gt;</span>, mountNode);</span></code></pre></div>
</div>
<div class="code-box-meta markdown">
<div class="code-box-title">
<a href="#demo-combobox">智能提示</a>
</div>
<p>输入框自动完成功能,下面是一个账号注册表单的例子。</p>
<span class="collapse anticon anticon-circle-o-right" unselectable="none"></span>
</div>
</div><div class="code-box" id="demo-coordinate">
<div class="code-box-demo">
<div id="components-select-demo-coordinate"></div>
<script>mountNode = document.getElementById('components-select-demo-coordinate');</script>
<script>(function(){'use strict';
var _antd = require('antd');
var Option = _antd.Select.Option;
var provinceData = ['浙江', '江苏'];
var cityData = {
浙江: ['杭州', '宁波', '温州'],
江苏: ['南京', '苏州', '镇江']
};
var App = React.createClass({
displayName: 'App',
getInitialState: function getInitialState() {
return {
cities: cityData[provinceData[0]],
secondCity: cityData[provinceData[0]][0]
};
},
handleProvinceChange: function handleProvinceChange(value) {
this.setState({
cities: cityData[value],
secondCity: cityData[value][0]
});
},
onSecondCityChange: function onSecondCityChange(value) {
this.setState({
secondCity: value
});
},
render: function render() {
var provinceOptions = provinceData.map(function (province) {
return React.createElement(
Option,
{ key: province },
province
);
});
var cityOptions = this.state.cities.map(function (city) {
return React.createElement(
Option,
{ key: city },
city
);
});
return React.createElement(
'div',
null,
React.createElement(
_antd.Select,
{ defaultValue: provinceData[0], style: { width: 90 }, onChange: this.handleProvinceChange },
provinceOptions
),
React.createElement(
_antd.Select,
{ value: this.state.secondCity, style: { width: 90 }, onChange: this.onSecondCityChange },
cityOptions
)
);
}
});
ReactDOM.render(React.createElement(App, null), mountNode);})()</script><div class="highlight"><pre><code class="javascript"><span class="hljs-keyword">import</span> { Select } <span class="hljs-keyword">from</span> <span class="hljs-string">'antd'</span>;
<span class="hljs-keyword">const</span> Option = Select.Option;
<span class="hljs-keyword">const</span> provinceData = [<span class="hljs-string">'浙江'</span>, <span class="hljs-string">'江苏'</span>];
<span class="hljs-keyword">const</span> cityData = {
浙江: [<span class="hljs-string">'杭州'</span>, <span class="hljs-string">'宁波'</span>, <span class="hljs-string">'温州'</span>],
江苏: [<span class="hljs-string">'南京'</span>, <span class="hljs-string">'苏州'</span>, <span class="hljs-string">'镇江'</span>]
};
<span class="hljs-keyword">const</span> App = React.createClass({
getInitialState() {
<span class="hljs-keyword">return</span> {
cities: cityData[provinceData[<span class="hljs-number">0</span>]],
secondCity: cityData[provinceData[<span class="hljs-number">0</span>]][<span class="hljs-number">0</span>]
};
},
handleProvinceChange(value) {
<span class="hljs-keyword">this</span>.setState({
cities: cityData[value],
secondCity: cityData[value][<span class="hljs-number">0</span>]
});
},
onSecondCityChange(value) {
<span class="hljs-keyword">this</span>.setState({
secondCity: value
});
},
render() {
<span class="hljs-keyword">const</span> provinceOptions = provinceData.map(province =&gt; <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">key</span>=<span class="hljs-value">{province}</span>&gt;</span>{province}<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>)</span>;
<span class="hljs-keyword">const</span> cityOptions = <span class="hljs-keyword">this</span>.state.cities.map(city =&gt; <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">Option</span> <span class="hljs-attribute">key</span>=<span class="hljs-value">{city}</span>&gt;</span>{city}<span class="hljs-tag">&lt;/<span class="hljs-title">Option</span>&gt;</span>)</span>;
<span class="hljs-keyword">return</span> (
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Select</span> <span class="hljs-attribute">defaultValue</span>=<span class="hljs-value">{provinceData[0]}</span> <span class="hljs-attribute">style</span>=<span class="hljs-value">{{</span> <span class="hljs-attribute">width:</span> <span class="hljs-attribute">90</span> }} <span class="hljs-attribute">onChange</span>=<span class="hljs-value">{this.handleProvinceChange}</span>&gt;</span>
{provinceOptions}
<span class="hljs-tag">&lt;/<span class="hljs-title">Select</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">Select</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">{this.state.secondCity}</span> <span class="hljs-attribute">style</span>=<span class="hljs-value">{{</span> <span class="hljs-attribute">width:</span> <span class="hljs-attribute">90</span> }} <span class="hljs-attribute">onChange</span>=<span class="hljs-value">{this.onSecondCityChange}</span>&gt;</span>
{cityOptions}
<span class="hljs-tag">&lt;/<span class="hljs-title">Select</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
)</span>;
}
});
ReactDOM.render(<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">App</span> /&gt;</span>, mountNode);</span></code></pre></div>
</div>
<div class="code-box-meta markdown">
<div class="code-box-title">
<a href="#demo-coordinate">联动</a>
</div>
<p>省市联动是典型的例子。</p>
<p>推荐使用 <a href="/components/cascader/">cascader</a> 组件。</p>
<span class="collapse anticon anticon-circle-o-right" unselectable="none"></span>
</div>
</div>
</div>
</div>
<ul class="toc demos-anchor">
<li>
<a title="基本使用" href="#demo-basic">
<span>基本使用</span>
</a>
</li>
<li>
<a title="三种大小" href="#demo-size">
<span>三种大小</span>
</a>
</li>
<li>
<a title="带搜索框" href="#demo-search">
<span>带搜索框</span>
</a>
</li>
<li>
<a title="多选" href="#demo-multiple">
<span>多选</span>
</a>
</li>
<li>
<a title="标签" href="#demo-tags">
<span>标签</span>
</a>
</li>
<li>
<a title="智能提示" href="#demo-combobox">
<span>智能提示</span>
</a>
</li>
<li>
<a title="分组" href="#demo-optgroup">
<span>分组</span>
</a>
</li>
<li>
<a title="联动" href="#demo-coordinate">
<span>联动</span>
</a>
</li>
<li>
<a title="搜索框" href="#demo-search-box">
<span>搜索框</span>
</a>
</li>
</ul>
<div class="api-container markdown"></div>
</section>
</div><footer id="footer">
<ul>
<li>
<h2>GitHub</h2>
<a target="_blank "href="https://github.com/ant-design/ant-design">仓库</a>
<a target="_blank" href="https://github.com/ant-design/antd-init">脚手架</a>
<a target="_blank" href="http://ant-tool.github.io/">开发工具</a>
</li>
<li>
<h2>关于我们</h2>
<a target="_blank" href="https://github.com/ant-ued/blog">博客 - Ant UED</a>
</li>
<li>
<h2>联系我们</h2>
<a target="_blank" href="https://github.com/ant-design/ant-design/issues">反馈和建议</a>
<a target="_blank" href="https://gitter.im/ant-design/ant-design">讨论</a>
<a target="_blank" href="http://dwz.cn/2AF9ao">报告 Bug</a>
</li>
<li>
<div>©2015 蚂蚁金服体验技术部出品</div>
<div>文档版本:<span id="versions-select"></span></div>
</li>
</ul>
</footer>
<script data-no-instant>
if (!location.port) {
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-72788897-1', 'auto');
ga('send', 'pageview');
InstantClick.on('change', function() {
ga('send', 'pageview', location.pathname + location.search);
});
}
</script>
<script data-no-instant>
InstantClick.on('change', function() {
InstantClickChangeFns.forEach(function(fn) {
fn();
});
});
InstantClick.init();
</script>
</body>
</html>