Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.flowingcode.vaadin.addons.chipfield</groupId>
<artifactId>chipfield-addon</artifactId>
<version>2.7.2-SNAPSHOT</version>
<version>2.8.0-SNAPSHOT</version>
<name>ChipField Addon</name>
<description>Integration of paper-chip for Vaadin 14 as a field</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ChipField Addon
* %%
* Copyright (C) 2018 - 2022 Flowing Code
* Copyright (C) 2018 - 2026 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -72,14 +72,14 @@
public static final String CHIP_LABEL = "event.detail.chipLabel";

private DataProvider<T, ?> availableItems = DataProvider.ofCollection(new ArrayList<T>());
private List<T> additionalItems = new ArrayList<>();

Check failure on line 75 in src/main/java/com/flowingcode/vaadin/addons/chipfield/ChipField.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make non-static "additionalItems" transient or serializable.

See more on https://sonarcloud.io/project/issues?id=FlowingCode_ChipFieldAddon&issues=AaBY1rNfjK1myYTdEkV4&open=AaBY1rNfjK1myYTdEkV4&pullRequest=90
private ItemLabelGenerator<T> itemLabelGenerator;
private SerializableFunction<String, T> newItemHandler;

public abstract static class ChipEvent<T> extends ComponentEvent<ChipField<T>> {

private final String chipLabel;
private final T item;

Check failure on line 82 in src/main/java/com/flowingcode/vaadin/addons/chipfield/ChipField.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make non-static "item" transient or serializable.

See more on https://sonarcloud.io/project/issues?id=FlowingCode_ChipFieldAddon&issues=AaBY1rNfjK1myYTdEkV5&open=AaBY1rNfjK1myYTdEkV5&pullRequest=90

private ChipEvent(ChipField<T> source, boolean fromClient, T item, String chipLabel) {
super(source, fromClient);
Expand Down Expand Up @@ -275,6 +275,26 @@
getElement().setProperty("label", label);
}

/**
* Sets whether the label is displayed as a static placeholder that is hidden when the input has a
* value, instead of floating above the input. When the label does not float, no space is reserved
* for it above the input.
*
* @param noLabelFloat {@code true} to prevent the label from floating, {@code false} otherwise.
*/
public void setNoLabelFloat(boolean noLabelFloat) {
getElement().setProperty("noLabelFloat", noLabelFloat);
}

/**
* Returns whether the label is prevented from floating above the input.
*
* @return {@code true} if the label does not float, {@code false} otherwise.
*/
public boolean isNoLabelFloat() {
return getElement().getProperty("noLabelFloat", false);
}

public String[] getChipsAsStrings() {
return super.getValue().stream().map(itemLabelGenerator).toArray(String[]::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ class PaperChipInputAutocomplete extends ThemableMixin(PolymerElement) {
value: ''
},

/**
* If true, the label is displayed as a static placeholder that is hidden
* when the input has a value, instead of floating above the input.
*/
noLabelFloat: {
type: Boolean,
value: false
},

/**
* If true, the paper-chip-input-autocomplete is focused.
*/
Expand Down Expand Up @@ -274,6 +283,7 @@ class PaperChipInputAutocomplete extends ThemableMixin(PolymerElement) {
disabled$="[[disabled]]"
readonly$="[[readonly]]"
label="[[label]]"
no-label-float$="[[noLabelFloat]]"
on-keyup="_findItems"
value="{{_inputValue}}"
autofocus="{{autofocus}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ChipField Addon
* %%
* Copyright (C) 2018 - 2022 Flowing Code
* Copyright (C) 2018 - 2026 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,5 +40,6 @@ public ChipfieldDemoView() {
addDemo(BinderDemo.class);
addDemo(ReadonlyDemo.class);
addDemo(StyledDemo.class);
addDemo(NoLabelFloatDemo.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*-
* #%L
* ChipField Addon
* %%
* Copyright (C) 2018 - 2026 Flowing Code
* %%
* 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.
* #L%
*/
package com.flowingcode.vaadin.addons.chipfield;

import com.flowingcode.vaadin.addons.demo.DemoSource;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;

@Route(value = "chipfield/no-label-float", layout = ChipfieldDemoView.class)
@PageTitle("No Label Float")
@DemoSource
@SuppressWarnings("serial")
public class NoLabelFloatDemo extends VerticalLayout {

public NoLabelFloatDemo() {
// by default, space is reserved above the input for the floating label,
// which misaligns the field from the label of the enclosing form item
ChipField<String> floating = newChipField();

// when the label does not float, no space is reserved for it above the input
ChipField<String> notFloating = newChipField();
notFloating.setNoLabelFloat(true);

FormLayout formLayout = new FormLayout();
formLayout.setResponsiveSteps(new FormLayout.ResponsiveStep("0", 1));
formLayout.setWidth("500px");
formLayout.addFormItem(floating, "Floating label");
formLayout.addFormItem(notFloating, "No label float");

add(formLayout);
}

private static ChipField<String> newChipField() {
ChipField<String> chf = new ChipField<>("", "Mercury", "Venus", "Earth", "Mars", "Jupiter");
chf.addSelectedItem("Earth");
chf.setClosable(true);
chf.setWidthFull();
return chf;
}
}
Loading