0

I'm working on a web application using the reflex library, and I'm trying to implement a feature where a function is executed when the user presses the Enter key in an input field. Specifically, I have an Input component, and I want to trigger a search function when the user presses Enter.

Here's what I've tried so far:

# My State class
class State(rx.State):
    # ... (other state variables)

    def handle_key_press(self, event):
        if event.type_ == 'key_down' and event.key == 'Enter':
            self.handle_search()

# My Input component
rx.input(
    placeholder="Search here...",
    on_key_down=State.handle_key_press,
)

However, I'm encountering an error, and the function is not being triggered as expected. I've checked the documentation, but I couldn't find detailed information on the structure of the event object returned by the on_key_down event.

Could someone please provide me with more information on the structure of the event object returned by the on_key_down event trigger? Specifically, what properties should I be checking to determine if the Enter key was pressed? Additionally, if there's a better way to achieve this functionality in the reflex library, I'd greatly appreciate any guidance.

Thank you for your help!

0 Answers0