@tarojs/components
Version:
Taro 组件库。
1 lines • 2.89 kB
JavaScript
System.register(["./p-b2d01686.system.js"],(function(e){"use strict";var t,n,i,a;return{setters:[function(e){t=e.r;n=e.c;i=e.h;a=e.g}],execute:function(){var o="taro-textarea-core{display:block;width:300px}taro-textarea-core .auto-height{height:auto}.taro-textarea{display:block;position:relative;border:0;width:100%;height:150px;-webkit-appearance:none;-moz-appearance:none;appearance:none;cursor:auto;line-height:1.5}.taro-textarea:focus{outline:none}";function r(e){return e!==null&&e!==void 0?e:""}var h=e("taro_textarea_core",function(){function e(e){var i=this;t(this,e);this.onInput=n(this,"input",7);this.onFocus=n(this,"focus",7);this.onBlur=n(this,"blur",7);this.onChange=n(this,"change",7);this.onLineChange=n(this,"linechange",7);this.disabled=false;this.maxlength=140;this.autoFocus=false;this.autoHeight=false;this.nativeProps={};this.line=1;this.handleInput=function(e){e.stopPropagation();i.handleLineChange();i.onInput.emit({value:e.target.value,cursor:e.target.value.length})};this.handleFocus=function(e){i.onFocus.emit({value:e.target.value})};this.handleBlur=function(e){i.onBlur.emit({value:e.target.value})};this.handleChange=function(e){e.stopPropagation();i.onChange.emit({value:e.target.value})};this.handleLineChange=function(){var e=i.getNumberOfLines();if(e!==i.line){i.line=e;i.onLineChange.emit({height:i.textareaRef.clientHeight,lineCount:i.line})}};this.calculateContentHeight=function(e,t){var n=e.style.height,i=e.offsetHeight,a=e.scrollHeight,o=e.style.overflow,r=e.style.minHeight||null;if(i>=a){e.style.minHeight=0;e.style.height=i+t+"px";e.style.overflow="hidden";if(a<e.scrollHeight){while(e.offsetHeight>=e.scrollHeight){e.style.height=(i-=t)+"px"}while(e.offsetHeight<e.scrollHeight){e.style.height=i+++"px"}e.style.height=n;e.style.overflow=o;e.style.minHeight=r;return i}}else{return a}};this.getNumberOfLines=function(){var e=i.textareaRef,t=window.getComputedStyle?window.getComputedStyle(e):e.style,n=parseInt(t.lineHeight,10),a=i.calculateContentHeight(e,n),o=Math.floor(a/n);return o}}e.prototype.componentDidLoad=function(){var e=this;Object.defineProperty(this.el,"value",{get:function(){return e.textareaRef.value},set:function(t){return e.value=t},configurable:true});this.autoFocus&&this.textareaRef.focus()};e.prototype.render=function(){var e=this;var t=this,n=t.value,a=t.placeholder,o=t.disabled,h=t.maxlength,l=t.autoFocus,s=t.autoHeight,u=t.name,c=t.nativeProps,g=t.handleInput,f=t.handleFocus,p=t.handleBlur,d=t.handleChange;var v={};if(s){v.rows=this.line}return i("textarea",Object.assign({ref:function(t){if(t){e.textareaRef=t}},class:"taro-textarea "+(s?"auto-height":""),value:r(n),placeholder:a,name:u,disabled:o,maxlength:h,autofocus:l,onInput:g,onFocus:f,onBlur:p,onChange:d},c,v))};Object.defineProperty(e.prototype,"el",{get:function(){return a(this)},enumerable:false,configurable:true});return e}());h.style=o}}}));