HarmonyOS TextArea填充值,如何自动滚动到文本底部和如何手动失去焦点

1. TextArea填充值,如何滚动到文本底部(注意:textarea不是处于编辑状态,没有光标)

2. TextArea 如何通过代码调用自动失去焦点

HarmonyOS
2024-08-08 18:47:16
1802浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

若需要滚动到文本底部,是需要通过光标控制的,可参考以下demo:

@Entry 
@Component 
struct TextAreaExample { 
  @State text: string = '' 
  @State positionInfo: CaretOffset = { index: 0, x: 0, y: 0 } 
  @State maxLength: number= 0 
  controller: TextAreaController = new TextAreaController() 
 
  build() { 
    Column() { 
      TextArea({ 
        text: this.text, 
        placeholder: '请输入内容....', 
        controller: this.controller 
      }) 
        .placeholderFont({ size: 16, weight: 400 }) 
        .width(336) 
        .height(56) 
        .margin(20) 
        .fontSize(16) 
        .fontColor('#182431') 
        .backgroundColor('#FFFFFF') 
        .onChange((value: string) => { 
          this.text = value 
          let Length: number= value.length; 
          if(this.maxLength< Length){ 
            this.maxLength = Length 
            console.log('length='+this.maxLength)} 
        }) 
 
 
      Text(this.text) 
      Button('跳转到最后一行').onClick((event: ClickEvent) => { 
        this.controller.caretPosition(this.maxLength) 
      }) 
 
    }.width('100%').height('100%').backgroundColor('#F1F3F5') 
    //失去焦点事件 
    .onClick(()=> { 
      this.controller.stopEditing() 
    }) 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
分享
微博
QQ
微信
回复
2024-08-09 10:45:17
相关问题
ets的text input手动控制获得失去焦点
5488浏览 • 1回复 待解决
HarmonyOS Image获取焦点失去焦点失效
614浏览 • 1回复 待解决
list组件无法滚动到底部
2330浏览 • 1回复 待解决
HarmonyOS List组件默认滚动到底部
1204浏览 • 1回复 待解决
HarmonyOS TextArea组件如何主动获取焦点
568浏览 • 1回复 待解决
HarmonyOS InputType失去焦点禁止交互
514浏览 • 1回复 待解决
HarmonyOS TextArea获取焦点
559浏览 • 1回复 待解决
HarmonyOS swiper如何滚动到任意页面?
1128浏览 • 1回复 待解决
TextInput如何取消自动获得焦点
1332浏览 • 1回复 待解决