簡體   English   中英

Ionic 2-提交后集中文本區域以防止虛擬鍵盤消失

[英]Ionic 2 - Focus textarea after submit to prevent virtual keyboard from disappearing

我的應用程序中有一個聊天應用程序的一部分,在該應用程序中,每當我按下“提交”按鈕時,textarea都會失去輸入,並且虛擬鍵盤也會關閉。 我嘗試通過在提交表單后立即重新調整文本區域來解決此問題。 問題是,當我在瀏覽器中使用Ionic時,此方法工作正常,但是一旦在iOS設備上對其進行測試,它便拒絕重新關注文本區域。 這是我的HTML模板中的代碼:

<div class="create-message-block">
    <form [formGroup]="addMessageForm" novalidate (ngSubmit)="addMessage(addMessageForm.value, focusableTextarea)">
      <textarea #focusableTextarea [formControl]="addMessageForm.get('message')" placeholder="Write your message..."></textarea>
      <input type="submit" value="Send"/>
    </form>
  </div>

// And here is the add message functionality in my component
addMessage(data, focusableTextarea) {
 // ... a lot of code edited out for sample purposes

  focusableTextarea.focus()
}

有誰知道我還能做些什么嗎? 我什至嘗試添加一個輕微的超時,在該超時中.focus()等待50毫秒才能觸發。 那也沒做。

提前致謝!

我在聊天應用程序中所做的是使用mousedown事件。

(mousedown)="preventFocusChange($event)"

並且在功能上

preventFocusChange(e) {
    e.preventDefault();
}

讓我知道這是否適合您。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM