-
Notifications
You must be signed in to change notification settings - Fork 0
/
28-9c128e7e1f8e9241073d.js
1 lines (1 loc) · 46.3 KB
/
28-9c128e7e1f8e9241073d.js
1
(window.webpackJsonp=window.webpackJsonp||[]).push([[28],{975:function(n,a,s){"use strict";s.r(a),s.d(a,"default",(function(){return _}));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),i=s.n(u),r=s(842),k=s.n(r),d=s(843),h=s.n(d),g=s(844),m=s.n(g),v=s(845),f=s.n(v),y=s(0),w=s.n(y),S=s(210),C=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=m()(n);if(a){var p=m()(this).constructor;s=Reflect.construct(t,arguments,p)}else s=t.apply(this,arguments);return h()(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)),f()(i()(n),"state",{data:[]}),f()(i()(n),"onSelect",(function(n){return console.log("onSelect",n)})),f()(i()(n),"onSearch",(function(a){n.setState({data:a?[a,a+a,a+a+a]:[]})})),f()(i()(n),"onChange",(function(n){return console.log("onChange",n)})),n}return l()(s,[{key:"render",value:function(){return w.a.createElement(C.AutoComplete,{data:this.state.data,onSelect:this.onSelect,onSearch:this.onSearch,onChange:this.onChange})}}]),s}(y.Component);return w.a.createElement("div",null,w.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)),f()(i()(n),"state",{value:"controlled",data:["controlled","controlledcontrolled","controlledcontrolledcontrolled"]}),f()(i()(n),"onSelect",(function(n){return console.log("onSelect",n)})),f()(i()(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}]:[]})})),f()(i()(n),"onChange",(function(a){console.log("onChange",a),n.setState({value:a})})),n}return l()(s,[{key:"render",value:function(){return w.a.createElement(C.AutoComplete,{value:this.state.value,data:this.state.data,onSelect:this.onSelect,onSearch:this.onSearch,onChange:this.onChange})}}]),s}(y.Component);return w.a.createElement("div",null,w.a.createElement(n,null))},A=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)),f()(i()(n),"state",{value:"",data:[]}),f()(i()(n),"data",[{isGroup:!0,content:"浙江"},{value:"hz",content:"杭州"},"绍兴","温州","金华",{isDivider:!0},{isGroup:!0,content:"江苏"},"南京","苏州","无锡","常州"]),f()(i()(n),"onSelect",(function(n){return console.log("onSelect",n)})),f()(i()(n),"onSearch",(function(n){return console.log("onSearch",n)})),f()(i()(n),"onChange",(function(a){console.log("onChange",a),n.setState({value:a})})),n}return l()(s,[{key:"render",value:function(){return w.a.createElement(C.AutoComplete,{placeholder:"输入值不受限...",value:this.state.value,data:this.data,onSelect:this.onSelect,onSearch:this.onSearch,onChange:this.onChange})}}]),s}(y.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)),f()(i()(n),"state",{value:"",data:[]}),f()(i()(n),"data",[{isGroup:!0,content:"浙江"},{value:"hz",content:"杭州"},{value:"绍兴",content:w.a.createElement("div",null,w.a.createElement("div",null,"绍!兴!"),w.a.createElement("div",null,"这是第二行"))},"温州","金华",{isDivider:!0},{isGroup:!0,content:"江苏"},"南京","苏州","无锡","常州"]),f()(i()(n),"onSelect",(function(n){return console.log("onSelect",n)})),f()(i()(n),"onSearch",(function(n){return console.log("onSearch",n)})),f()(i()(n),"onChange",(function(a){console.log("onChange",a),n.setState({value:a})})),n}return l()(s,[{key:"render",value:function(){return w.a.createElement(C.AutoComplete,{placeholder:"输入值受限...",value:this.state.value,data:this.data,onSelect:this.onSelect,onSearch:this.onSearch,onChange:this.onChange,valueFromOptions:!0})}}]),s}(y.Component);return w.a.createElement("div",null,w.a.createElement("div",null,w.a.createElement("div",{style:{display:"inline-block",margin:"5px 0"}},"输入值不受限:"),w.a.createElement(n,null)),w.a.createElement("div",{style:{marginTop:"5px"}},w.a.createElement("div",{style:{display:"inline-block",margin:"5px 0"}},"输入值必须来自于选项:"),w.a.createElement(a,null)))};function z(n){return w.a.createElement(n.tag,p()({},n.attributes,{dangerouslySetInnerHTML:{__html:n.html}}))}function x(n){return w.a.createElement(z,{tag:"section",html:n.html,attributes:{className:"zandoc-react-markdown"}})}function N(n){return w.a.createElement(z,{tag:"style",html:n.style})}var D=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)),f()(i()(n),"state",{showCode:!1}),f()(i()(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 w.a.createElement("div",{className:"zandoc-react-demo"},w.a.createElement("div",{className:"zandoc-react-demo__preview"},p),w.a.createElement("div",{className:"zandoc-react-demo__bottom",onClick:this.toggle},w.a.createElement("div",{className:"zandoc-react-demo__title"},w.a.createElement("p",null,s||"")),w.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&&w.a.createElement("pre",{className:"zandoc-react-demo__code"},w.a.createElement(z,{tag:"code",html:t,attributes:{className:"language-jsx"}})))}}]),s}(y.Component),_=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(S.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 w.a.createElement("div",{className:"zandoc-react-container",key:null},w.a.createElement(N,{style:""}),w.a.createElement(x,{html:'<h2 class="anchor-heading"><a href="#autocomplete">¶</a><a href="javascript:void(0)" id="autocomplete" class="anchor-point"></a>AutoComplete</h2>\n<p>AutoComplete of input field.</p>\n<h3 class="anchor-heading"><a href="#demos">¶</a><a href="javascript:void(0)" id="demos" class="anchor-point"></a>Demos</h3>'}),w.a.createElement(D,{title:"Basic Usage",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>'},w.a.createElement(E)),w.a.createElement(D,{title:"Controlled Component",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>'},w.a.createElement(j)),w.a.createElement(D,{title:"Advanced Menu Item Configs",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>'},w.a.createElement(A)),w.a.createElement(x,{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>Props</th>\n<th>Description</th>\n<th>Type</th>\n<th>Required</th>\n<th>Default</th>\n<th>Alternative</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>value</td>\n<td>Selected value</td>\n<td>any</td>\n<td>no</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>initialValue</td>\n<td>Initial value</td>\n<td>any</td>\n<td>no</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>placeholder</td>\n<td>Input placeholder</td>\n<td>string</td>\n<td>no</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>data</td>\n<td>Option data</td>\n<td>array</td>\n<td>no</td>\n<td>[]</td>\n<td></td>\n</tr>\n<tr>\n<td>onChange</td>\n<td>The callback when value is changed</td>\n<td>function (value) {}</td>\n<td>no</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>onSearch</td>\n<td>The callback when input text is changed</td>\n<td>function (searchText) {}</td>\n<td>no</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>onSelect</td>\n<td>The callback when option is selected</td>\n<td>function (value) {}</td>\n<td>no</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>filterOption</td>\n<td>Filter function for options</td>\n<td>function (searchText, { value, content }) {}</td>\n<td>no</td>\n<td>caselessMatch</td>\n<td></td>\n</tr>\n<tr>\n<td>valueFromOptions</td>\n<td>Whether value can only be one of the options\' value</td>\n<td>bool</td>\n<td>no</td>\n<td><code>false</code></td>\n<td></td>\n</tr>\n<tr>\n<td>className</td>\n<td>Optional, custom input wrapper className</td>\n<td>string</td>\n<td>no</td>\n<td><code>\'\'</code></td>\n<td></td>\n</tr>\n<tr>\n<td>popupClassName</td>\n<td>Optional, custom popup classname</td>\n<td>string</td>\n<td>no</td>\n<td><code>\'\'</code></td>\n<td></td>\n</tr>\n<tr>\n<td>width</td>\n<td>The input-box width</td>\n<td>string or number</td>\n<td>no</td>\n<td></td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<h3 class="anchor-heading"><a href="#data-structure">¶</a><a href="javascript:void(0)" id="data-structure" class="anchor-point"></a>data structure</h3>\n<ul>\n<li>Case 1: string array, the content and value is the same, recommended.</li>\n<li>Case 2: object array, the struct of each item is like:</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">// Reqiured, as the option value; When content is not passed in, value is also used as content; When content is not passed in, or content is not string type, value is used for option filter.</span>\n content<span class="token operator">:</span> <span class="token string">\'content\'</span><span class="token punctuation">,</span> <span class="token comment">// Optional, as the option display content,could be react node type, when content is string type, content will be sued for option filter instead of value.</span>\n isGroup<span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token comment">// Optional, means this option will be rendered as group header, the header content will be content passed in, and the option is not selectable.</span>\n isDivider<span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token comment">// Optional, means this option will be rendered as divider, in, and the option is not selectable.</span>\n<span class="token punctuation">}</span></code></pre>\n<p>Note that here <code>value</code> and <code>content</code> could be different. User input will be returned by <code>onSearch</code>, used for the filter of <code>content</code> or <code>value</code>, string <code>content</code> prior to <code>value</code>. When user select one option, the value will be returned by <code>onSelect</code>. No matter user select an option or input text, the new value of input will be returned by <code>onChange</code>. Specially, when <code>valueFromOptions</code> is true, the blur of input will trigger a check for current value to determine whether this is a value from its options, if not, <code>onSelect</code> and <code>onChange</code> will be triggered and null will be passed in.</p>'}))}}]),s}(y.Component)}}]);