Browse Source

Fix combobox adding new items on blur (#9660)

Fixes #9071
tags/8.1.0.rc2
Teemu Suo-Anttila 6 years ago
parent
commit
01a453649e

+ 10
- 2
client/src/main/java/com/vaadin/client/ui/VComboBox.java View File

@@ -2489,11 +2489,19 @@ public class VComboBox extends Composite implements Field, KeyDownHandler,

focused = false;
updatePlaceholder();
removeStyleDependentName("focus");

// Send new items when clicking out with the mouse.
if (!readonly) {
reset();
if (textInputEnabled && allowNewItems
&& (currentSuggestion == null || tb.getText().equals(
currentSuggestion.getReplacementString()))) {
dataReceivedHandler.reactOnInputWhenReady(tb.getText());
} else {
reset();
}
suggestionPopup.hide();
}
removeStyleDependentName("focus");

connector.sendBlurEvent();
}

+ 16
- 0
uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxSelectingWithNewItemsAllowedTest.java View File

@@ -21,6 +21,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedCondition;

import com.vaadin.testbench.By;
@@ -64,6 +65,14 @@ public class ComboBoxSelectingWithNewItemsAllowedTest extends MultiBrowserTest {
assertThatSelectedValueIs("a");
}

@Test
public void itemIsAddedWithClickOut() {
typeInputAndClickOut("a");

assertOneMoreThanInitial();
assertThatSelectedValueIs("a");
}

@Test
public void matchingSuggestionIsSelectedWithEnter() {
typeInputAndHitEnter("a0");
@@ -204,6 +213,13 @@ public class ComboBoxSelectingWithNewItemsAllowedTest extends MultiBrowserTest {
sendKeysToInput(Keys.TAB);
}

private void typeInputAndClickOut(String input) {
clearInputAndType(input);
new Actions(getDriver()).moveToElement(comboBoxElement, 10, 10)
.moveByOffset(comboBoxElement.getSize().getWidth(), 0).click()
.perform();
}

private void clearInputAndType(String input) {
comboBoxElement.clear();
sendKeysToInput(input);

Loading…
Cancel
Save