Skip to content

Commit

Permalink
feat(tree): added selection via ctrl and shift (#UIM-197)
Browse files Browse the repository at this point in the history
* feat(tree): added selection via ctrl and shift (#197)

* Revert: feat(tree): added selection via ctrl and shift (#197)

* linter fix

* attributes logic is changed

* attributes logic is changed

* shift logic changes

* review changes

* review fixes

* review fixes

* rewrited some moments
  • Loading branch information
roll314 authored and lskramarov committed Oct 25, 2019
1 parent cfa8ad3 commit d5ba275
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/mosaic-dev/tree/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class DemoComponent {

filterValue: string = '';

modelValue: any = 'Chrome';
modelValue: any = ['Chrome'];
// modelValue: any[] = ['rootNode_1', 'Documents', 'Calendar', 'Chrome'];

disableState: boolean = false;
Expand Down
1 change: 1 addition & 0 deletions packages/mosaic-dev/tree/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<!--no-unselect="false"-->
<!-- multiple-->
<mc-tree-selection
multiple="keyboard"
[disabled]="disableState"
[(ngModel)]="modelValue"
[dataSource]="dataSource"
Expand Down
2 changes: 1 addition & 1 deletion packages/mosaic/tree-select/tree-select.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ class BasicSelectOnPushPreselected {
template: `
<mc-form-field>
<mc-tree-select
[multiple]="true"
multiple
placeholder="Food"
[formControl]="control">
Expand Down
8 changes: 2 additions & 6 deletions packages/mosaic/tree-select/tree-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import {
} from '@ptsecurity/mosaic/core';
import { McFormField, McFormFieldControl } from '@ptsecurity/mosaic/form-field';
import { McTag } from '@ptsecurity/mosaic/tags';
import { McTreeSelection, McTreeOption } from '@ptsecurity/mosaic/tree';
import { McTreeSelection, McTreeOption, MultipleMode } from "@ptsecurity/mosaic/tree";
import { defer, merge, Observable, Subject } from 'rxjs';
import {
filter,
Expand Down Expand Up @@ -428,10 +428,6 @@ export class McTreeSelect extends McTreeSelectMixinBase implements
}

ngOnInit() {
if (this.tree) {
this.tree.multiple = this.multiple;
}

this.stateChanges.next();

// We need `distinctUntilChanged` here, because some browsers will
Expand Down Expand Up @@ -462,7 +458,7 @@ export class McTreeSelect extends McTreeSelectMixinBase implements

this.options = this.tree.renderedOptions;
this.tree.autoSelect = this.autoSelect;
this.tree.multiple = this.multiple;
this.tree.multipleMode = this.multiple ? MultipleMode.CHECKBOX : null;

if (this.multiple) {
this.tree.noUnselectLast = false;
Expand Down
8 changes: 6 additions & 2 deletions packages/mosaic/tree/tree-option.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export class McTreeOption extends CdkTreeNode<McTreeOption> implements OnInit, O

private _disabled: boolean = false;

get showCheckbox(): boolean {
return this.tree.showCheckbox;
}

@Output() readonly onSelectionChange = new EventEmitter<McTreeOptionChange>();

get selected(): boolean {
Expand Down Expand Up @@ -141,9 +145,9 @@ export class McTreeOption extends CdkTreeNode<McTreeOption> implements OnInit, O
this._selected = selected;

if (selected) {
this.tree.selectionModel.select(this.value);
this.tree.selectionModel.select(this.data);
} else {
this.tree.selectionModel.deselect(this.value);
this.tree.selectionModel.deselect(this.data);
}

this.changeDetectorRef.markForCheck();
Expand Down
4 changes: 2 additions & 2 deletions packages/mosaic/tree/tree-option.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<ng-content select="[mc-icon]"></ng-content>

<mc-pseudo-checkbox
*ngIf="multiple"
*ngIf="showCheckbox"
[state]="selected ? 'checked' : ''"
[disabled]="disabled">
</mc-pseudo-checkbox>

<span class="mc-option-text"><ng-content></ng-content></span>
<span class="mc-option-text mc-no-select"><ng-content></ng-content></span>

<div class="mc-option-overlay"></div>
Loading

0 comments on commit d5ba275

Please sign in to comment.