patternfly_yew/hooks/
enter.rs

1use yew::prelude::*;
2
3/// Create a new callback handling only the case when the user pressed the enter key.
4#[hook]
5pub fn use_on_enter<F, D>(d: D, f: F) -> Callback<KeyboardEvent>
6where
7    F: Fn(&D) + 'static,
8    D: PartialEq + 'static,
9{
10    use_callback(d, move |evt: KeyboardEvent, d| {
11        if evt.key_code() == 13 {
12            f(d)
13        }
14    })
15}