[(100000:100000:scope)] current focus node info : (TextArea/9077). ... [(100000:100000:scope)] current focus node info : (TextArea/9154).
TextArea.onChange(() => {
// 自定义函数包含组件重新渲染逻辑
}); 参考以下示例,优化代码逻辑,当输入框内容发生变化时,不要进行导致组件失焦的操作。
@Entry
@Component
struct TextAreaPage {
@State text: string = '';
@State textStr1: string = '';
@State textStr9: string = '';
controller: TextAreaController = new TextAreaController();
build() {
Row() {
Column() {
Text(`${this.textStr1}\n${this.textStr9}`)
.fontSize(20)
TextArea({ text: this.text, placeholder: 'input your word...', controller: this.controller })
.onChange((value: string) => {
// 文本内容发生变化时触发该回调
// 文本内容变化的时候不要有失焦的代码逻辑
console.info('onChange is triggering: ', value);
this.textStr1 = `onChange is triggering: ${value}`;
})
.onFocus(() => {
// 绑定通用事件,输入框获焦时触发该回调
console.info('onFocus is triggering');
this.textStr9 = `onFocus is triggering`;
})
}.width('100%')
}
.height('100%')
}
}