Skip to content

fix: correct implementation of setCaption #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/main/java/com/flowingcode/addons/applayout/AppLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@
import com.vaadin.flow.component.dependency.NpmPackage;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Image;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.dom.Element;
import com.vaadin.flow.router.RouterLayout;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;

/**
* Component that renders the div that contains the entire layout.
Expand All @@ -45,7 +49,6 @@ public class AppLayout extends Div implements RouterLayout {

private static final String PROFILE_SLOT_NAME = "profile";
private static final String APP_LAYOUT_TITLE_SLOT_NAME = "title";
private static final String TITLE_ATTRIBUTE_NAME = "title";
private final List<Component> menuItems = new ArrayList<>();
private final List<Component> toolbarComponents = new ArrayList<>();

Expand Down Expand Up @@ -146,7 +149,12 @@ public boolean isMenuVisible() {
* @param caption
*/
public void setCaption(String caption) {
getElement().setAttribute(TITLE_ATTRIBUTE_NAME, caption);
getChildren().map(Component::getElement)
.filter(child -> APP_LAYOUT_TITLE_SLOT_NAME.equals(child.getAttribute("slot")))
.collect(Collectors.toList()).forEach(Element::removeFromParent);
if (!StringUtils.isEmpty(caption)) {
addToTitleSection(new Span(caption));
}
}

/**
Expand Down