kozan_core/events/
focus_event.rs1use crate::id::RawId;
8use kozan_macros::Event;
9
10#[derive(Debug, Clone, Event)]
15#[event()]
16#[non_exhaustive]
17pub struct FocusEvent {
18 pub related_target: Option<RawId>,
22}
23
24#[derive(Debug, Clone, Event)]
29#[event()]
30#[non_exhaustive]
31pub struct BlurEvent {
32 pub related_target: Option<RawId>,
34}
35
36#[derive(Debug, Clone, Event)]
41#[event(bubbles)]
42#[non_exhaustive]
43pub struct FocusInEvent {
44 pub related_target: Option<RawId>,
46}
47
48#[derive(Debug, Clone, Event)]
53#[event(bubbles)]
54#[non_exhaustive]
55pub struct FocusOutEvent {
56 pub related_target: Option<RawId>,
58}
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63 use crate::events::{Bubbles, Cancelable, Event};
64 use crate::id::RawId;
65
66 #[test]
67 fn focus_does_not_bubble() {
68 let evt = FocusEvent {
69 related_target: None,
70 };
71 assert_eq!(evt.bubbles(), Bubbles::No);
72 assert_eq!(evt.cancelable(), Cancelable::No);
73 }
74
75 #[test]
76 fn blur_does_not_bubble() {
77 let evt = BlurEvent {
78 related_target: Some(RawId::new(42, 0)),
79 };
80 assert_eq!(evt.bubbles(), Bubbles::No);
81 assert_eq!(evt.cancelable(), Cancelable::No);
82 }
83
84 #[test]
85 fn focusin_bubbles() {
86 let evt = FocusInEvent {
87 related_target: None,
88 };
89 assert_eq!(evt.bubbles(), Bubbles::Yes);
90 assert_eq!(evt.cancelable(), Cancelable::No);
91 }
92
93 #[test]
94 fn focusout_bubbles() {
95 let evt = FocusOutEvent {
96 related_target: Some(RawId::new(7, 1)),
97 };
98 assert_eq!(evt.bubbles(), Bubbles::Yes);
99 assert_eq!(evt.cancelable(), Cancelable::No);
100 }
101}