valor-software / ngx-bootstrap

Fast and reliable Bootstrap widgets in Angular (supports Ivy engine)
https://valor-software.com/ngx-bootstrap
MIT License
5.53k stars 1.69k forks source link

datepicker component ignores custom configuration if isOpen property set to "true" #5035

Closed treeskar closed 4 years ago

treeskar commented 5 years ago

Bug description or feature request:

bsDatepicker component ignores bsConfig if isOpen is true

<input  bsDatepicker [bsConfig]="bsConfig" [isOpen]=“true”>

If I close and open datepicker the configuration applied correctly.

Plunker/StackBlitz that reproduces the issue:

https://stackblitz.com/edit/angular-c1pmag

Versions of ngx-bootstrap, Angular, and Bootstrap:

ngx-bootstrap: 3.2.0

Angular: 7.2.2

Bootstrap: 4.2.1

Build system: Angular CLI

treeskar commented 5 years ago

Hi @ludmilanesvitiy, The problem is, that isOpen setter calls to show method instantly without waiting to custom configuration or other inputs to come.

  set isOpen(value: boolean) {
    if (value) {
      this.show();
    } else {
      this.hide();
    }
  }

https://github.com/valor-software/ngx-bootstrap/blob/v3.2.0/src/datepicker/bs-daterangepicker.component.ts#L53

BTW if "bsConfig" input would change when "datepicker" is open, this change wouldn't affect to component at all.

I recommend from isOpen setter emit event only, then create a stream, that will aggregate all necessary data, will deal with all dependencies and call show/hide method with right timing and when it needed. For example first time has to be after component's view initiated and all inputs got their values.

  set isOpen(value: boolean) {
    this._isOpen$.next(value)
  }

If you are welcome contribution, I'd like create a pull request with fix that I described. Thanks.

ludmilanesvitiy commented 5 years ago

@treeskar If you could create PR with a fix, it'll be super awesome. Thank you!