Skip to content

FAST-HTML should support event handler context access inside f-repeat #7329

@mohamedmansour

Description

@mohamedmansour

When an event binding like @click="{onItemClick(e)}" is used inside <f-repeat>, the handler's this context is bound to the repeat item rather than the host element. This means the handler can't
access the host element's properties or methods.

The repeat() directive's execution context provides parent (parent view-model) and parentContext (parent ExecutionContext), but fast-html's declarative <f-repeat> doesn't currently expose
these to event bindings.

Expected behavior

Event handlers inside <f-repeat> should be bound to the host element (or allow explicit context access), matching how repeat() works in imperative fast-element templates.

Reproduction

<f-template name="my-element">
    <template>
        <ul>
            <f-repeat value="{{item in items}}">
                <li>
                    <button @click="{onItemClick(e)}">{{item.name}}</button>
                </li>
            </f-repeat>
        </ul>
    </template>
</f-template>
   class MyElement extends FASTElement {
       @observable items = [{ name: "Alpha" }, { name: "Beta" }];
   
       // This handler is never reachable because `this` is bound
       // to the repeat item, not the host element.
       onItemClick(e: Event) {
           console.log("clicked", e.currentTarget);
       }
   }

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions