Skip to content

Commit

Permalink
Expose evil focus callback; tab bar improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Follpvosten committed Apr 26, 2020
1 parent b19132a commit c22e7b9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/components/tabs/tab_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ impl Component for TabBar {

fn change(&mut self, props: Self::Properties) -> ShouldRender {
if self.props != props {
if let Some(tab) = props.activated_tab {
if tab as u64 != self.current_tab {
if let Some(ref inner) = self.inner {
inner.activate_tab(tab);
}
}
}
self.props = props;
true
} else {
Expand Down
16 changes: 16 additions & 0 deletions src/components/text_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,24 @@ pub struct Props {
pub onchange: Callback<String>,
#[prop_or_default]
pub children: Children,
#[prop_or_default]
pub evil_gimme_focus_callback: Option<Callback<Callback<()>>>,
}

pub enum Msg {
ValueChanged(String),
FocusRequested,
}

impl Component for TextField {
type Message = Msg;
type Properties = Props;

fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self {
if let Some(ref callback) = props.evil_gimme_focus_callback {
let my_callback = link.callback(|_| Msg::FocusRequested);
callback.emit(my_callback);
}
Self {
node_ref: NodeRef::default(),
props,
Expand All @@ -60,6 +67,10 @@ impl Component for TextField {

fn change(&mut self, props: Props) -> ShouldRender {
if props != self.props {
if let Some(ref callback) = props.evil_gimme_focus_callback {
let my_callback = self.link.callback(|_| Msg::FocusRequested);
callback.emit(my_callback);
}
self.props = props;
if let Some(inner) = &self.inner {
inner.set_value(&self.props.value);
Expand All @@ -75,6 +86,11 @@ impl Component for TextField {
Msg::ValueChanged(s) => {
self.props.onchange.emit(s);
}
Msg::FocusRequested => {
if let Some(ref inner) = self.inner {
inner.focus();
}
}
};
false
}
Expand Down
3 changes: 3 additions & 0 deletions src/mdc_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ extern "C" {
pub fn disabled(this: &MDCTextField) -> bool;
#[wasm_bindgen(method, setter)]
pub fn set_disabled(this: &MDCTextField, disabled: bool);

#[wasm_bindgen(method)]
pub fn focus(this: &MDCTextField);
}

#[cfg(feature = "menu")]
Expand Down

0 comments on commit c22e7b9

Please sign in to comment.