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

Dropdown head is empty if no value is provided #14954

Closed
gpobr opened this issue Mar 6, 2024 · 7 comments · Fixed by #15383 · May be fixed by Rodolphe33/gestion-personnel#2 or diaz-rigo/austins#4
Closed

Dropdown head is empty if no value is provided #14954

gpobr opened this issue Mar 6, 2024 · 7 comments · Fixed by #15383 · May be fixed by Rodolphe33/gestion-personnel#2 or diaz-rigo/austins#4
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@gpobr
Copy link

gpobr commented Mar 6, 2024

Describe the bug

Dropdown that defines a custom selectedItem template, is empty when no initial value or a placeholder is provided.

image

Environment

Windows

Reproducer

https://stackblitz.com/edit/yczs8n-mr98fr?file=src%2Fapp%2Fdemo%2Fdropdown-template-demo.html

Angular version

17.1.2

PrimeNG version

17.9.0

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

20.9.0

Browser(s)

No response

Steps to reproduce the behavior

  1. Define a dropdown
  2. Do not provide placeholder value
  3. Do not provide initial value

Expected behavior

The dropdown should be the same size as dropdowns with value.

@gpobr gpobr added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Mar 6, 2024
@gpobr gpobr changed the title Dropdown head is empty if no placeholder value is provided Dropdown head is empty if no value is provided Mar 6, 2024
@dalenguyen
Copy link
Contributor

How about adding a placeholder for it?

  <p-dropdown
    [options]="countries"
    [(ngModel)]="selectedCountry"
    optionLabel="name"
    placeholder="Select a Country"
    [showClear]="true"
  >

@gpobr
Copy link
Author

gpobr commented Mar 12, 2024

How about adding a placeholder for it?

  <p-dropdown
    [options]="countries"
    [(ngModel)]="selectedCountry"
    optionLabel="name"
    placeholder="Select a Country"
    [showClear]="true"
  >

Hi @dalenguyen, that would be an obvious solution. The thing is that a placeholder is redundant for dropdowns that use a float-label.

If no placeholder value is provided, then the expected behavior would be to display something like an empty character.
Placeholder should not be a prerequisite.

I have updated the Reproducer code to show the case with float-label.

@dimd13
Copy link

dimd13 commented Mar 12, 2024

Hello, i have the same problem! I don't need the placeholder, it's just an optional attribute, but if selected item is null field is shrinking

primeng 17.10.0
angular 17.0.2

https://stackblitz.com/edit/d2r6ts?file=src%2Fapp%2Fdemo%2Fdropdown-template-demo.html

@dalenguyen
Copy link
Contributor

Temporary solution: I think you can try to use global css to fix it:

p-dropdown > div {
    min-height: 40px;
    min-width: 200px;
}

@gpobr
Copy link
Author

gpobr commented Mar 12, 2024

Thanks for your response @dalenguyen

I would avoid setting a static height value because the element's height is dynamically calculated as the sum of font-size+padding. Width is always set to 100% of the container element's box size.

What I'm doing, for now, is setting the placeholder value to "_". This will display a dash until an option is selected.
You can also set the placeholder's opacity to 0, under conditions.

I can easily apply this system-wide because all p-dropdown elements are implemented via a wrapper component.

@dalenguyen
Copy link
Contributor

It's not static. It has a minimum value set min- though. Your solution also works 😄

@gpobr
Copy link
Author

gpobr commented Mar 12, 2024

Yes, you're right, it's not completely static. I want to avoid adding a value based on visual/manual estimation 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
5 participants