Skip to content

Commit

Permalink
implement html from Option<VNode> (#2792)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Molzer <WorldSEnder@users.noreply.github.com>
  • Loading branch information
cecton and WorldSEnder committed Sep 14, 2022
1 parent 8eb9b5a commit 81f7ea4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/yew-macro/tests/html_macro/html-element-pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ fn compile_pass() {

// test for https://github.com/yewstack/yew/issues/2810
::yew::html! { <div data-type="date" data-as="calender" /> };

let option_vnode = ::std::option::Option::Some(::yew::html! {});
::yew::html! { <div>{option_vnode}</div> };
}

fn main() {}
9 changes: 9 additions & 0 deletions packages/yew/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ impl<IN: Into<OUT>, OUT> From<IN> for NodeSeq<IN, OUT> {
}
}

impl<IN: Into<OUT>, OUT> From<Option<IN>> for NodeSeq<IN, OUT> {
fn from(val: Option<IN>) -> Self {
Self(
val.map(|s| vec![s.into()]).unwrap_or_default(),
PhantomData::default(),
)
}
}

impl<IN: Into<OUT>, OUT> From<Vec<IN>> for NodeSeq<IN, OUT> {
fn from(val: Vec<IN>) -> Self {
Self(
Expand Down

0 comments on commit 81f7ea4

Please sign in to comment.