public void updateCaption(TabState tabState) {
// TODO need to call this because the caption does not have an owner
+ caption.setCaptionAsHtml(isTabCaptionsAsHtml());
caption.updateCaptionWithoutOwner(
tabState.caption,
!tabState.enabled,
}
private void updateFromState(TabState tabState) {
+ tabCaption.setCaptionAsHtml(getTabsheet().isTabCaptionsAsHtml());
tabCaption.update(tabState);
// Apply the styleName set for the tab
String newStyleName = tabState.styleName;
/** For internal use only. May be removed or replaced in the future. */
protected AbstractComponentConnector connector;
+ private boolean tabCaptionsAsHtml = false;
+
public VTabsheetBase(String classname) {
setElement(DOM.createDiv());
setStyleName(classname);
public boolean isEnabled() {
return !disabled;
}
+
+ /**
+ * Sets whether the caption is rendered as HTML.
+ * <p>
+ * The default is false, i.e. render tab captions as plain text
+ *
+ * @since 7.4
+ * @param captionAsHtml
+ * true if the captions are rendered as HTML, false if rendered
+ * as plain text
+ */
+ public void setTabCaptionsAsHtml(boolean tabCaptionsAsHtml) {
+ this.tabCaptionsAsHtml = tabCaptionsAsHtml;
+ }
+
+ /**
+ * Checks whether captions are rendered as HTML
+ *
+ * The default is false, i.e. render tab captions as plain text
+ *
+ * @since 7.4
+ * @return true if the captions are rendered as HTML, false if rendered as
+ * plain text
+ */
+ public boolean isTabCaptionsAsHtml() {
+ return tabCaptionsAsHtml;
+ }
+
}
}
}
+ /**
+ * Sets whether HTML is allowed in the tab captions.
+ * <p>
+ * If set to true, the captions are rendered in the browser as HTML and the
+ * developer is responsible for ensuring no harmful HTML is used. If set to
+ * false, the content is rendered in the browser as plain text.
+ * <p>
+ * The default is false, i.e. render tab captions as plain text
+ *
+ * @param tabCaptionsAsHtml
+ * true if the tab captions are rendered as HTML, false if
+ * rendered as plain text
+ * @since 7.4
+ */
+ public void setTabCaptionsAsHtml(boolean tabCaptionsAsHtml) {
+ getState().tabCaptionsAsHtml = tabCaptionsAsHtml;
+ }
+
+ /**
+ * Checks whether HTML is allowed in the tab captions.
+ * <p>
+ * The default is false, i.e. render tab captions as plain text
+ *
+ * @return true if the tab captions are rendered as HTML, false if rendered
+ * as plain text
+ * @since 7.4
+ */
+ public boolean isTabCaptionsAsHtml() {
+ return getState(false).tabCaptionsAsHtml;
+ }
}
import java.util.List;
import com.vaadin.shared.AbstractComponentState;
+import com.vaadin.shared.annotations.DelegateToWidget;
public class TabsheetState extends AbstractComponentState {
public static final String PRIMARY_STYLE_NAME = "v-tabsheet";
/** the key of the currently selected tab */
public String selected;
+ @DelegateToWidget
+ public boolean tabCaptionsAsHtml = false;
+
}
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.tabsheet;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Accordion;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.TabSheet;
+
+public class HtmlInTabCaption extends AbstractTestUI {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server.
+ * VaadinRequest)
+ */
+ @Override
+ protected void setup(VaadinRequest request) {
+ getLayout().setSpacing(true);
+ TabSheet ts = new TabSheet();
+ ts.setCaption("TabSheet - no <u>html</u> in tab captions");
+ ts.setCaptionAsHtml(true);
+ ts.addTab(new Label(), "<font color='red'>red</font>");
+ ts.addTab(new Label(), "<font color='blue'>blue</font>");
+ addComponent(ts);
+
+ ts = new TabSheet();
+ ts.setCaption("TabSheet - <b>html</b> in tab captions");
+ ts.setCaptionAsHtml(false);
+ ts.setTabCaptionsAsHtml(true);
+ ts.addTab(new Label(), "<font color='red'>red</font>");
+ ts.addTab(new Label(), "<font color='blue'>blue</font>");
+ addComponent(ts);
+
+ Accordion acc = new Accordion();
+ acc.setCaption("Accordion - no <u>html</u> in tab captions");
+ acc.setCaptionAsHtml(true);
+ acc.addTab(new Label(), "<font color='red'>red</font>");
+ acc.addTab(new Label(), "<font color='blue'>blue</font>");
+ addComponent(acc);
+
+ acc = new Accordion();
+ acc.setCaption("Accordion - <b>html</b> in tab captions");
+ acc.setCaptionAsHtml(false);
+ acc.setTabCaptionsAsHtml(true);
+ acc.addTab(new Label(), "<font color='red'>red</font>");
+ acc.addTab(new Label(), "<font color='blue'>blue</font>");
+ addComponent(acc);
+
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 14609;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.tabsheet;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.elements.AccordionElement;
+import com.vaadin.testbench.elements.TabSheetElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class HtmlInTabCaptionTest extends SingleBrowserTest {
+ static final String PLAIN_TEXT_RED = "<font color='red'>red</font>";
+ static final String HTML_TEXT_RED = "red";
+ static final String PLAIN_TEXT_BLUE = "<font color='blue'>blue</font>";
+ static final String HTML_TEXT_BLUE = "blue";
+
+ @Test
+ public void tabsheetWithoutHtmlCaptions() {
+ openTestURL();
+ TabSheetElement ts = $(TabSheetElement.class).get(0);
+ Assert.assertEquals(PLAIN_TEXT_RED, getTab(ts, 0).getText());
+ Assert.assertEquals(PLAIN_TEXT_BLUE, getTab(ts, 1).getText());
+ }
+
+ private WebElement getTab(TabSheetElement tabSheetElement, int i) {
+ String className = "v-tabsheet-tabitem";
+ if (tabSheetElement instanceof AccordionElement) {
+ className = "v-accordion-item";
+ }
+ return tabSheetElement.findElements(By.className(className)).get(i);
+ }
+
+ @Test
+ public void tabsheetWithHtmlCaptions() {
+ openTestURL();
+ TabSheetElement ts = $(TabSheetElement.class).get(1);
+ Assert.assertEquals(HTML_TEXT_RED, getTab(ts, 0).getText());
+ Assert.assertEquals(HTML_TEXT_BLUE, getTab(ts, 1).getText());
+ }
+
+ @Test
+ public void accordionWithoutHtmlCaptions() {
+ openTestURL();
+ AccordionElement acc = $(AccordionElement.class).get(0);
+ Assert.assertEquals(PLAIN_TEXT_RED, getTab(acc, 0).getText());
+ Assert.assertEquals(PLAIN_TEXT_BLUE, getTab(acc, 1).getText());
+
+ }
+
+ @Test
+ public void accordionWithHtmlCaptions() {
+ openTestURL();
+ AccordionElement acc = $(AccordionElement.class).get(1);
+ Assert.assertEquals(HTML_TEXT_RED, getTab(acc, 0).getText());
+ Assert.assertEquals(HTML_TEXT_BLUE, getTab(acc, 1).getText());
+ }
+}