Polymer 1.0 - paper-textarea 自动对焦,即使自动对焦设置为 false

Polymer 1.0 - paper-textarea autofocusing even when autofocus set to false

我在抽屉里有一个 paper-textarea。当我转到页面时,paper-textarea 会自动对焦,这会打开抽屉。我试图通过尝试 autofocus="false" 和 autofocus="off" 来摆脱焦点,但它们都不适合我。任何帮助将不胜感激。

<paper-textarea id="descriptionInput" label="Description" invalid="{{descriptionError}}" error-message="please enter a valid description" value="{{description}}" autofocus="false"></paper-textarea>

更新:解决这个问题的另一种方法可能是以编程方式删除焦点,但我已经在附加函数中尝试了这个。$.descriptionInput.blur(),但它也不起作用。

这是由于 iron-autogrow-textarea 的自动对焦 属性 默认值设置为 "off"。 autofocus 属性如果存在则处于活动状态,禁用它的唯一方法是将其全部删除(即 autofocus="disabled" 或 autofocus="off" 仍将自动聚焦标签)。

我已经创建了一个 pull request,这有望在未来的版本中得到修复。

目前,您可以在 textarea 之前创建一个禁用的 input 标签,并将 autofocus 属性和可见性设置为 hidden,这将阻止 textarea 获得焦点。

<input disabled autofocus style="visibilty: hidden">

我 运行 遇到了 Kevin Ashcraft 的回答问题,在 Safari 上它不起作用。

这是另一个选项,因为它是由于存在自动对焦属性而导致的,您需要删除该属性。所以我有聚合物元素,里面有以下内容

ready:function(){
    var list = Polymer.dom(this.root).querySelectorAll('iron-autogrow-textarea');
    list.forEach(function (e) {
        e.textarea.removeAttribute("autofocus")
    });
}

这会扫描我的对话框,找到所有 iron-autogrow-textarea 并从中删除属性...您可以更改选择器以仅获取您需要的那些。

更新此问题已在最新版本中修复 应该提及此问题已在 https://github.com/PolymerElements/iron-autogrow-textarea/releases/tag/v1.0.8

的最新版本中修复