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

Hint/Placeholder is blank when select allows empty selection #7243

Closed
sergetania opened this issue Mar 19, 2024 · 3 comments · Fixed by #7303
Closed

Hint/Placeholder is blank when select allows empty selection #7243

sergetania opened this issue Mar 19, 2024 · 3 comments · Fixed by #7303
Assignees
Labels
bug Something isn't working regression Sometimes we make things break vaadin-select

Comments

@sergetania
Copy link

Description

This has worked in Vaadin 14. Switching to V23, we have noticed this issue..
I create a select component, set a placeholder and allow empty selection. Vaadin blanks the set placeholder if a select allows empty selection. @javier-godoy suggested to set an empty selection caption which is displayed in place of placeholder when nothing is selected. However, it creates a weird UI experience when a "placeholder" becomes a selectable option. The example in Vaadin docs has a select(works because it does not allow empty selection) with "Select Size" placeholder and options "XS", "S",... So with the suggested workaround the user will see the following options in the dropdown list: "Select Size", "XS", "S"... Sorry, it is weird.

Expected outcome

Vaadin not blanking out the placeholder if no empty selection caption is set.

Minimal reproducible example

	Select typeSelect = new Select();
	typeSelect.setPlaceholder( "Filter By Type" );
	typeSelect.setEmptySelectionAllowed( true );
	String[] types = { "One", "Two" };
	typeSelect.setItems( types );

Steps to reproduce

Create a select component using the above code. The combo will not display the set placeholder.

Environment

Vaadin version(s): 23.3.31 - 23.4.0
OS: Windows

Browsers

Chrome

@yuriy-fix yuriy-fix added DX Developer experience issue vaadin-select needs design Design is needed UX User experience issue and removed DX Developer experience issue labels Mar 21, 2024
@sergetania
Copy link
Author

sergetania commented Mar 22, 2024

Sorry, I find it puzzling that this issue needs a design decision. To me, this seems like a very simple issue.

What is the placeholder? It is what is displayed when the field is empty. When is the combo field empty? When nothing is selected and the empty selection caption is not specified (because if it is specified then the field is not empty).

And that is how this used to work in V14. There was no conflict

@web-padawan
Copy link
Member

The reason why this was working in V14 is that <vaadin-select> was using <vaadin-text-field> internally and that has native <input> with placeholder property. As for empty selection, the logic for updating value slot didn't insert the item when it doesn't have content (which is the case when empty selection is allowed).

In Vaadin 22 and later, the placeholder is also implemented by using cloned vaadin-select-item and placing it in value slot. Therefore, empty selection item overrides the one that the web component uses for placeholder. In order to show the placeholder when the selected item is empty, we need to update the corresponding block:

if (!selected) {
if (this.placeholder) {
const item = this.__createItemElement({ label: this.placeholder });
this.__appendValueItemElement(item, valueButton);
valueButton.setAttribute('placeholder', '');
}
} else {

@rolfsmeds
Copy link
Contributor

Yup, makes sense.

As for why this needed a design decision, we wanted to check if there was something fundamentally wrong with the field supporting both placeholder and empty-selection-caption, and if that was something we'd need to look into.

But I do think they serve to distinct use cases:

  • A placeholder prompts the user to select something
  • An empty-selection-caption is for when "none of the above" is a valid selection, which should clearly not be shown as a placeholder, and would be a lot of extra work to include in the dataset bound to the field.

So, let's go ahead and fix this.

@rolfsmeds rolfsmeds added regression Sometimes we make things break bug Something isn't working and removed needs design Design is needed UX User experience issue labels Apr 4, 2024
@web-padawan web-padawan assigned web-padawan and unassigned rolfsmeds Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regression Sometimes we make things break vaadin-select
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants