-
Notifications
You must be signed in to change notification settings - Fork 0
/
1837-ed889661c526fa56cc83.js
1 lines (1 loc) · 45.1 KB
/
1837-ed889661c526fa56cc83.js
1
(self.webpackChunkzent_docs=self.webpackChunkzent_docs||[]).push([[1837],{91837:(n,s,a)=>{"use strict";a.r(s),a.d(s,{default:()=>y});var t=a(73450),p=a(27378),o=a(57318),e=a(65762),c=a(24246);function l(n,s){var a=Object.keys(n);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(n);s&&(t=t.filter((function(s){return Object.getOwnPropertyDescriptor(n,s).enumerable}))),a.push.apply(a,t)}return a}function u(n){for(var s=1;s<arguments.length;s++){var a=null!=arguments[s]?arguments[s]:{};s%2?l(Object(a),!0).forEach((function(s){(0,t.Z)(n,s,a[s])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(a)):l(Object(a)).forEach((function(s){Object.defineProperty(n,s,Object.getOwnPropertyDescriptor(a,s))}))}return n}var i=function(){class n extends p.Component{constructor(...n){super(...n),(0,t.Z)(this,"state",{data:[]}),(0,t.Z)(this,"onSelect",(n=>{})),(0,t.Z)(this,"onSearch",(n=>{this.setState({data:n?[n,n+n,n+n+n]:[]})})),(0,t.Z)(this,"onChange",(n=>{}))}render(){return(0,c.jsx)(e.Q,{data:this.state.data,onSelect:this.onSelect,onSearch:this.onSearch,onChange:this.onChange})}}return(0,c.jsx)("div",{children:(0,c.jsx)(n,{})})},r=function(){class n extends p.Component{constructor(...n){super(...n),(0,t.Z)(this,"state",{value:"controlled",data:["controlled","controlledcontrolled","controlledcontrolledcontrolled"]}),(0,t.Z)(this,"onSelect",(n=>{})),(0,t.Z)(this,"onSearch",(n=>{this.setState({data:n?[{value:n,content:n},{value:n+n,content:n+n},{value:n+n+n,content:n+n+n}]:[]})})),(0,t.Z)(this,"onChange",(n=>{this.setState({value:n})}))}render(){return(0,c.jsx)(e.Q,{value:this.state.value,data:this.state.data,onSelect:this.onSelect,onSearch:this.onSearch,onChange:this.onChange})}}return(0,c.jsx)("div",{children:(0,c.jsx)(n,{})})},k=function(){class n extends p.Component{constructor(...n){super(...n),(0,t.Z)(this,"state",{value:"",data:[]}),(0,t.Z)(this,"data",[{isGroup:!0,content:"浙江"},{value:"hz",content:"杭州"},"绍兴","温州","金华",{isDivider:!0},{isGroup:!0,content:"江苏"},"南京","苏州","无锡","常州"]),(0,t.Z)(this,"onSelect",(n=>{})),(0,t.Z)(this,"onSearch",(n=>{})),(0,t.Z)(this,"onChange",(n=>{this.setState({value:n})}))}render(){return(0,c.jsx)(e.Q,{placeholder:"输入值不受限...",value:this.state.value,data:this.data,onSelect:this.onSelect,onSearch:this.onSearch,onChange:this.onChange})}}class s extends p.Component{constructor(...n){super(...n),(0,t.Z)(this,"state",{value:"",data:[]}),(0,t.Z)(this,"data",[{isGroup:!0,content:"浙江"},{value:"hz",content:"杭州"},{value:"绍兴",content:(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{children:"绍!兴!"}),(0,c.jsx)("div",{children:"这是第二行"})]})},"温州","金华",{isDivider:!0},{isGroup:!0,content:"江苏"},"南京","苏州","无锡","常州"]),(0,t.Z)(this,"onSelect",(n=>{})),(0,t.Z)(this,"onSearch",(n=>{})),(0,t.Z)(this,"onChange",(n=>{this.setState({value:n})}))}render(){return(0,c.jsx)(e.Q,{placeholder:"输入值受限...",value:this.state.value,data:this.data,onSelect:this.onSelect,onSearch:this.onSearch,onChange:this.onChange,valueFromOptions:!0})}}return(0,c.jsxs)("div",{children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{style:{display:"inline-block",margin:"5px 0"},children:"输入值不受限:"}),(0,c.jsx)(n,{})]}),(0,c.jsxs)("div",{style:{marginTop:"5px"},children:[(0,c.jsx)("div",{style:{display:"inline-block",margin:"5px 0"},children:"输入值必须来自于选项:"}),(0,c.jsx)(s,{})]})]})};function d(n){return(0,c.jsx)(n.tag,u(u({},n.attributes),{},{dangerouslySetInnerHTML:{__html:n.html}}))}function h(n){return(0,c.jsx)(d,{tag:"section",html:n.html,attributes:{className:"zandoc-react-markdown"}})}function g(n){return(0,c.jsx)(d,{tag:"style",html:n.style})}function m(n,s){for(;n;)return n.offsetTop&&"static"!==getComputedStyle(n).position&&(s+=n.offsetTop),m(n.parentNode,s);return s}class v extends p.Component{constructor(...n){super(...n),(0,t.Z)(this,"state",{showCode:!1}),(0,t.Z)(this,"toggle",(()=>{this.setState({showCode:!this.state.showCode})}))}render(){var n=this.state.showCode,s=this.props,a=s.title,t=s.src,p=s.children;return(0,c.jsxs)("div",{className:"zandoc-react-demo",children:[(0,c.jsx)("div",{className:"zandoc-react-demo__preview",children:p}),(0,c.jsxs)("div",{className:"zandoc-react-demo__bottom",onClick:this.toggle,children:[(0,c.jsx)("div",{className:"zandoc-react-demo__title",children:(0,c.jsx)("p",{children:a||""})}),(0,c.jsx)("i",{className:"zenticon zenticon-caret-up zandoc-react-demo__toggle ".concat(n?"zandoc-react-demo__toggle-on":"zandoc-react-demo__toggle-off")})]}),n&&(0,c.jsx)("pre",{className:"zandoc-react-demo__code",children:(0,c.jsx)(d,{tag:"code",html:t,attributes:{className:"language-jsx"}})})]})}}class y extends p.Component{componentDidMount(){var n=location.hash;if(n){var s=document.querySelector('a[href="'.concat(n,'"]'));s&&(0,o.l)(document.documentElement,0,m(s,-9))}}render(){return p.createElement("div",{className:"zandoc-react-container"},p.createElement(g,{style:""}),p.createElement(h,{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>'}),p.createElement(v,{title:"Basic Usage",id:"Demobasic",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">AutoComplete</span> <span class="token punctuation">}</span></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 control-flow">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>'},p.createElement(i)),p.createElement(v,{title:"Controlled Component",id:"Democontrolled",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">AutoComplete</span> <span class="token punctuation">}</span></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 control-flow">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>'},p.createElement(r)),p.createElement(v,{title:"Advanced Menu Item Configs",id:"Demoadvanced",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">AutoComplete</span> <span class="token punctuation">}</span></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 control-flow">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 control-flow">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>'},p.createElement(k)),p.createElement(h,{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>Input width</td>\n<td><code>string</code>\n \n|\n \n<code>number</code></td>\n<td>No</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>inline</td>\n<td>Input inline display</td>\n<td><code>boolean</code></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>'}))}}}}]);