Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Taro next]input光标位置不对 #6632

Closed
myl0204 opened this issue Jun 10, 2020 · 11 comments · Fixed by #9690 or #9694
Closed

[Taro next]input光标位置不对 #6632

myl0204 opened this issue Jun 10, 2020 · 11 comments · Fixed by #9690 or #9694
Assignees
Milestone

Comments

@myl0204
Copy link
Contributor

myl0204 commented Jun 10, 2020

问题描述

iOS下,有初始值的input首次聚焦,光标会在最左边。

版本:rc.3,在1.3.22中试过没有这个问题。

复现步骤

  1. 点击有文本的输入框
  2. 光标位置会在最左边
  3. 失焦 ,再点击,光标位置正常。
state = {value: '我是一行文本'}

// ...

<Input value={this.state.value} onInput={this.onInput} />

期望行为

光标位置在文本末端

报错信息

系统信息

补充信息

如果您有功能上的建议,可以提到 FeatHub

使用上的问题,欢迎在「Taro 社区」一起交流

@yuche yuche added this to the 3.0.0-rc.6 milestone Jun 15, 2020
@yuche
Copy link
Contributor

yuche commented Jun 23, 2020

这样能不能解决问题?

<Input value={this.state.value} onInput={this.onInput} cursor={this.state.value.length} />

@myl0204
Copy link
Contributor Author

myl0204 commented Jun 23, 2020

这样能不能解决问题?

<Input value={this.state.value} onInput={this.onInput} cursor={this.state.value.length} />

这样子光标在文本中间时候,输入会导致光标跳动吧

@fjc0k
Copy link
Contributor

fjc0k commented Jun 24, 2020

@Chen-jj 3.0.0-rc.6,ios 下光标依然总是在最左边。

@fjc0k
Copy link
Contributor

fjc0k commented Jun 24, 2020

通过 vConsole 得到如下数据:

image

ios 下点击输入框光标必在最左边。

@fjc0k
Copy link
Contributor

fjc0k commented Jun 24, 2020

这样能不能解决问题?

<Input value={this.state.value} onInput={this.onInput} cursor={this.state.value.length} />

yuche 大佬的方案使用后一切正常。

@SyMind
Copy link
Member

SyMind commented Jul 6, 2021

@Chen-jj @yuche 感觉这个默认值加的没啥道理啊。

首先 cursor 属性在百度小程序是受控属性,这样导致的结果就是从文本中间删除某个字符后,光标就定位到了文本最后。

其次,这个是可以通过开发者编码实现的,看起并不需要框架层面做什么处理。

最后,我查阅了微信小程序的文档如下,input 组件的默认值应为 undefined。

image

@Chen-jj
Copy link
Contributor

Chen-jj commented Jul 6, 2021

@SyMind 不绑定默认值的话,会出现楼主提出的问题,虽然用户可以通过开发者编码实现,但框架层面处理的话不会增加心智负担和额外工作。

首先 cursor 属性在百度小程序是受控属性,这样导致的结果就是从文本中间删除某个字符后,光标就定位到了文本最后。

百度的话的确存在这个问题,我们把百度的 cusor 默认值去掉。

@SyMind
Copy link
Member

SyMind commented Jul 6, 2021

@Chen-jj 我想,微信小程序的文档和百度小程序的文档中,input 组件的默认值都是 undefined。从有小程序开发经验的开发者的角度看,会对其有路径依赖吧,从这个角度看这种改动破坏了这些人的直觉。

可能这样解决比较好,将 cursor 移动到需要 'i.value.length' 作为默认值的小程序对应的插件中,例如微信小程序,而不是对百度小程序做特殊处理。

@Chen-jj
Copy link
Contributor

Chen-jj commented Jul 6, 2021

我想,微信小程序的文档和百度小程序的文档中,input 组件的默认值都是 undefined。从有小程序开发经验的开发者的角度看,会对其有路径依赖吧,从这个角度看这种改动破坏了这些人的直觉。

没懂什么意思

首先 cursor 属性在百度小程序是受控属性,这样导致的结果就是从文本中间删除某个字符后,光标就定位到了文本最后。

最后定位到,也不是 cursor、selection-start、selection-end 的问题,是在百度中当 input 的 id 以 _ (默认 id)开头时,就会和这三个属性相冲突。

模板用 sjs 处理一下 input 的 id 即可。

@SyMind
Copy link
Member

SyMind commented Jul 6, 2021

@Chen-jj 哦哦哦,能询问一下你是如何定位到这个问题的么?

@Chen-jj
Copy link
Contributor

Chen-jj commented Jul 7, 2021

@Chen-jj 哦哦哦,能询问一下你是如何定位到这个问题的么?

不断调试 input 的模板属性

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants