Skip to content

Commit 1171951

Browse files
WIP: fix: avoid creating duplicate tooltips in HasTooltip impl
1 parent 411c095 commit 1171951

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/main/java/com/flowingcode/vaadin/addons/togglebutton/ToggleButton.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class ToggleButton extends AbstractSinglePropertyField<ToggleButton, Bool
5151
HasThemeVariant<ToggleButtonVariant> {
5252

5353
private ItemLabelGenerator<Boolean> itemLabelGenerator = b -> "";
54+
private Tooltip tooltip;
5455

5556
/** Creates a new toggle button with an initial value of {@code false}. */
5657
public ToggleButton() {
@@ -106,11 +107,21 @@ public boolean isReadOnly() {
106107

107108
@Override
108109
public Tooltip setTooltipText(String text) {
109-
Tooltip tooltip = Tooltip.forComponent(this);
110+
if (tooltip == null) {
111+
tooltip = Tooltip.forComponent(this);
112+
}
110113
tooltip.setText(text);
111114
return tooltip;
112115
}
113116

117+
@Override
118+
public Tooltip getTooltip() {
119+
if (tooltip == null) {
120+
tooltip = Tooltip.forComponent(this);
121+
}
122+
return tooltip;
123+
}
124+
114125
/**
115126
* Sets a generator that provides labels for the checked ({@code true}) and unchecked
116127
* ({@code false}) states. The generator is called with the state value and its result is used

0 commit comments

Comments
 (0)