@tarojs/components
Version:
Taro 组件库。
1 lines • 2.51 kB
JavaScript
import{r as t,c as e,h as i,g as h}from"./p-f05e1558.js";function s(t){return null!=t?t:""}let a=class{constructor(i){t(this,i),this.onInput=e(this,"input",7),this.onFocus=e(this,"focus",7),this.onBlur=e(this,"blur",7),this.onChange=e(this,"change",7),this.onLineChange=e(this,"linechange",7),this.disabled=!1,this.maxlength=140,this.autoFocus=!1,this.autoHeight=!1,this.nativeProps={},this.line=1,this.handleInput=t=>{t.stopPropagation(),this.handleLineChange(),this.onInput.emit({value:t.target.value,cursor:t.target.value.length})},this.handleFocus=t=>{this.onFocus.emit({value:t.target.value})},this.handleBlur=t=>{this.onBlur.emit({value:t.target.value})},this.handleChange=t=>{t.stopPropagation(),this.onChange.emit({value:t.target.value})},this.handleLineChange=()=>{const t=this.getNumberOfLines();t!==this.line&&(this.line=t,this.onLineChange.emit({height:this.textareaRef.clientHeight,lineCount:this.line}))},this.calculateContentHeight=(t,e)=>{let i=t.style.height,h=t.offsetHeight,s=t.scrollHeight,a=t.style.overflow,o=t.style.minHeight||null;if(!(h>=s))return s;if(t.style.minHeight=0,t.style.height=h+e+"px",t.style.overflow="hidden",s<t.scrollHeight){for(;t.offsetHeight>=t.scrollHeight;)t.style.height=(h-=e)+"px";for(;t.offsetHeight<t.scrollHeight;)t.style.height=h+++"px";return t.style.height=i,t.style.overflow=a,t.style.minHeight=o,h}},this.getNumberOfLines=()=>{const t=this.textareaRef,e=window.getComputedStyle?window.getComputedStyle(t):t.style,i=parseInt(e.lineHeight,10),h=this.calculateContentHeight(t,i);return Math.floor(h/i)}}componentDidLoad(){Object.defineProperty(this.el,"value",{get:()=>this.textareaRef.value,set:t=>this.value=t,configurable:!0}),this.autoFocus&&this.textareaRef.focus()}render(){const{value:t,placeholder:e,disabled:h,maxlength:a,autoFocus:o,autoHeight:n,name:r,nativeProps:l,handleInput:u,handleFocus:c,handleBlur:p,handleChange:d}=this,g={};return n&&(g.rows=this.line),i("textarea",Object.assign({ref:t=>{t&&(this.textareaRef=t)},class:"taro-textarea "+(n?"auto-height":""),value:s(t),placeholder:e,name:r,disabled:h,maxlength:a,autofocus:o,onInput:u,onFocus:c,onBlur:p,onChange:d},l,g))}get el(){return h(this)}};a.style="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}";export{a as taro_textarea_core}