Skip to content

Commit

Permalink
fix(datepicker): setting initial state of datepicker via bsValue (#6121)
Browse files Browse the repository at this point in the history
* chore: ng11 changed an order of components injection

* chore: build common docs with ivy
  • Loading branch information
valorkin authored May 21, 2021
1 parent 4dbbe08 commit ea62fb9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
Empty file removed Agent
Empty file.
3 changes: 1 addition & 2 deletions libs/common-docs/src/lib/common/add-nav/add-nav.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import { ContentSection } from '../../models/content-section.model';
})
export class AddNavComponent {
@Input() componentContent: ContentSection[];
private document: Document;
// eslint-disable-next-line @typescript-eslint/no-empty-function
constructor(@Inject(DOCUMENT) document: any){ }
constructor(@Inject(DOCUMENT) private document: Document){ }

goToSection(event: Event): void {
const item: HTMLElement = event.target as HTMLElement;
Expand Down
3 changes: 0 additions & 3 deletions libs/common-docs/tsconfig.lib.prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
"extends": "./tsconfig.lib.json",
"compilerOptions": {
"declarationMap": false
},
"angularCompilerOptions": {
"enableIvy": false
}
}
25 changes: 16 additions & 9 deletions src/datepicker/bs-datepicker-input.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,24 @@ export class BsDatepickerInputDirective
private changeDetection: ChangeDetectorRef) {}

ngOnInit() {
const setBsValue = (value: Date) => {
this._setInputValue(value);
if (this._value !== value) {
this._value = value;
this._onChange(value);
this._onTouched();
}
this.changeDetection.markForCheck();
};

// if value set via [bsValue] it will not get into value change
if (this._picker._bsValue) {
setBsValue(this._picker._bsValue);
}

// update input value on datepicker value update
this._subs.add(
this._picker.bsValueChange.subscribe((value: Date) => {
this._setInputValue(value);
if (this._value !== value) {
this._value = value;
this._onChange(value);
this._onTouched();
}
this.changeDetection.markForCheck();
})
this._picker.bsValueChange.subscribe(setBsValue)
);

// update input value on locale change
Expand Down
15 changes: 15 additions & 0 deletions src/datepicker/bs-daterangepicker-input.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ export class BsDaterangepickerInputDirective
}

ngOnInit() {
const setBsValue = (value: (Date|undefined)[]) => {
this._setInputValue(value);
if (this._value !== value) {
this._value = value;
this._onChange(value);
this._onTouched();
}
this.changeDetection.markForCheck();
};

// if value set via [bsValue] it will not get into value change
if (this._picker._bsValue) {
setBsValue(this._picker._bsValue);
}

// update input value on datepicker value update
this._subs.add(
this._picker.bsValueChange.subscribe((value: Date[]) => {
Expand Down

0 comments on commit ea62fb9

Please sign in to comment.