输入组件(即TextInput、TextArea等输入组件)会解析placeholder得到相关字段触发智能填充,当前TextInput的placeholder属性存在关键字'名'会产生联想填充,导致气泡无法弹出。
TextInput组件设置enableAutoFill属性值为false,禁用自动填充。
@Entry @Component struct CustomPopup { @State message: string = ''; @State customPopup: boolean = false; @Builder popupBuilder() { Row({ space: 2 }) { Image($r('app.media.startIcon')).width(24).height(24) Text('Custom Popup').fontSize(10); }.width(110).height(50).padding(10).backgroundColor('#ffffff') } build() { Column() { TextInput({ text: this.message, placeholder: '请输入服务器标识/IP/域名' }) .margin({ top: 50 }) .enableAutoFill(false) // 属性值为false,禁用自动填充。 .bindPopup(this.customPopup, { builder: this.popupBuilder, placement: Placement.Top, mask: false, popupColor: Color.Yellow, enableArrow: true, showInSubWindow: false, onStateChange: (e) => { if (!e.isVisible) { this.customPopup = false; } } }) .onChange((value: string) => { if (value === '') { this.customPopup = true; } else { this.customPopup = false; } }) .onEditChange((isEditing: boolean) => { if (isEditing) { this.customPopup = true; } }) } .padding({ left: 16, right: 16 }) .width('100%') .height('100%') } }