瀏覽代碼

Ensure pop-up is not opened, when tabbing out fast from Combobox (#11436)

Checking that no prior Combobox behavior is broken

* Cleaning-up the code

Adding UI test

* Adding TestBench test
tags/8.8.0.beta1
Anastasia Smirnova 5 年之前
父節點
當前提交
6cc773fb7c

+ 9
- 4
client/src/main/java/com/vaadin/client/ui/VComboBox.java 查看文件

if (!waitingForFilteringResponse && suggestionPopup.isAttached()) { if (!waitingForFilteringResponse && suggestionPopup.isAttached()) {
showPopup = true; showPopup = true;
} }
if (showPopup) {
// Don't show popup, if is not focused
if (showPopup && focused) {
suggestionPopup.showSuggestions(currentPage); suggestionPopup.showSuggestions(currentPage);
} }




/** For internal use only. May be removed or replaced in the future. */ /** For internal use only. May be removed or replaced in the future. */
public boolean focused = false; public boolean focused = false;

/** For internal use only. May be removed or replaced in the future. */
public boolean noKeyDownEvents = true;
/** /**
* If set to false, the component should not allow entering text to the * If set to false, the component should not allow entering text to the
* field even for filtering. * field even for filtering.
return; return;
} }


noKeyDownEvents = false;
if (suggestionPopup.isAttached()) { if (suggestionPopup.isAttached()) {
if (enableDebug) { if (enableDebug) {
debug("Keycode " + keyCode + " target is popup"); debug("Keycode " + keyCode + " target is popup");


// queue this, may be cancelled by selection // queue this, may be cancelled by selection
int selectedIndex = suggestionPopup.menu.getSelectedIndex(); int selectedIndex = suggestionPopup.menu.getSelectedIndex();
if (!allowNewItems && selectedIndex != -1) {
if (!allowNewItems && selectedIndex != -1
&& !currentSuggestions.isEmpty()) {
onSuggestionSelected(currentSuggestions.get(selectedIndex)); onSuggestionSelected(currentSuggestions.get(selectedIndex));
} else { } else {
dataReceivedHandler.reactOnInputWhenReady(tb.getText()); dataReceivedHandler.reactOnInputWhenReady(tb.getText());
// NOP // NOP
break; break;
default: default:
if (textInputEnabled) {
if (textInputEnabled && !noKeyDownEvents) {
// when filtering, we always want to see the results on the // when filtering, we always want to see the results on the
// first page first. // first page first.
filterOptions(0); filterOptions(0);
return; return;
} }


noKeyDownEvents = true;
focused = true; focused = true;
updatePlaceholder(); updatePlaceholder();
addStyleDependentName("focus"); addStyleDependentName("focus");

+ 43
- 0
uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxFastTabbingOut.java 查看文件

package com.vaadin.tests.components.combobox;

import com.vaadin.annotations.Widgetset;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.ComboBox;

import java.util.ArrayList;

@Widgetset("com.vaadin.DefaultWidgetSet")
public class ComboboxFastTabbingOut extends AbstractTestUI {
@Override
protected void setup(VaadinRequest request) {
ComboBox<String> combobox = new ComboBox<>(
"Press any letter and tab out fast. The pop-up should stay closed");
ArrayList<String> values = new ArrayList<>();
values.add("AMERICAN SAMOA");
values.add("ANTIGUA AND BARBUDA");
values.add("Bali");
combobox.setId("firstCombobox");
combobox.setItems(values);

ComboBox<String> combobox2 = new ComboBox<>(
"Focusing after tabbing from another CB should not open the pop-up");

combobox2.setItems("AMERICAN SAMOA", "ANTIGUA AND BARBUDA", "Lake 1",
"Lake 2");
combobox2.setId("secondCombobox");
addComponent(combobox);
addComponent(combobox2);
}

@Override
protected String getTestDescription() {
return "On tabbing out fast, the popup window stays closed";
}

@Override
protected Integer getTicketNumber() {
return 11354;
}

}

Loading…
取消
儲存