-
Notifications
You must be signed in to change notification settings - Fork 0
/
3935-11feadd0ef7c2af17a30.js
1 lines (1 loc) · 45.1 KB
/
3935-11feadd0ef7c2af17a30.js
1
(self.webpackChunkzent_docs=self.webpackChunkzent_docs||[]).push([[3935],{41610:(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,{})})},k=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,{})})},r=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-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>'}),p.createElement(v,{title:"基础用法",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:"受控组件",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(k)),p.createElement(v,{title:"高级菜单项",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(r)),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>参数</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><code>string</code>\n \n|\n \n<code>number</code></td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>inline</td>\n<td>输入框 inline 展示</td>\n<td><code>boolean</code></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>'}))}}}}]);