From b5653e4376115974c7f015d7601ce0dff831f7cf Mon Sep 17 00:00:00 2001 From: David-OConnor Date: Sat, 22 Jun 2019 15:04:25 +0400 Subject: [PATCH] cleanup for 0.3.7 release --- CHANGELOG.md | 4 ++-- src/dom_types.rs | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d280af959..2e535a313 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,8 +13,8 @@ in addition to semicolons - `Listener` now implements `MessageMapper` - `El methods` `add_child`, `add_style`, `add_attr`, and `set_text` now return the elements, allowing chaining -- Fixed a bug with `set_text`. Renamed to `replace_text`. Aded `add_text`, which adds -a text node, but doesn't remove existing ones. Added `add_class`. +- Fixed a bug with `set_text`. Renamed to `replace_text`. Added `add_text`, which adds +a text node, but doesn't remove existing ones. Added `add_class`. (Breaking) ## v0.3.6 diff --git a/src/dom_types.rs b/src/dom_types.rs index e51a5f372..dc0148b6f 100644 --- a/src/dom_types.rs +++ b/src/dom_types.rs @@ -850,7 +850,11 @@ impl El { pub fn add_class(mut self, name: &str) -> Self { let mut updated = name.to_string(); if let Some(names) = self.attrs.vals.get(&At::Class) { - updated = names.clone() + " " + name; + if names.is_empty() { + updated = name.to_string(); + } else { + updated = names.clone() + " " + name; + } } self.attrs.vals.insert(At::Class, updated); self @@ -862,7 +866,8 @@ impl El { self } - /// Add a text node to the element. (ie between the HTML tags) + /// Add a text node to the element. (ie between the HTML tags). + /// Removes all text nodes from element, then adds the new one. pub fn add_text(mut self, text: &str) -> Self { // todo: Allow text to be impl ToString? self.children.push(El::new_text(text));