MaterialFX icon indicating copy to clipboard operation
MaterialFX copied to clipboard

MFXDatePicker styling isn't working

Open Laritello opened this issue 4 years ago • 4 comments

Hi! I'm trying to change default colors of controls to suit my app's color scheme. But when I tried to do the same for DatePicker I've found out that some colors aren't changing. Specifically the name of the month and year when focused. image

Here's my CSS:

.mfx-date-picker .date-picker-popup .years-combo:focused,
.mfx-date-picker .date-picker-popup .months-combo:focused {
    -fx-text-fill: red;
}

However, if I use:

#custom-date-picker .date-picker-popup .years-combo:focused,
#custom-date-picker .date-picker-popup .months-combo:focused{
    -fx-text-fill: red;
}

And then set id for my DatePicker - everything works. image

Here's reproductable example: Main.java

import io.github.palexdev.materialfx.controls.MFXDatePicker;
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

import java.util.Objects;

public class Main extends Application {
    @Override
    public void start(Stage stage) {
        HBox content = new HBox(100);
        content.getStylesheets().add(Objects.requireNonNull(getClass().getResource("main.css")).toExternalForm());

        MFXDatePicker date = new MFXDatePicker();

        MFXDatePicker dateCustom = new MFXDatePicker();
        dateCustom.setId("custom-date-picker");

        content.getChildren().addAll(date, dateCustom);
        Parent root = new Pane(content);
        Scene scene = new Scene(root);

        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

main.css

.mfx-date-picker .date-picker-popup .years-combo:focused,
.mfx-date-picker .date-picker-popup .months-combo:focused {
    -fx-text-fill: red;
}

#custom-date-picker .date-picker-popup .years-combo:focused,
#custom-date-picker .date-picker-popup .months-combo:focused{
    -fx-text-fill: red;
}

image image

I'm using:

  • Windows 10
  • JDK 17
  • MaterialFX 11.13.0

I'm not sure if it's a bug or I am doing something wrong here, but the fact that the same path works using Id instead of class seems odd to me. P.S. Some other properties also weren't changing. For example, ripple color of left-arrow and right-arrow.

Laritello avatar Feb 03 '22 21:02 Laritello

Thanks for sharing a minimal reproducible example, I'll look into it as soon as possible and let you know the cause of the issue

palexdev avatar Feb 03 '22 22:02 palexdev

@Laritello I can confirm the issue. An improvement is available on the staging branch.

The issue is that for some reason the ":focused" PseudoClass is ignored, yet I don't know why it works by setting the id. Another workaround until the new minor version is out (couple days I think) is to change the CSS like this:

.mfx-date-picker .date-picker-popup .years-combo .text-field:focused,
.mfx-date-picker .date-picker-popup .months-combo .text-field:focused {
    -fx-text-fill: red;
}

Just for "completion" the new minor version will allow to do this instead:

.mfx-date-picker .date-picker-popup .years-combo:focus-within,
.mfx-date-picker .date-picker-popup .months-combo:focus-within {
    -fx-text-fill: red;
}

palexdev avatar Feb 04 '22 13:02 palexdev

Great! Thanks for quick response :)

Laritello avatar Feb 04 '22 13:02 Laritello

Fix available in the latest version

palexdev avatar Feb 09 '22 13:02 palexdev