This commit is contained in:
Khaleel Al-Adhami 2024-10-22 12:07:27 -07:00
parent fcdee97aa0
commit ea471aaa6e
2 changed files with 25 additions and 1 deletions

View File

@ -38,6 +38,7 @@ from reflex.constants import (
) )
from reflex.constants.compiler import SpecialAttributes from reflex.constants.compiler import SpecialAttributes
from reflex.event import ( from reflex.event import (
EventCallback,
EventChain, EventChain,
EventChainVar, EventChainVar,
EventHandler, EventHandler,
@ -1126,6 +1127,8 @@ class Component(BaseComponent, ABC):
for trigger in self.event_triggers.values(): for trigger in self.event_triggers.values():
if isinstance(trigger, EventChain): if isinstance(trigger, EventChain):
for event in trigger.events: for event in trigger.events:
if isinstance(event, EventCallback):
continue
if isinstance(event, EventSpec): if isinstance(event, EventSpec):
if event.handler.state_full_name: if event.handler.state_full_name:
return True return True

View File

@ -16,6 +16,7 @@ from typing import (
Generic, Generic,
List, List,
Optional, Optional,
Sequence,
Tuple, Tuple,
Type, Type,
TypeVar, TypeVar,
@ -389,7 +390,9 @@ class CallableEventSpec(EventSpec):
class EventChain(EventActionsMixin): class EventChain(EventActionsMixin):
"""Container for a chain of events that will be executed in order.""" """Container for a chain of events that will be executed in order."""
events: List[Union[EventSpec, EventVar]] = dataclasses.field(default_factory=list) events: Sequence[Union[EventSpec, EventVar, EventCallback]] = dataclasses.field(
default_factory=list
)
args_spec: Optional[Callable] = dataclasses.field(default=None) args_spec: Optional[Callable] = dataclasses.field(default=None)
@ -1468,6 +1471,24 @@ if sys.version_info >= (3, 10):
""" """
self.func = func self.func = func
@property
def prevent_default(self):
"""Prevent default behavior.
Returns:
The event callback with prevent default behavior.
"""
return self
@property
def stop_propagation(self):
"""Stop event propagation.
Returns:
The event callback with stop propagation behavior.
"""
return self
@overload @overload
def __call__( def __call__(
self: EventCallback[Concatenate[V, Q], T], value: V | Var[V] self: EventCallback[Concatenate[V, Q], T], value: V | Var[V]