简体   繁体   中英

Angular iOS text field focus

I need to open mobile keyboard when I open div with input. I tried to set the focus for input

 this.changeCityInput.nativeElement.focus();

That triggers when I click to parent div. After click on the parent div child expanding and show an input field

but it doesn't work on ios, for desktop and android it works correctly.

Also

document.body.ontouchend = () => {
        this.changeCityInput.nativeElement.focus();
      };
setTimeout(() => {
  this.renderer.selectRootElement(this.changeCityInput.nativeElement).focus();

  this.changeCityInput.nativeElement.focus();
}, 500);

Doesnt work. What is the correct way to set focus on the input?


UPD: On the MacOS works correctly

focus() doesnt work with disabled button I emulate disabled action

For default when i open div with input i focus on it, after finishing i use blur() to unfocus el

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM