diff options
author | Denis Anisimov <denis@vaadin.com> | 2015-03-13 10:52:35 +0200 |
---|---|---|
committer | Markus Koivisto <markus@vaadin.com> | 2015-04-15 11:52:21 +0300 |
commit | 3ac8bf71e4b88e4c0fe683c84940509d6194c782 (patch) | |
tree | ea6f1d563b36e69dc84fc37e883f9d50510c879a | |
parent | 5daa2361381995bed07ccac6bd500681f1b050ce (diff) | |
download | vaadin-framework-3ac8bf71e4b88e4c0fe683c84940509d6194c782.tar.gz vaadin-framework-3ac8bf71e4b88e4c0fe683c84940509d6194c782.zip |
Don't use !important for ColorPicker width in Valo (#17140).
Change-Id: I47feff9c78a39e30233f388b938c7e4e53b52051
8 files changed, 244 insertions, 13 deletions
diff --git a/WebContent/VAADIN/themes/base/colorpicker/colorpicker.scss b/WebContent/VAADIN/themes/base/colorpicker/colorpicker.scss index b2558d8df3..70705dcee3 100644 --- a/WebContent/VAADIN/themes/base/colorpicker/colorpicker.scss +++ b/WebContent/VAADIN/themes/base/colorpicker/colorpicker.scss @@ -18,6 +18,9 @@ margin: 1px auto; } +.#{$name}.v-default-caption-width { + width: 100px; +} /***************** COLOR HISTORY COMPONENT *****************************/ .#{$name}-history { diff --git a/WebContent/VAADIN/themes/valo/components/_colorpicker.scss b/WebContent/VAADIN/themes/valo/components/_colorpicker.scss index b859904e59..18f92500dc 100644 --- a/WebContent/VAADIN/themes/valo/components/_colorpicker.scss +++ b/WebContent/VAADIN/themes/valo/components/_colorpicker.scss @@ -198,7 +198,7 @@ } .#{$primary-stylename} { - width: auto !important; + width: auto; } .#{$primary-stylename}-button-color { diff --git a/client/src/com/vaadin/client/ui/colorpicker/AbstractColorPickerConnector.java b/client/src/com/vaadin/client/ui/colorpicker/AbstractColorPickerConnector.java index ac168d1f9a..cba2a667ca 100644 --- a/client/src/com/vaadin/client/ui/colorpicker/AbstractColorPickerConnector.java +++ b/client/src/com/vaadin/client/ui/colorpicker/AbstractColorPickerConnector.java @@ -30,6 +30,8 @@ import com.vaadin.shared.ui.colorpicker.ColorPickerState; public abstract class AbstractColorPickerConnector extends AbstractComponentConnector implements ClickHandler { + private static final String DEFAULT_WIDTH_STYLE = "v-default-caption-width"; + @Override public ColorPickerState getState() { return (ColorPickerState) super.getState(); @@ -59,6 +61,7 @@ public abstract class AbstractColorPickerConnector extends || stateChangeEvent.hasPropertyChanged("showDefaultCaption")) { setCaption(getCaption()); + refreshDefaultCaptionStyle(); } } @@ -84,6 +87,19 @@ public abstract class AbstractColorPickerConnector extends } /** + * Add/remove default caption style. + */ + protected void refreshDefaultCaptionStyle() { + if (getState().showDefaultCaption + && (getState().caption == null || getState().caption.isEmpty()) + && getState().width.isEmpty()) { + getWidget().addStyleName(DEFAULT_WIDTH_STYLE); + } else { + getWidget().removeStyleName(DEFAULT_WIDTH_STYLE); + } + } + + /** * Set caption of the color picker widget. * * @param caption diff --git a/server/src/com/vaadin/ui/ColorPicker.java b/server/src/com/vaadin/ui/ColorPicker.java index f65b67db72..9e46c4e718 100644 --- a/server/src/com/vaadin/ui/ColorPicker.java +++ b/server/src/com/vaadin/ui/ColorPicker.java @@ -64,16 +64,4 @@ public class ColorPicker extends AbstractColorPicker { addStyleName(STYLENAME_DEFAULT); } - @Override - public void beforeClientResponse(boolean initial) { - super.beforeClientResponse(initial); - - if (isDefaultCaptionEnabled() - && ((getState().caption == null || "" - .equals(getState().caption))) - && "".equals(getState().width)) { - getState().width = "100px"; - } - } - } diff --git a/uitest/src/com/vaadin/tests/components/colorpicker/DefaultCaptionWidth.java b/uitest/src/com/vaadin/tests/components/colorpicker/DefaultCaptionWidth.java new file mode 100644 index 0000000000..d3dd0aeccc --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/colorpicker/DefaultCaptionWidth.java @@ -0,0 +1,72 @@ +/* + * 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.colorpicker; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.ColorPicker; + +/** + * Test for color picker with default caption. + * + * @author Vaadin Ltd + */ +public class DefaultCaptionWidth extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final ColorPicker colorPicker = new ColorPicker(); + addComponent(colorPicker); + colorPicker.setDefaultCaptionEnabled(true); + + Button setWidth = new Button("Set explicit width", + new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + colorPicker.setCaption(null); + colorPicker.setWidth("150px"); + } + }); + setWidth.addStyleName("set-width"); + addComponent(setWidth); + + Button setCaption = new Button("Set explicit caption", + new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + colorPicker.setCaption("caption"); + colorPicker.setWidthUndefined(); + } + }); + setCaption.addStyleName("set-caption"); + addComponent(setCaption); + + } + + @Override + protected String getTestDescription() { + return "Color picker with default caption enabled should get appropriate style"; + } + + @Override + protected Integer getTicketNumber() { + return 17140; + } +} diff --git a/uitest/src/com/vaadin/tests/components/colorpicker/DefaultCaptionWidthTest.java b/uitest/src/com/vaadin/tests/components/colorpicker/DefaultCaptionWidthTest.java new file mode 100644 index 0000000000..78b7120b4e --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/colorpicker/DefaultCaptionWidthTest.java @@ -0,0 +1,67 @@ +/* + * 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.colorpicker; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.elements.ColorPickerElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Test for default caption behavior in color picker. + * + * @author Vaadin Ltd + */ +public class DefaultCaptionWidthTest extends MultiBrowserTest { + + @Before + public void setUp() { + openTestURL(); + } + + @Test + public void setDefaultCaption_sizeAndCaptionAreNotSet_pickerGetsStyle() { + checkStylePresence(true); + } + + @Test + public void setDefaultCaption_explicitSizeIsSet_pickerNoCaptionStyle() { + findElement(By.className("set-width")).click(); + checkStylePresence(false); + } + + @Test + public void setDefaultCaption_explicitCaptionIsSet_pickerNoCaptionStyle() { + findElement(By.className("set-caption")).click(); + checkStylePresence(false); + } + + protected void checkStylePresence(boolean expectedStyle) { + String clazz = $(ColorPickerElement.class).first() + .getAttribute("class"); + if (expectedStyle) { + Assert.assertTrue("Default caption style is not found", + clazz.contains("v-default-caption-width")); + } else { + Assert.assertFalse("Found unexpected default caption style", + clazz.contains("v-default-caption-width")); + } + } + +} diff --git a/uitest/src/com/vaadin/tests/themes/valo/ValoDefaultCaptionWidth.java b/uitest/src/com/vaadin/tests/themes/valo/ValoDefaultCaptionWidth.java new file mode 100644 index 0000000000..6ef585cc12 --- /dev/null +++ b/uitest/src/com/vaadin/tests/themes/valo/ValoDefaultCaptionWidth.java @@ -0,0 +1,29 @@ +/* + * 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.themes.valo; + +import com.vaadin.annotations.Theme; +import com.vaadin.tests.components.colorpicker.DefaultCaptionWidth; + +/** + * Test for color picker with default caption. + * + * @author Vaadin Ltd + */ +@Theme("valo") +public class ValoDefaultCaptionWidth extends DefaultCaptionWidth { + +} diff --git a/uitest/src/com/vaadin/tests/themes/valo/ValoDefaultCaptionWidthTest.java b/uitest/src/com/vaadin/tests/themes/valo/ValoDefaultCaptionWidthTest.java new file mode 100644 index 0000000000..7651b641de --- /dev/null +++ b/uitest/src/com/vaadin/tests/themes/valo/ValoDefaultCaptionWidthTest.java @@ -0,0 +1,56 @@ +/* + * 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.themes.valo; + +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.lessThan; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +import com.vaadin.testbench.elements.ColorPickerElement; +import com.vaadin.tests.components.colorpicker.DefaultCaptionWidthTest; + +/** + * Test for default caption behavior in color picker using Valo theme. + * + * @author Vaadin Ltd + */ +public class ValoDefaultCaptionWidthTest extends DefaultCaptionWidthTest { + + @Override + @Test + public void setDefaultCaption_sizeAndCaptionAreNotSet_pickerGetsStyle() { + super.setDefaultCaption_sizeAndCaptionAreNotSet_pickerGetsStyle(); + int width = $(ColorPickerElement.class).first().getSize().getWidth(); + // Make sure that implicit width is less than one that will be + // explicitly set by the test + assertThat("Width of color picker is overriden by " + + "default caption feature", width, is(lessThan(148))); + } + + @Override + @Test + public void setDefaultCaption_explicitSizeIsSet_pickerNoCaptionStyle() { + super.setDefaultCaption_explicitSizeIsSet_pickerNoCaptionStyle(); + int width = $(ColorPickerElement.class).first().getSize().getWidth(); + // Width should be 150px but let's just check that it's not which is + // used when default caption is used and at least >= 150-1 + assertThat("Width of color picker is overriden by " + + "default caption feature", width, is(greaterThan(149))); + } +} |