pub struct GlobalClose { /* private fields */ }
Expand description

Helper to trigger a close operation, when the user clicks on the global space.

This can be e.g. used for a drop down menu, where the component should be closed when the user clicks outside of the dropped down content.

In order to use this, you need to define and assign the NodeRef to an element which is considered the “inside”. When the user clicks “outside” of the referenced element, it will execute the callback.

When the instance is dropped, the callback will no longer be fired.

When creating the structure, you can pass in a new NodeRef, and you can deref and clone later using the function GlobalClose::node_ref.

Implementations§

Examples found in repository?
src/dropdown.rs (line 50)
47
48
49
50
51
52
    fn create(ctx: &Context<Self>) -> Self {
        Self {
            expanded: false,
            global_close: GlobalClose::new(NodeRef::default(), ctx.link().callback(|_| Msg::Close)),
        }
    }
More examples
Hide additional examples
src/select.rs (line 96)
93
94
95
96
97
98
99
    fn create(ctx: &Context<Self>) -> Self {
        Self {
            expanded: false,
            global_close: GlobalClose::new(NodeRef::default(), ctx.link().callback(|_| Msg::Close)),
            selection: Vec::new(),
        }
    }
src/app_launcher.rs (line 37)
35
36
37
38
39
40
41
42
    fn create(ctx: &Context<Self>) -> Self {
        let global_close =
            GlobalClose::new(NodeRef::default(), ctx.link().callback(|_| Msg::Close));
        Self {
            expanded: false,
            global_close,
        }
    }
src/context_selector.rs (line 33)
31
32
33
34
35
36
37
38
    fn create(ctx: &Context<Self>) -> Self {
        let global_close =
            GlobalClose::new(NodeRef::default(), ctx.link().callback(|_| Msg::Close));
        Self {
            expanded: false,
            global_close,
        }
    }
src/pagination.rs (lines 58-61)
55
56
57
58
59
60
61
62
63
    fn create(ctx: &Context<Self>) -> Self {
        Self {
            expanded: false,
            global_close: GlobalClose::new(
                NodeRef::default(),
                ctx.link().callback(|_| Msg::CloseMenu),
            ),
        }
    }
src/popper.rs (line 68)
60
61
62
63
64
65
66
67
68
69
70
    fn create(ctx: &Context<Self>) -> Self {
        Self {
            target: NodeRef::default(),
            popper: None,
            _callback: None,
            active: false,
            state: None,
            _marker: Default::default(),
            global_close: GlobalClose::new(NodeRef::default(), ctx.link().callback(|_| Msg::Close)),
        }
    }

Methods from Deref<Target = NodeRef>§

Get the wrapped Node reference if it exists

Try converting the node reference into another form

Trait Implementations§

The resulting type after dereferencing.
Dereferences the value.
Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Convert self to a value of a Properties struct.
Convert self to a value of a Properties struct.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more