Skip to content

Commit

Permalink
Support web_sys
Browse files Browse the repository at this point in the history
  • Loading branch information
kuy committed Mar 8, 2020
1 parent 810b6f7 commit c272c2b
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/components/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@
use crate::callback::Callback;
use crate::html::{ChangeData, Component, ComponentLink, Html, NodeRef, ShouldRender};
use crate::macros::{html, Properties};
use cfg_if::cfg_if;
use cfg_match::cfg_match;
use stdweb::web::html_element::SelectElement;
cfg_if! {
if #[cfg(feature = "std_web")] {
use stdweb::web::html_element::SelectElement;
} else if #[cfg(feature = "web_sys")] {
use web_sys::HtmlSelectElement as SelectElement;
}
}

/// `Select` component.
#[derive(Debug)]
Expand Down Expand Up @@ -101,13 +108,15 @@ where
fn change(&mut self, props: Self::Properties) -> ShouldRender {
if self.props.selected != props.selected {
if let Some(select) = self.select_ref.cast::<SelectElement>() {
select.set_raw_value(
&props
.selected
.as_ref()
.map(|v| v.to_string())
.unwrap_or("".into()),
);
let val = props
.selected
.as_ref()
.map(|v| v.to_string())
.unwrap_or("".into());
cfg_match! {
feature = "std_web" => select.set_raw_value(&val),
feature = "web_sys" => select.set_value(&val),
}
}
}
self.props = props;
Expand Down

0 comments on commit c272c2b

Please sign in to comment.