-
Notifications
You must be signed in to change notification settings - Fork 5
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
Zhylka/legacy chips rewriting #2655
Conversation
@@ -60,7 +60,7 @@ | |||
>{{ 'FORMS.PLACEHOLDERS.KEYWORDS_START' | translate }} {{ validationConstants.MAX_KEYWORDS_LENGTH }} | |||
{{ 'FORMS.PLACEHOLDERS.KEYWORDS_END' | translate }}</span | |||
> | |||
<mat-chip-list #chipList> | |||
<mat-chip-grid #chipGrid> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to use mat-chip-grid together with the input to follow the correct interaction pattern
@@ -34,8 +34,9 @@ export class ChildFormComponent implements OnInit, OnDestroy { | |||
|
|||
@ViewChild('select') | |||
private select: MatSelect; | |||
@ViewChild('chipList') | |||
private chipList: MatChipList; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove empty row
I am not sure if ngModel needs to be set on mat-chip-grid (as shown in the docs), because we use reactive forms. So, I removed ngModel from the input and fixed the issue where the input remained disabled after adding 5 elements and then removing one. |
<input | ||
[ngClass]="{ 'keywords-input': !keyWord && keyWords.length < 1 }" | ||
[ngClass]="{ 'keywords-input': !keyWordsCtrl.value && keyWords$.value.length < 1 }" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove extra whitespace after {
and before }
public keyWord: string; | ||
|
||
public disabilityOptionRadioBtn: FormControl = new FormControl(false); | ||
public disabledKeyWordsInput = false; | ||
|
||
public separatorKeysCodes = [13, 188]; // Enter and Comma |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import keycodes from @angular/cdk/keycodes
@@ -74,18 +75,29 @@ export class CreateDescriptionFormComponent implements OnInit, OnDestroy { | |||
|
|||
this.passDescriptionFormGroup.emit(this.DescriptionFormGroup); | |||
this.keyWordsListener(); | |||
|
|||
this.keyWords$.pipe(takeUntil(this.destroy$)).subscribe((keyWords) => { | |||
this.disabledKeyWordsInput = keyWords.length >= 5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create a private read-only property for max keywords instead of a magic number
@@ -40,12 +40,13 @@ export class CreateDescriptionFormComponent implements OnInit, OnDestroy { | |||
public SectionItemsFormArray = new FormArray([]); | |||
public keyWordsCtrl: FormControl = new FormControl('', Validators.required); | |||
|
|||
public keyWords: string[] = []; | |||
public keyWords$: BehaviorSubject<string[]> = new BehaviorSubject<string[]>([]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a subject in this case?
We can simply do checks inside the method or create a separate method to switch the input state
if (this.keyWords.length) { | ||
this.DescriptionFormGroup.get('keyWords').setValue([...this.keyWords]); | ||
const keyWords = this.keyWords$.value; | ||
const index = keyWords.indexOf(word); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keyWords.includes()
Quality Gate passedIssues Measures |
* Liuboff/Replacing legacy snack bar * Liuboff/Replacing legacy snack bar * Zhylka/legacy chips rewriting (#2655) * chip-list replaced by chip-set/chip-listbox * all chip-lists replaced by chip-set * replaced list-set by list-grid in create-description-form for passing tests * added test for removing chips when changing language * removed ngModel and fixed input behavior after adding 5 elements * removed behavior subject, added function to change keyword input state, fixed remarks * changed cdk version * changed based on PR recommendations * Liuboff/Replacing legacy snack bar * changed based on PR recommendations * fix tests according PR recomendations * Replace > to previous line * fix tests according PR recomendations * Replace > to previous line --------- Co-authored-by: Liubov Zatsepina <liubov_zatsepina@epam.com> Co-authored-by: MaxZhylka <132847452+MaxZhylka@users.noreply.github.com>
Replaced MatLegacyChipModule, replaced all chip-lists by chip-set. In the CreateDescriptionForm component, specifically updated mat-chip-list to mat-chip-grid to resolve test failures