Skip to content

Commit

Permalink
fix #947 Calling SetTitle twice on NavBar removes description
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Jul 26, 2024
1 parent 896c9de commit 816bc36
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions domino-ui/src/main/java/org/dominokit/domino/ui/layout/NavBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.dominokit.domino.ui.elements.HeadingElement;
import org.dominokit.domino.ui.elements.NavElement;
import org.dominokit.domino.ui.elements.SmallElement;
import org.dominokit.domino.ui.elements.SpanElement;
import org.dominokit.domino.ui.utils.*;

/**
Expand Down Expand Up @@ -57,6 +58,7 @@
public class NavBar extends BaseDominoElement<HTMLElement, NavBar> {
private NavElement root;
private HeadingElement title;
private SpanElement titleTextElement;
private LazyChild<SmallElement> description;
private DivElement body;

Expand Down Expand Up @@ -84,7 +86,7 @@ public NavBar() {
root =
nav()
.addCss(dui_nav_bar)
.appendChild(title = h(4).addCss(dui_nav_title))
.appendChild(title = h(4).appendChild(titleTextElement = span()).addCss(dui_nav_title))
.appendChild(body = div().addCss(dui_nav_body));
description = LazyChild.of(small().addCss(dui_nav_description), title);
init(this);
Expand Down Expand Up @@ -118,7 +120,7 @@ public NavBar(String title, String description) {
* @return This {@code NavBar} instance.
*/
public NavBar setTitle(String title) {
this.title.setTextContent(title);
this.titleTextElement.setTextContent(title);
return this;
}

Expand Down Expand Up @@ -159,6 +161,17 @@ public NavBar withDescription(ChildHandler<NavBar, SmallElement> handler) {
return this;
}

/**
* Allows customization of the title text element.
*
* @param handler The handler for customizing the title text element.
* @return This {@code NavBar} instance.
*/
public NavBar withTitleTextElement(ChildHandler<NavBar, SpanElement> handler) {
handler.apply(this, titleTextElement);
return this;
}

/**
* Gets the title element.
*
Expand Down Expand Up @@ -186,6 +199,11 @@ public String getTitle() {
return title.getTextContent();
}

/** @return the element containing the text of the title. */
public SpanElement getTitleTextElement() {
return titleTextElement;
}

/**
* Gets the text of the description displayed in the navigation bar.
*
Expand Down

0 comments on commit 816bc36

Please sign in to comment.