Function maybe_attr

Source
pub fn maybe_attr<MSG>(
    name: AttributeName,
    value: Option<impl Into<Value>>,
) -> Attribute<MSG>
Expand description

Set the attribute of this element if value is Some, empty attribute otherwise

ยงExamples

use sauron::{*, html::attributes::maybe_attr};

let width = Some(10);
let html: Node<()> = button(vec![maybe_attr("width", width)], vec![]);
let expected = r#"<button width="10"></button>"#;
assert_eq!(expected, html.render_to_string());

let width = None::<usize>;
let html: Node<()> = button(vec![maybe_attr("width", width)], vec![]);
let expected = r#"<button></button>"#;
assert_eq!(expected, html.render_to_string());