Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select Component Renderer not showing selected item #7497

Closed
funfried opened this issue Jun 21, 2024 · 3 comments · Fixed by #7504
Closed

Select Component Renderer not showing selected item #7497

funfried opened this issue Jun 21, 2024 · 3 comments · Fixed by #7504
Labels
BFP Bug fix prioritised by a customer bug Something isn't working Impact: Low regression Sometimes we make things break Severity: Major workaround There is a workaround in the comments.

Comments

@funfried
Copy link

Describe the bug

Since Vaadin 24.3.x a Flow Select component with a custom renderer seems not to show its selected value anymore. I recorded a video in version 24.2.12 (see expected-behavior) where everything works fine and another one showing the current version (24.4.3) where it's not been renderered anymore:

Vaadin_24.4.3.mov

Expected-behavior

Here you see the example Vaadin Spring application build with Vaadin 24.2.12 where everything works fine:
https://github.com/vaadin/platform/assets/7093028/9c7c6a84-4c4e-4b14-88d7-86f801c82f1b

Reproduction

You can checkout my forked Vaadin example application within a Select component which shows the behavior, just change the Vaadin version to 24.4.3 in the pom.xml and you'll see the issue when you ran the application:

https://github.com/funfried/vaadin-select-with-custom-renderer-issue

System Info

MacBook Pro M1 Max / 32GB
MacOS 14.5 (Sonoma)

java -version
openjdk version "21" 2023-09-19
OpenJDK Runtime Environment Zulu21.28+85-CA (build 21+35)
OpenJDK 64-Bit Server VM Zulu21.28+85-CA (build 21+35, mixed mode, sharing)

Vaadin 24.4.3

@funfried funfried added the bug Something isn't working label Jun 21, 2024
@TatuLund TatuLund transferred this issue from vaadin/platform Jun 24, 2024
@ssc-css
Copy link

ssc-css commented Jun 24, 2024

I have the same problem with Icons:

iconSelection

Select<String> iconSelectRenderer2 = new Select<>(); iconSelectRenderer2.setRenderer(new ComponentRenderer<>(path -> { Icon test = new Icon(path.toLowerCase(Locale.ENGLISH).replace('_', '-')); return test; })); iconSelectRenderer2.setItems(VaadinIcon.SELECT.name(), VaadinIcon.ANCHOR.name(), VaadinIcon.ADOBE_FLASH.name()); iconSelectRenderer2.setValue(VaadinIcon.SELECT.name());

@yuriy-fix yuriy-fix added the BFP Bug fix prioritised by a customer label Jun 25, 2024
@sissbruecker
Copy link
Contributor

Seems to be a regression from #7303. That change adds a check for whether a select item has "content" and shows the placeholder if that is not the case. Content is identified as either:

  • having a label attribute -> not the case here since it's using a custom renderer
  • having any text content -> not the case here, since the custom renderer only shows an image or icon

The check would need to be changed somehow, probably to accept custom rendered items as having content by default, since we can't really make any assumptions whether a custom rendered item represents an empty value or not.

A workaround would be to add some text content to the rendered items, which could just be an invisible span:

    private ComponentRenderer<? extends Component, ExampleDto> createImageRenderer() {
        return new ComponentRenderer<>(dto -> {
            Div wrapper = new Div();

            // Add image...

            // Add some hidden text
            Span hiddenText = new Span();
            hiddenText.setText("hidden");
            hiddenText.getStyle().set("display", "none");
            wrapper.add(hiddenText);

            return wrapper;
        });
    }

@funfried
Copy link
Author

@sissbruecker

Indeed, with those changes the images are rendered again! Thanks for the workaround!

Cheers,
Fabian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BFP Bug fix prioritised by a customer bug Something isn't working Impact: Low regression Sometimes we make things break Severity: Major workaround There is a workaround in the comments.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants