我的组件包含许多文本区域和一个用于添加另一个文本区域的按钮。当用户单击按钮时,会添加一个新的文本区域。我希望焦点移到这个新的文本区域。
我看到了这个答案,但它是针对旧版本的,我们没有将 jQuery 与 Ember 一起使用。
到目前为止我所拥有的:
五个为什么
type LocalWhy = {
content: string;
};
export default class FiveWhys extends Component<FiveWhysArgs> {
@tracked
whys: LocalWhy[] = ...
@action
addWhy() {
this.whys.pushObject({ content: "" });
}
}
五个为什么.hbs
{{#each this.whys as |why i|}}
<TextQuestion @value={{why.content}} />
{{/each}}
<button {{on "click" (action this.addWhy)}}>Add Why</button>
文本问题.hbs
...
<textarea value="{{ @value }}" />
问题摘要
用户单击“添加原因”后,如何将焦点设置到新的文本区域?