import com.vaadin.shared.EventId;
import com.vaadin.shared.communication.FieldRpc.FocusAndBlurServerRpc;
import com.vaadin.shared.ui.ComponentStateUtil;
-import com.vaadin.shared.ui.ContentMode;
import com.vaadin.shared.ui.tabsheet.TabState;
import com.vaadin.shared.ui.tabsheet.TabsheetServerRpc;
import com.vaadin.shared.ui.tabsheet.TabsheetState;
if (tabState.description != null
|| tabState.componentError != null) {
setTooltipInfo(new TooltipInfo(tabState.description,
- ContentMode.PREFORMATTED, tabState.componentError,
- this));
+ tabState.descriptionContentMode,
+ tabState.componentError, this));
} else {
setTooltipInfo(null);
}
import com.vaadin.server.Resource;
import com.vaadin.shared.ComponentConstants;
import com.vaadin.shared.Registration;
+import com.vaadin.shared.ui.ContentMode;
import com.vaadin.shared.ui.tabsheet.TabState;
import com.vaadin.shared.ui.tabsheet.TabsheetClientRpc;
import com.vaadin.shared.ui.tabsheet.TabsheetServerRpc;
* Sets the description for the tab. The description can be used to
* briefly describe the state of the tab to the user, and is typically
* shown as a tooltip when hovering over the tab.
+ * <p>
+ * Setting a description through this method will additionally set the
+ * content mode of the description to preformatted. For setting a
+ * different content mode see the overload
+ * {@link #setDescription(String, ContentMode)}.
*
* @param description
* the new description string for the tab.
*/
public void setDescription(String description);
+ /**
+ * Sets the description for the tab. The description can be used to
+ * briefly describe the state of the tab to the user, and is typically
+ * shown as a tooltip when hovering over the tab.
+ *
+ * @see ContentMode
+ *
+ * @param description
+ * the new description string for the tab
+ * @param mode
+ * content mode used to display the description
+ *
+ * @since 8.1
+ */
+ public void setDescription(String description, ContentMode mode);
+
/**
* Sets an error indicator to be shown in the tab. This can be used e.g.
* to communicate to the user that there is a problem in the contents of
@Override
public void setDescription(String description) {
+ setDescription(description, ContentMode.PREFORMATTED);
+ }
+
+ @Override
+ public void setDescription(String description, ContentMode mode) {
tabState.description = description;
+ tabState.descriptionContentMode = mode;
markAsDirty();
}
import java.io.Serializable;
+import com.vaadin.shared.ui.ContentMode;
+
/**
* Shared state of a single tab in a Tabsheet or an Accordion.
*
public boolean visible = true;
public boolean closable = false;
public String description = null;
+ public ContentMode descriptionContentMode = ContentMode.PREFORMATTED;
public String styleName;
public String key;
public String componentError;
--- /dev/null
+package com.vaadin.tests.components.tabsheet;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.ui.ContentMode;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.TabSheet;
+import com.vaadin.ui.TabSheet.Tab;
+
+public class TabDescriptionContentMode extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ TabSheet tabSheet = new TabSheet();
+
+ Tab firstTab = tabSheet.addTab(new Label());
+ firstTab.setCaption("First tab");
+ firstTab.setDescription("First tab description", ContentMode.TEXT);
+
+ Tab secondTab = tabSheet.addTab(new Label());
+ secondTab.setCaption("Second tab");
+ secondTab.setDescription("Second tab\ndescription",
+ ContentMode.PREFORMATTED);
+
+ Tab thirdTab = tabSheet.addTab(new Label());
+ thirdTab.setCaption("Third tab");
+ thirdTab.setDescription("<b>Third tab description</b>",
+ ContentMode.HTML);
+
+ Tab fourthTab = tabSheet.addTab(new Label());
+ fourthTab.setCaption("Fourth tab");
+ fourthTab.setDescription("Fourth tab description");
+
+ Button changeFourthTabDescription = new Button(
+ "Change fourth tab description");
+ changeFourthTabDescription.addClickListener(
+ event -> fourthTab.setDescription(
+ "Fourth tab description, changed",
+ ContentMode.TEXT));
+
+ addComponents(tabSheet, changeFourthTabDescription);
+ }
+}
--- /dev/null
+package com.vaadin.tests.components.tabsheet;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class TabDescriptionContentModeTest extends SingleBrowserTest {
+
+ @Test
+ public void tab_description_content_modes() {
+ openTestURL();
+ List<WebElement> tabCaptions = findElements(
+ By.className("v-captiontext"));
+
+ hoverCaption(tabCaptions.get(0));
+ waitUntil(driver -> "First tab description"
+ .equals(getDescriptionElement().getText()));
+
+ hoverCaption(tabCaptions.get(1));
+ waitUntil(driver -> "Second tab\ndescription"
+ .equals(getDescriptionElement().findElement(By.tagName("pre"))
+ .getText()));
+
+ hoverCaption(tabCaptions.get(2));
+ waitUntil(
+ driver -> "Third tab description".equals(getDescriptionElement()
+ .findElement(By.tagName("b")).getText()));
+
+ hoverCaption(tabCaptions.get(3));
+ waitUntil(driver -> "Fourth tab description"
+ .equals(getDescriptionElement().findElement(By.tagName("pre"))
+ .getText()));
+
+ $(ButtonElement.class).first().click();
+ hoverCaption(tabCaptions.get(3));
+ waitUntil(driver -> "Fourth tab description, changed"
+ .equals(getDescriptionElement().getText()));
+ }
+
+ private void hoverCaption(WebElement captionElement) {
+ new Actions(getDriver()).moveToElement(captionElement, 1, 1).perform();
+ }
+
+ private WebElement getDescriptionElement() {
+ return findElement(By.className("v-tooltip-text"));
+ }
+}