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: Custom option shows only after reselected with reactive forms #1228

Open
1 task done
gabrieledaugenaite opened this issue Feb 26, 2024 · 3 comments
Open
1 task done
Labels
Comp: Dropdown Type: Bug Something isn't working

Comments

@gabrieledaugenaite
Copy link
Contributor

gabrieledaugenaite commented Feb 26, 2024

Custom option/button templates for dropdown show up only after value is reselected with reactive forms

Bug already reported?

  • I confirm that I have checked if the bug already has been reported

For which framework/library you are reporting the bug

Angular

Component name

dropdown

Description

There seems to be issues to display custom option/button templates when using reactive form control. Dropdown options structure can be as simple as an array of objects with label and value, however the actual templates won't be displayed until value is selected/reselected. You can see both cases below

When initial value is not provided (before making a selection) - custom option template is not visible

image

When initial value is not provided (after making a selection) - custom option template becomes visible

image

When initial value is provided (before reselecting value) - custom button (selected value) template is not visible

image

When initial value is provided (after reselecting value) - custom button (selected value) template becomes not visible

image

Steps To Reproduce

No response

Current Behaviour

When custom option/button template is provided while using a reactive form approach, the default option is being shown initially and custom option/button template becomes visible after selecting/reselecting dropdown value

Expected Behaviour

Custom option/button template should be shown from the start if provided while using a reactive form approach

@gabrieledaugenaite gabrieledaugenaite added the Type: Bug Something isn't working label Feb 26, 2024
@splashdust
Copy link
Contributor

@gabrieledaugenaite A similar issue was fixed recently, in 3.1.0.
It could be something else in your case, but I just want to confirm that you are experiencing the issue on the latest released version?

@gabrieledaugenaite
Copy link
Contributor Author

@splashdust yes, the screenshots above are from running angular storybook locally with latest code.

below are the changes I've done for FormControlWithResetTemplate in dropdown.stories.ts file in angular lib to reproduce the issue

const options$ = of([
    {
      label: 'Sweden',
      value: 'sweden'
    },
    {
      label: 'Australia',
      value: 'australia'
    },
  ])
<ng-template nggDropdownButton let-option="option">
  <div>
    <div>{{ option.label }} (selected)</div>
  </div>
</ng-template>
<ng-template nggDropdownOption let-option="option" let-index="index">
  <div>
    <div>{{ index }}. {{ option.label } </div>
  </div>
</ng-template>

though now I noticed that keeping pipe(delay(3000)) (or even pipe(delay(0))) removes the issue completely. but is it an expected behavior?

@splashdust
Copy link
Contributor

I see! No, I don't think that is an expected behavior. Definitely sounds like a bug!
Probably some kind of Angular change detection quirk.

@EldRoos EldRoos changed the title Custom option/button templates for dropdown show up only after value is reselected with reactive forms Dropdown: Custom option/button templates for dropdown show up only after value is reselected with reactive forms Mar 17, 2024
@EldRoos EldRoos changed the title Dropdown: Custom option/button templates for dropdown show up only after value is reselected with reactive forms Dropdown: Custom option shows only after reselected with reactive forms Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Comp: Dropdown Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants