-
Notifications
You must be signed in to change notification settings - Fork 0
/
29-9c128e7e1f8e9241073d.js
1 lines (1 loc) · 46.3 KB
/
29-9c128e7e1f8e9241073d.js
1
(window.webpackJsonp=window.webpackJsonp||[]).push([[29],{902:function(n,a,s){"use strict";s.r(a),s.d(a,"default",(function(){return D}));var t=s(846),p=s.n(t),o=s(840),e=s.n(o),c=s(841),l=s.n(c),u=s(521),r=s.n(u),i=s(842),k=s.n(i),d=s(843),g=s.n(d),m=s(844),h=s.n(m),v=s(845),y=s.n(v),f=s(0),S=s.n(f),C=s(210),w=s(145);function b(n){var a=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(n){return!1}}();return function(){var s,t=h()(n);if(a){var p=h()(this).constructor;s=Reflect.construct(t,arguments,p)}else s=t.apply(this,arguments);return g()(this,s)}}var E=function(){var n=function(n){k()(s,n);var a=b(s);function s(){var n;e()(this,s);for(var t=arguments.length,p=new Array(t),o=0;o<t;o++)p[o]=arguments[o];return n=a.call.apply(a,[this].concat(p)),y()(r()(n),"state",{data:[]}),y()(r()(n),"onSelect",(function(n){return console.log("onSelect",n)})),y()(r()(n),"onSearch",(function(a){n.setState({data:a?[a,a+a,a+a+a]:[]})})),y()(r()(n),"onChange",(function(n){return console.log("onChange",n)})),n}return l()(s,[{key:"render",value:function(){return S.a.createElement(w.AutoComplete,{data:this.state.data,onSelect:this.onSelect,onSearch:this.onSearch,onChange:this.onChange})}}]),s}(f.Component);return S.a.createElement("div",null,S.a.createElement(n,null))},j=function(){var n=function(n){k()(s,n);var a=b(s);function s(){var n;e()(this,s);for(var t=arguments.length,p=new Array(t),o=0;o<t;o++)p[o]=arguments[o];return n=a.call.apply(a,[this].concat(p)),y()(r()(n),"state",{value:"controlled",data:["controlled","controlledcontrolled","controlledcontrolledcontrolled"]}),y()(r()(n),"onSelect",(function(n){return console.log("onSelect",n)})),y()(r()(n),"onSearch",(function(a){n.setState({data:a?[{value:a,content:a},{value:a+a,content:a+a},{value:a+a+a,content:a+a+a}]:[]})})),y()(r()(n),"onChange",(function(a){console.log("onChange",a),n.setState({value:a})})),n}return l()(s,[{key:"render",value:function(){return S.a.createElement(w.AutoComplete,{value:this.state.value,data:this.state.data,onSelect:this.onSelect,onSearch:this.onSearch,onChange:this.onChange})}}]),s}(f.Component);return S.a.createElement("div",null,S.a.createElement(n,null))},z=function(){var n=function(n){k()(s,n);var a=b(s);function s(){var n;e()(this,s);for(var t=arguments.length,p=new Array(t),o=0;o<t;o++)p[o]=arguments[o];return n=a.call.apply(a,[this].concat(p)),y()(r()(n),"state",{value:"",data:[]}),y()(r()(n),"data",[{isGroup:!0,content:"浙江"},{value:"hz",content:"杭州"},"绍兴","温州","金华",{isDivider:!0},{isGroup:!0,content:"江苏"},"南京","苏州","无锡","常州"]),y()(r()(n),"onSelect",(function(n){return console.log("onSelect",n)})),y()(r()(n),"onSearch",(function(n){return console.log("onSearch",n)})),y()(r()(n),"onChange",(function(a){console.log("onChange",a),n.setState({value:a})})),n}return l()(s,[{key:"render",value:function(){return S.a.createElement(w.AutoComplete,{placeholder:"输入值不受限...",value:this.state.value,data:this.data,onSelect:this.onSelect,onSearch:this.onSearch,onChange:this.onChange})}}]),s}(f.Component),a=function(n){k()(s,n);var a=b(s);function s(){var n;e()(this,s);for(var t=arguments.length,p=new Array(t),o=0;o<t;o++)p[o]=arguments[o];return n=a.call.apply(a,[this].concat(p)),y()(r()(n),"state",{value:"",data:[]}),y()(r()(n),"data",[{isGroup:!0,content:"浙江"},{value:"hz",content:"杭州"},{value:"绍兴",content:S.a.createElement("div",null,S.a.createElement("div",null,"绍!兴!"),S.a.createElement("div",null,"这是第二行"))},"温州","金华",{isDivider:!0},{isGroup:!0,content:"江苏"},"南京","苏州","无锡","常州"]),y()(r()(n),"onSelect",(function(n){return console.log("onSelect",n)})),y()(r()(n),"onSearch",(function(n){return console.log("onSearch",n)})),y()(r()(n),"onChange",(function(a){console.log("onChange",a),n.setState({value:a})})),n}return l()(s,[{key:"render",value:function(){return S.a.createElement(w.AutoComplete,{placeholder:"输入值受限...",value:this.state.value,data:this.data,onSelect:this.onSelect,onSearch:this.onSearch,onChange:this.onChange,valueFromOptions:!0})}}]),s}(f.Component);return S.a.createElement("div",null,S.a.createElement("div",null,S.a.createElement("div",{style:{display:"inline-block",margin:"5px 0"}},"输入值不受限:"),S.a.createElement(n,null)),S.a.createElement("div",{style:{marginTop:"5px"}},S.a.createElement("div",{style:{display:"inline-block",margin:"5px 0"}},"输入值必须来自于选项:"),S.a.createElement(a,null)))};function A(n){return S.a.createElement(n.tag,p()({},n.attributes,{dangerouslySetInnerHTML:{__html:n.html}}))}function _(n){return S.a.createElement(A,{tag:"section",html:n.html,attributes:{className:"zandoc-react-markdown"}})}function x(n){return S.a.createElement(A,{tag:"style",html:n.style})}var N=function(n){k()(s,n);var a=b(s);function s(){var n;e()(this,s);for(var t=arguments.length,p=new Array(t),o=0;o<t;o++)p[o]=arguments[o];return n=a.call.apply(a,[this].concat(p)),y()(r()(n),"state",{showCode:!1}),y()(r()(n),"toggle",(function(){n.setState({showCode:!n.state.showCode})})),n}return l()(s,[{key:"render",value:function(){var n=this.state.showCode,a=this.props,s=a.title,t=a.src,p=a.children;return S.a.createElement("div",{className:"zandoc-react-demo"},S.a.createElement("div",{className:"zandoc-react-demo__preview"},p),S.a.createElement("div",{className:"zandoc-react-demo__bottom",onClick:this.toggle},S.a.createElement("div",{className:"zandoc-react-demo__title"},S.a.createElement("p",null,s||"")),S.a.createElement("i",{className:"zenticon zenticon-caret-up zandoc-react-demo__toggle ".concat(n?"zandoc-react-demo__toggle-on":"zandoc-react-demo__toggle-off")})),n&&S.a.createElement("pre",{className:"zandoc-react-demo__code"},S.a.createElement(A,{tag:"code",html:t,attributes:{className:"language-jsx"}})))}}]),s}(f.Component),D=function(n){k()(s,n);var a=b(s);function s(){return e()(this,s),a.apply(this,arguments)}return l()(s,[{key:"componentDidMount",value:function(){var n=location.hash;if(n){var a=document.querySelector('a[href="'.concat(n,'"]'));a&&Object(C.a)(document.documentElement,0,function n(a,s){for(;a;)return a.offsetTop&&"static"!==getComputedStyle(a).position&&(s+=a.offsetTop),n(a.parentNode,s);return s}(a,-9))}}},{key:"render",value:function(){return S.a.createElement("div",{className:"zandoc-react-container",key:null},S.a.createElement(x,{style:""}),S.a.createElement(_,{html:'<h2 class="anchor-heading"><a href="#autocomplete-zi-dong-wan-cheng">¶</a><a href="javascript:void(0)" id="autocomplete-zi-dong-wan-cheng" class="anchor-point"></a>AutoComplete 自动完成</h2>\n<p>输入框自动完成功能。</p>\n<h3 class="anchor-heading"><a href="#dai-ma-yan-shi">¶</a><a href="javascript:void(0)" id="dai-ma-yan-shi" class="anchor-point"></a>代码演示</h3>'}),S.a.createElement(N,{title:"基础用法",id:"Demobasic",src:'<span class="token keyword module">import</span> <span class="token punctuation">{</span> <span class="token maybe-class-name">AutoComplete</span> <span class="token punctuation">}</span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">class</span> <span class="token class-name">Complete</span> <span class="token keyword">extends</span> <span class="token class-name">Component</span> <span class="token punctuation">{</span>\n state <span class="token operator">=</span> <span class="token punctuation">{</span>\n data<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">;</span>\n\n <span class="token function-variable function">onSelect</span> <span class="token operator">=</span> <span class="token parameter">v</span> <span class="token arrow operator">=></span> <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token string">\'onSelect\'</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token function-variable function">onSearch</span> <span class="token operator">=</span> <span class="token parameter">v</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token method function property-access">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span>\n data<span class="token operator">:</span> v <span class="token operator">?</span> <span class="token punctuation">[</span>v<span class="token punctuation">,</span> v <span class="token operator">+</span> v<span class="token punctuation">,</span> v <span class="token operator">+</span> v <span class="token operator">+</span> v<span class="token punctuation">]</span> <span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">;</span>\n <span class="token function-variable function">onChange</span> <span class="token operator">=</span> <span class="token parameter">v</span> <span class="token arrow operator">=></span> <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token string">\'onChange\'</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">AutoComplete</span></span>\n <span class="token attr-name">data</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">state</span><span class="token punctuation">.</span><span class="token property-access">data</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onSelect</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">onSelect</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onSearch</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">onSearch</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">onChange</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Complete</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span><span class="token punctuation">,</span>\n mountNode\n<span class="token punctuation">)</span><span class="token punctuation">;</span>'},S.a.createElement(E)),S.a.createElement(N,{title:"受控组件",id:"Democontrolled",src:'<span class="token keyword module">import</span> <span class="token punctuation">{</span> <span class="token maybe-class-name">AutoComplete</span> <span class="token punctuation">}</span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">class</span> <span class="token class-name">ControlledComplete</span> <span class="token keyword">extends</span> <span class="token class-name">Component</span> <span class="token punctuation">{</span>\n state <span class="token operator">=</span> <span class="token punctuation">{</span>\n value<span class="token operator">:</span> <span class="token string">\'controlled\'</span><span class="token punctuation">,</span>\n data<span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token string">\'controlled\'</span><span class="token punctuation">,</span> <span class="token string">\'controlledcontrolled\'</span><span class="token punctuation">,</span> <span class="token string">\'controlledcontrolledcontrolled\'</span><span class="token punctuation">]</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span>\n\n <span class="token function-variable function">onSelect</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">v</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token string">\'onSelect\'</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span>\n <span class="token function-variable function">onSearch</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">v</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token method function property-access">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span>\n data<span class="token operator">:</span> v <span class="token operator">?</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span>\n value<span class="token operator">:</span> v<span class="token punctuation">,</span>\n content<span class="token operator">:</span> v<span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>\n value<span class="token operator">:</span> v <span class="token operator">+</span> v<span class="token punctuation">,</span>\n content<span class="token operator">:</span> v <span class="token operator">+</span> v<span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>\n value<span class="token operator">:</span> v <span class="token operator">+</span> v <span class="token operator">+</span> v<span class="token punctuation">,</span>\n content<span class="token operator">:</span> v <span class="token operator">+</span> v <span class="token operator">+</span> v<span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">]</span> <span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span>\n <span class="token punctuation">}</span>\n <span class="token function-variable function">onChange</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">v</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token string">\'onChange\'</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span>\n <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token method function property-access">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span>\n value<span class="token operator">:</span> v\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n\n <span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">AutoComplete</span></span>\n <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">state</span><span class="token punctuation">.</span><span class="token property-access">value</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">data</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">state</span><span class="token punctuation">.</span><span class="token property-access">data</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onSelect</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">onSelect</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onSearch</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">onSearch</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">onChange</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">ControlledComplete</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span><span class="token punctuation">,</span>\n mountNode\n<span class="token punctuation">)</span><span class="token punctuation">;</span>'},S.a.createElement(j)),S.a.createElement(N,{title:"高级菜单项",id:"Demoadvanced",src:'<span class="token keyword module">import</span> <span class="token punctuation">{</span> <span class="token maybe-class-name">AutoComplete</span> <span class="token punctuation">}</span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">class</span> <span class="token class-name">ControlledComplete</span> <span class="token keyword">extends</span> <span class="token class-name">Component</span> <span class="token punctuation">{</span>\n state <span class="token operator">=</span> <span class="token punctuation">{</span>\n value<span class="token operator">:</span> <span class="token string">\'\'</span><span class="token punctuation">,</span>\n data<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>\n <span class="token punctuation">}</span>\n\n data <span class="token operator">=</span> <span class="token punctuation">[</span>\n <span class="token punctuation">{</span> isGroup<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> content<span class="token operator">:</span> <span class="token string">\'浙江\'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">{</span> value<span class="token operator">:</span> <span class="token string">\'hz\'</span><span class="token punctuation">,</span> content<span class="token operator">:</span> <span class="token string">\'杭州\'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token string">\'绍兴\'</span><span class="token punctuation">,</span>\n <span class="token string">\'温州\'</span><span class="token punctuation">,</span>\n <span class="token string">\'金华\'</span><span class="token punctuation">,</span>\n <span class="token punctuation">{</span> isDivider<span class="token operator">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">{</span> isGroup<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> content<span class="token operator">:</span> <span class="token string">\'江苏\'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token string">\'南京\'</span><span class="token punctuation">,</span>\n <span class="token string">\'苏州\'</span><span class="token punctuation">,</span>\n <span class="token string">\'无锡\'</span><span class="token punctuation">,</span>\n <span class="token string">\'常州\'</span><span class="token punctuation">,</span>\n <span class="token punctuation">]</span>\n\n <span class="token function-variable function">onSelect</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">v</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token string">\'onSelect\'</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span>\n <span class="token function-variable function">onSearch</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">v</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token string">\'onSearch\'</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span>\n <span class="token function-variable function">onChange</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">v</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token string">\'onChange\'</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span>\n <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token method function property-access">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span>\n value<span class="token operator">:</span> v\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n\n <span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">AutoComplete</span></span>\n <span class="token attr-name">placeholder</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>输入值不受限...<span class="token punctuation">"</span></span>\n <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">state</span><span class="token punctuation">.</span><span class="token property-access">value</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">data</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">data</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onSelect</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">onSelect</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onSearch</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">onSearch</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">onChange</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">class</span> <span class="token class-name">SelectComplete</span> <span class="token keyword">extends</span> <span class="token class-name">Component</span> <span class="token punctuation">{</span>\n state <span class="token operator">=</span> <span class="token punctuation">{</span>\n value<span class="token operator">:</span> <span class="token string">\'\'</span><span class="token punctuation">,</span>\n data<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>\n <span class="token punctuation">}</span>\n\n data <span class="token operator">=</span> <span class="token punctuation">[</span>\n <span class="token punctuation">{</span> isGroup<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> content<span class="token operator">:</span> <span class="token string">\'浙江\'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">{</span> value<span class="token operator">:</span> <span class="token string">\'hz\'</span><span class="token punctuation">,</span> content<span class="token operator">:</span> <span class="token string">\'杭州\'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">{</span> value<span class="token operator">:</span> <span class="token string">\'绍兴\'</span><span class="token punctuation">,</span> content<span class="token operator">:</span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span><span class="token punctuation">></span></span>绍<span class="token operator">!</span>兴<span class="token operator">!</span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span><span class="token punctuation">></span></span>这是第二行<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span> <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token string">\'温州\'</span><span class="token punctuation">,</span>\n <span class="token string">\'金华\'</span><span class="token punctuation">,</span>\n <span class="token punctuation">{</span> isDivider<span class="token operator">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">{</span> isGroup<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> content<span class="token operator">:</span> <span class="token string">\'江苏\'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token string">\'南京\'</span><span class="token punctuation">,</span>\n <span class="token string">\'苏州\'</span><span class="token punctuation">,</span>\n <span class="token string">\'无锡\'</span><span class="token punctuation">,</span>\n <span class="token string">\'常州\'</span><span class="token punctuation">,</span>\n <span class="token punctuation">]</span>\n\n <span class="token function-variable function">onSelect</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">v</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token string">\'onSelect\'</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span>\n <span class="token function-variable function">onSearch</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">v</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token string">\'onSearch\'</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span>\n <span class="token function-variable function">onChange</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">v</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token string">\'onChange\'</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span>\n <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token method function property-access">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span>\n value<span class="token operator">:</span> v\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n\n <span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">AutoComplete</span></span>\n <span class="token attr-name">placeholder</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>输入值受限...<span class="token punctuation">"</span></span>\n <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">state</span><span class="token punctuation">.</span><span class="token property-access">value</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">data</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">data</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onSelect</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">onSelect</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onSearch</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">onSearch</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">onChange</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">valueFromOptions</span>\n <span class="token punctuation">/></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n<span class="token punctuation">}</span>\n\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> display<span class="token operator">:</span> <span class="token string">\'inline-block\'</span><span class="token punctuation">,</span> margin<span class="token operator">:</span> <span class="token string">\'5px 0\'</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>输入值不受限:<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">ControlledComplete</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> marginTop<span class="token operator">:</span> <span class="token string">\'5px\'</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> display<span class="token operator">:</span> <span class="token string">\'inline-block\'</span><span class="token punctuation">,</span> margin<span class="token operator">:</span> <span class="token string">\'5px 0\'</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>输入值必须来自于选项:<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">SelectComplete</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span><span class="token punctuation">,</span>\n mountNode\n<span class="token punctuation">)</span><span class="token punctuation">;</span>'},S.a.createElement(z)),S.a.createElement(_,{html:'<h3 class="anchor-heading"><a href="#api">¶</a><a href="javascript:void(0)" id="api" class="anchor-point"></a>API</h3>\n<table class="table">\n<thead>\n<tr>\n<th>参数</th>\n<th>说明</th>\n<th>类型</th>\n<th>是否必填</th>\n<th>默认值</th>\n<th>备选值</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>value</td>\n<td>选中值</td>\n<td>any</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>initialValue</td>\n<td>初始值</td>\n<td>any</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>placeholder</td>\n<td>输入框的placeholder</td>\n<td>string</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>data</td>\n<td>选项数据</td>\n<td>array</td>\n<td>否</td>\n<td>[]</td>\n<td></td>\n</tr>\n<tr>\n<td>onChange</td>\n<td>当value改变时的callback</td>\n<td>function (value) {}</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>onSearch</td>\n<td>当输入值改变时的callback</td>\n<td>function (searchText) {}</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>onSelect</td>\n<td>当选中某个选项时的callback</td>\n<td>function (value) {}</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>filterOption</td>\n<td>根据输入值过滤选项的function</td>\n<td>function (searchText, { value, content }) {}</td>\n<td>否</td>\n<td>caselessMatch</td>\n<td></td>\n</tr>\n<tr>\n<td>valueFromOptions</td>\n<td>是否只能选中选项中存在的值</td>\n<td>bool</td>\n<td>否</td>\n<td><code>false</code></td>\n<td></td>\n</tr>\n<tr>\n<td>className</td>\n<td>可选,自定义输入框容器额外类名</td>\n<td>string</td>\n<td>否</td>\n<td><code>\'\'</code></td>\n<td></td>\n</tr>\n<tr>\n<td>popupClassName</td>\n<td>可选,自定义popup的类名</td>\n<td>string</td>\n<td>否</td>\n<td><code>\'\'</code></td>\n<td></td>\n</tr>\n<tr>\n<td>width</td>\n<td>输入框宽度</td>\n<td>string or number</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<h3 class="anchor-heading"><a href="#data-jie-gou">¶</a><a href="javascript:void(0)" id="data-jie-gou" class="anchor-point"></a>data 结构</h3>\n<ul>\n<li>使用方式 1: string array, 此时选项显示内容和选项value相同, 推荐使用</li>\n<li>使用方式 2: object array, 其中每项的结构是:</li>\n</ul>\n<pre><code class="language-text"><span class="token punctuation">{</span>\n value<span class="token operator">:</span> <span class="token string">\'value\'</span><span class="token punctuation">,</span> <span class="token comment">// 必填, 作为选项 value; 当 content 未传入时, 同时作为 content 使用; 当 content 未传入, 或者 content 不是 string 类型时, 用于默认的过滤匹配</span>\n content<span class="token operator">:</span> <span class="token string">\'content\'</span><span class="token punctuation">,</span> <span class="token comment">// 选填, 作为选项显示内容,可以填入 react node, 当 content 是 string 类型时, 会被优先用于过滤匹配</span>\n isGroup<span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token comment">// 选填, 此项作为分组头部渲染, 显示内容是content的值, 不可被点击选择</span>\n isDivider<span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token comment">// 选填, 此项作为分割线渲染, 不可被点击选择</span>\n<span class="token punctuation">}</span></code></pre>\n<p>注意此时的 <code>value</code> 和 <code>content</code> 是可以不同的。用户输入的值会通过 <code>onSearch</code> 返回,用于 <code>value</code> 和 <code>content</code> 值的匹配,其优先级: string 类型的 <code>content</code> > <code>value</code>。 当用户选中某个选项时,其 value 会被通过 <code>onSelect</code> 返回。无论是选中选项,还是直接用户输入,当输入框中的值变化时,新的 value 都会通过 <code>onChange</code> 返回。特别的,当 <code>valueFromOptions</code> 为 true 时,输入框失焦时会检查当前value是否在选项值中,如果不在则会重置,触发 <code>onSelect</code> 和 <code>onChange</code> 传入 null 值。</p>'}))}}]),s}(f.Component)}}]);