use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.
the class ComboBoxView method autoOpenDisabled.
private void autoOpenDisabled() {
Span note = new Span("Dropdown is only opened when clicking the toggle button or pressing Up or Down arrow keys.");
ComboBox<String> comboBox = new ComboBox<>();
comboBox.setItems("Option one", "Option two");
comboBox.setAutoOpen(false);
addCard("Auto open disabled", note, comboBox);
}
use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.
the class ComboBoxDemoPage method createWithClearButton.
private void createWithClearButton() {
ComboBox<String> comboBox = new ComboBox<>("Browsers");
comboBox.setItems("Google Chrome", "Mozilla Firefox", "Opera", "Apple Safari", "Microsoft Edge");
comboBox.setValue("Google Chrome");
// Display an icon which can be clicked to clear the value:
comboBox.setClearButtonVisible(true);
comboBox.getStyle().set(ElementConstants.STYLE_WIDTH, WIDTH_STRING);
comboBox.setId("clear-button-box");
add(new Div(new H2("Clear button"), comboBox));
}
use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.
the class ComboBoxDemoPage method createComboBoxWithObjectStringSimpleValue.
private void createComboBoxWithObjectStringSimpleValue() {
Div message = createMessageDiv("value-selection-message");
ComboBox<Song> comboBox = new ComboBox<>("Artists");
comboBox.setItemLabelGenerator(Song::getArtist);
List<Song> listOfSongs = createListOfSongs();
comboBox.setItems(listOfSongs);
comboBox.addValueChangeListener(event -> {
if (event.getSource().isEmpty()) {
message.setText("No artist selected");
} else if (event.getOldValue() == null) {
message.setText("Selected artist: " + event.getValue().getArtist());
} else {
message.setText("Selected artist: " + event.getValue().getArtist() + "\nThe old selection was: " + event.getOldValue().getArtist());
}
});
comboBox.getStyle().set(ElementConstants.STYLE_WIDTH, WIDTH_STRING);
comboBox.setId("value-selection-box");
add(new Div(new H2("Value selection from objects"), comboBox, message));
}
use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.
the class ComboBoxDemoPage method createComboBoxWithInMemoryLazyLoading.
private void createComboBoxWithInMemoryLazyLoading() {
ComboBox<String> comboBox = new ComboBox<>();
/*
* Using a large data set makes the browser request items lazily as the
* user scrolls down the overlay. This will also trigger server-side
* filtering.
*/
List<String> names = getNames(500);
comboBox.setItems(names);
comboBox.setId("lazy-loading-box");
add(new Div(new H2("Lazy Loading"), new H2("Lazy loading between client and server"), comboBox));
}
use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.
the class ComboBoxDemoPage method createComboBoxUsingTemplateRenderer.
private void createComboBoxUsingTemplateRenderer() {
Div message = createMessageDiv("template-selection-message");
ComboBox<Song> comboBox = new ComboBox<>();
List<Song> listOfSongs = createListOfSongs();
/*
* Providing a custom item filter allows filtering based on all of the
* rendered properties:
*/
ItemFilter<Song> filter = (song, filterString) -> song.getName().toLowerCase().contains(filterString.toLowerCase()) || song.getArtist().toLowerCase().contains(filterString.toLowerCase());
comboBox.setItems(filter, listOfSongs);
comboBox.setItemLabelGenerator(Song::getName);
comboBox.setRenderer(TemplateRenderer.<Song>of("<div>[[item.song]]<br><small>[[item.artist]]</small></div>").withProperty("song", Song::getName).withProperty("artist", Song::getArtist));
comboBox.addValueChangeListener(event -> {
if (event.getSource().isEmpty()) {
message.setText("No artist selected");
} else if (event.getOldValue() == null) {
message.setText("Selected artist: " + event.getValue().getArtist());
} else {
message.setText("Selected artist: " + event.getValue().getArtist() + "\nThe old selection was: " + event.getOldValue().getArtist());
}
});
comboBox.getStyle().set(ElementConstants.STYLE_WIDTH, WIDTH_STRING);
comboBox.setId("template-selection-box");
add(new Div(new H2("Using templates"), new H2("Rendering items using TemplateRenderer"), comboBox, message));
}
Aggregations