Skip to content

Commit

Permalink
fix(tree-selection): if ngModel change View will have previous value (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lskramarov authored and pimenovoleg committed Jul 23, 2019
1 parent 49dca88 commit 33ad81b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/mosaic-dev/tree/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { FlatTreeControl, NestedTreeControl } from '@ptsecurity/cdk/tree';
import { McButtonModule } from '@ptsecurity/mosaic/button';
import { McIconModule } from '@ptsecurity/mosaic/icon';
import {
McTreeFlatDataSource,
Expand Down Expand Up @@ -191,6 +192,7 @@ export class DemoComponent {
imports: [
BrowserModule,
FormsModule,
McButtonModule,
McTreeModule,
McIconModule
],
Expand Down
6 changes: 6 additions & 0 deletions packages/mosaic-dev/tree/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
</style>
<h5>multiple selection</h5>

<button class="mc-primary" mc-button (click)="modelValue = 'Applications'">set modelValue = Applications</button>

<br><br><br>

<div>ngModel: {{ modelValue }}</div>

<br><br><br>

<!--auto-select="true"-->
<!--no-unselect="false"-->
<!-- multiple-->
Expand Down
6 changes: 5 additions & 1 deletion packages/mosaic/tree/tree-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export class McTreeSelection extends McTreeSelectionBaseMixin<McTreeOption>
.subscribe((options) => {
options.forEach((option) => {
this.selectionModel.selected.forEach((selectedOption) => {
if (option.value === selectedOption) { option._selected = true; }
option._selected = option.value === selectedOption;
});
});
});
Expand Down Expand Up @@ -398,13 +398,17 @@ export class McTreeSelection extends McTreeSelectionBaseMixin<McTreeOption>
}

private setOptionsFromValues(values: any[]): void {
this.selectionModel.clear();

values.forEach((value) => {
const correspondingOption = this.getCorrespondOption(value);

this.selectionModel.select(value);

if (correspondingOption) { correspondingOption.selected = true; }
});

this.options.notifyOnChanges();
}

private canDeselectLast(option: McTreeOption): boolean {
Expand Down

0 comments on commit 33ad81b

Please sign in to comment.