-
Notifications
You must be signed in to change notification settings - Fork 614
Open
Labels
status:triageNew Issue - needs triageNew Issue - needs triage
Description
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
- PR fix(fast-html): fix event bindings inside f-when not firing after hydration #7327 originally included a workaround (manually walking parentContext/parent chain) that was reverted per review feedback
- Similar to FAST HTML templates should support adding context on passed events #7287 (event bindings context access)
- Repeat directive context docs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
status:triageNew Issue - needs triageNew Issue - needs triage