Skip to content

Commit

Permalink
Merge pull request #2704 from HenrikJannsen/Avoid-that-textfields-get…
Browse files Browse the repository at this point in the history
…-selected-at-screen-change

Process onInputTextFieldFocus only if editable
  • Loading branch information
HenrikJannsen authored Aug 27, 2024
2 parents 140c9ae + 85bdad0 commit ab9f551
Showing 1 changed file with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ public MaterialTextField(@Nullable String description, @Nullable String prompt,
this(description, prompt, help, null);
}

public MaterialTextField(@Nullable String description, @Nullable String prompt, @Nullable String help, @Nullable String value) {
public MaterialTextField(@Nullable String description,
@Nullable String prompt,
@Nullable String help,
@Nullable String value) {
bg.getStyleClass().add("material-text-field-bg");

line.setPrefHeight(1);
Expand Down Expand Up @@ -400,23 +403,25 @@ protected void onMouseExited() {
}

protected void onInputTextFieldFocus(boolean focus) {
if (focus && textInputControl.isEditable()) {
resetValidation();
selectionLine.setPrefWidth(0);
selectionLine.setOpacity(1);
Transitions.animateWidth(selectionLine, getWidth());
} else {
Transitions.fadeOut(selectionLine, 200);
stringConverter.ifPresent(stringConverter -> {
try {
setText(stringConverter.toString(stringConverter.fromString(getText())));
} catch (Exception ignore) {
}
});
validate();
if (textInputControl.isEditable()) {
if (focus) {
resetValidation();
selectionLine.setPrefWidth(0);
selectionLine.setOpacity(1);
Transitions.animateWidth(selectionLine, getWidth());
} else {
Transitions.fadeOut(selectionLine, 200);
stringConverter.ifPresent(stringConverter -> {
try {
setText(stringConverter.toString(stringConverter.fromString(getText())));
} catch (Exception ignore) {
}
});
validate();
}
onMouseExited();
update();
}
onMouseExited();
update();
}

protected void onWidthChanged(double width) {
Expand Down

0 comments on commit ab9f551

Please sign in to comment.