I’m using Polaris. ember-cli: 6.3.1 node: 20.19.4 os: win32 x64
And I want to set the focus to a component after the user has created a tag. This is a partial code block: if you need more, please ask.
My issue is that this won’t build. Everything I’ve read says that I don’t need to import ref and that ember-ref-modifier should already be installed and part of the base ember build package.
The desired effect is when the user types in the input, and presses enter, the application builds the tag, updates the display and then the user can add another tag. This works now but I want the focus to go back to the input field so the user can just type text, hit enter, and repeat without having to click on the input field again, and again.
So there are two actual questions. One, is this even the correct approach? Two, if it is, can you give a hint as to why I’m not getting it to work?
Attempted to resolve a modifier in a strict mode template, but that value was not in scope: ref:
|
| {{ref this.setInputElement}}
|
@tracked inputElement = null;
@action
setFocus() {
this.inputElement?.focus();
}
@action
setInputElement(element) {
this.inputElement = element;
}
<template>
<div class='flex flex-wrap gap-1' ...attributes>
<LabelValue @label='Tags' @colectomy={{true}} />
{{#each @tags as |tag index|}}
<TagDisplay
@tag={{tag}}
@onDelete={{fn this.onDelete index}}
@color={{this.colorBar index}}
/>
{{/each}}
<InputText
class='text-xs max-w-32 max-h-5'
@onEnterKeyDown={{this.onEnter}}
@onBlur={{this.onEnter}}
@value={{this.newTag}}
data-test-user-tag-editor-input
{{ref this.setInputElement}}
/>
</div>
</template>