vaadin/flow-components

Checkbox helper component cleared but not showing helper text

krissvaa opened this issue · 3 comments

Description

Setting checkbox.setHelperText(null) before setting checkbox.setHelperComponent(...) results on next setHelperText() not to show anything.

Expected outcome

Expected to show helperText always if helperComponent is not present

Minimal reproducible example

Checkbox someCheckbox = new Checkbox("Some Checkbox");
someCheckbox.addValueChangeListener(event -> {
  if (event.getValue()) {
      someCheckbox.setHelperComponent(null);
      someCheckbox.setHelperText("This really helps!");
  } else {
      someCheckbox.setHelperText(null);
      someCheckbox.setHelperComponent(VaadinIcon.HEART_O.create());
  }
 });

Steps to reproduce

  1. Add the snippet to a view
  2. Click the checkbox three times
  3. After the third click the helperText is missing

Environment

Vaadin version(s): 24.4.0.beta5
OS: Windows

Browsers

Firefox

Let's check if this only affects checkbox or also other fields.

Aren't the null calls supposed to be redundant? Setting a text will remove the component and vice versa so that you don't need to clear one when setting the other.

Confirmed the issue also with TextField (and presumably other components that implement HasHelper too):

TextField textField = new TextField();
textField.addValueChangeListener(event -> {
        if (event.getValue().length() > 0) {
                textField.setHelperComponent(null);
                textField.setHelperText("This is a text!");
        } else {
                textField.setHelperText(null);
                textField.setHelperComponent(new Span("This is a component!"));
        }
});

Looks like removing setHelperText(null) helps. Note, setHelperComponent(null) is needed to work properly because it takes precedence when both methods are used, as specified in the JavaDoc.

I will investigate this further to identify if there is an issue in the web component helper implementation.