add metainfo to keyevent
This commit is contained in:
parent
115a5c9203
commit
ba9f3304de
@ -25,7 +25,7 @@ from typing import (
|
|||||||
overload,
|
overload,
|
||||||
)
|
)
|
||||||
|
|
||||||
from typing_extensions import ParamSpec, Protocol, get_args, get_origin
|
from typing_extensions import ParamSpec, Protocol, TypedDict, get_args, get_origin
|
||||||
|
|
||||||
from reflex import constants
|
from reflex import constants
|
||||||
from reflex.constants.state import FRONTEND_EVENT_STATE
|
from reflex.constants.state import FRONTEND_EVENT_STATE
|
||||||
@ -440,6 +440,10 @@ class JavasciptKeyboardEvent:
|
|||||||
"""Interface for a Javascript KeyboardEvent https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent."""
|
"""Interface for a Javascript KeyboardEvent https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent."""
|
||||||
|
|
||||||
key: str = ""
|
key: str = ""
|
||||||
|
altKey: bool = False
|
||||||
|
ctrlKey: bool = False
|
||||||
|
metaKey: bool = False
|
||||||
|
shiftKey: bool = False
|
||||||
|
|
||||||
|
|
||||||
def input_event(e: Var[JavascriptInputEvent]) -> Tuple[Var[str]]:
|
def input_event(e: Var[JavascriptInputEvent]) -> Tuple[Var[str]]:
|
||||||
@ -454,7 +458,16 @@ def input_event(e: Var[JavascriptInputEvent]) -> Tuple[Var[str]]:
|
|||||||
return (e.target.value,)
|
return (e.target.value,)
|
||||||
|
|
||||||
|
|
||||||
def key_event(e: Var[JavasciptKeyboardEvent]) -> Tuple[Var[str]]:
|
class KeyInputInfo(TypedDict):
|
||||||
|
"""Information about a key input event."""
|
||||||
|
|
||||||
|
alt_key: bool
|
||||||
|
ctrl_key: bool
|
||||||
|
meta_key: bool
|
||||||
|
shift_key: bool
|
||||||
|
|
||||||
|
|
||||||
|
def key_event(e: Var[JavasciptKeyboardEvent]) -> Tuple[Var[str], Var[KeyInputInfo]]:
|
||||||
"""Get the key from a keyboard event.
|
"""Get the key from a keyboard event.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -463,7 +476,17 @@ def key_event(e: Var[JavasciptKeyboardEvent]) -> Tuple[Var[str]]:
|
|||||||
Returns:
|
Returns:
|
||||||
The key from the keyboard event.
|
The key from the keyboard event.
|
||||||
"""
|
"""
|
||||||
return (e.key,)
|
return (
|
||||||
|
e.key,
|
||||||
|
Var.create(
|
||||||
|
{
|
||||||
|
"alt_key": e.altKey,
|
||||||
|
"ctrl_key": e.ctrlKey,
|
||||||
|
"meta_key": e.metaKey,
|
||||||
|
"shift_key": e.shiftKey,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def empty_event() -> Tuple[()]:
|
def empty_event() -> Tuple[()]:
|
||||||
|
Loading…
Reference in New Issue
Block a user