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



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

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


connector.sendBlurEvent(); connector.sendBlurEvent();
} }

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

import org.junit.Test; import org.junit.Test;
import org.openqa.selenium.Keys; import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.ExpectedCondition;


import com.vaadin.testbench.By; import com.vaadin.testbench.By;
assertThatSelectedValueIs("a"); assertThatSelectedValueIs("a");
} }


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

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

@Test @Test
public void matchingSuggestionIsSelectedWithEnter() { public void matchingSuggestionIsSelectedWithEnter() {
typeInputAndHitEnter("a0"); typeInputAndHitEnter("a0");
sendKeysToInput(Keys.TAB); 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) { private void clearInputAndType(String input) {
comboBoxElement.clear(); comboBoxElement.clear();
sendKeysToInput(input); sendKeysToInput(input);

Loading…
Cancel
Save