Hide values from the Angular Material multiple drop down list - angular-material

How can I hide the values in the drop down box. What I want to achieve is just a placeholder without showing the values selected from multiple. I should keep this ngmodel and selectionChange for other purposes.
Is there any way?
<mat-form-field>
<mat-select
placeholder="Select Columns"
(selectionChange)="columnSelect()"
multiple
[(ngModel)]="selectedColumns"
>
<mat-option
*ngFor="let c of fixedColumns"
[value]="c"
>
{{ c }}
</mat-option>
</mat-select>
</mat-form-field>

I solved the problem by adding mat-select-trigger;
<mat-select
(selectionChange)="columnSelect()"
multiple
[(ngModel)]="selectedColumns"
>
<mat-select-trigger class="trigger">
Select Columns
</mat-select-trigger>
<mat-option
*ngFor="let c of fixedColumns"
[value]="c"
>
{{ c }}
</mat-option>
</mat-select>
``

Related

Change event not being invoked in material ui select component

I have to run some code when country is selected in the dropdown but the method is not called at all. Here is the material code:
<mat-form-field>
<mat-label>Select country</mat-label>
<mat-select (change)="countrySelected(value)">
<mat-option>None</mat-option>
<mat-option value="option1">France</mat-option>
<mat-option value="option2">Germany</mat-option>
<mat-option value="option3">America</mat-option>
</mat-select>
</mat-form-field>
Here is the method that is not being called:
countrySelected(value): void {
console.log(value);
}
You should be using the event selectionChange instead. So change your code as follows:
<mat-form-field>
<mat-label>Select country</mat-label>
<mat-select (change)="selectionChange(value)">
<mat-option>None</mat-option>
<mat-option value="option1">France</mat-option>
<mat-option value="option2">Germany</mat-option>
<mat-option value="option3">America</mat-option>
</mat-select>
</mat-form-field>
Checkout https://material.angular.io/components/select/api for all supported events.

How to change the direction of a dropdown in a mat select?

I'm using a mat select to display a list of items.
<mat-label>{{ 'CLAIMS.PLACEHOLDERS.STATUS' | translate }}</mat-label>
<mat-select (valueChange)="onStatusChange($event)">
<mat-option *ngFor="let option of statusses" [value]="option">
{{ 'STATUS.' + option | translate }}
</mat-option>
</mat-select>
When selecting certain options my dropdown is "stuck" in my navbar:
Is there any way to change the "direction" of the dropdown? So it does down instead of up?
I was able to force my dropdown to open downwards by adding the disableOptionCentering option.
<mat-label>{{ 'CLAIMS.PLACEHOLDERS.CLAIMTYPE' | translate }}</mat-label>
<mat-select (valueChange)="onClaimTypeChange($event)" disableOptionCentering>
<mat-option *ngFor="let option of claimTypes" [value]="option">
{{ option }}
</mat-option>
</mat-select>

Show extra values in mat option when panel is open

<mat-select >
<mat-option *ngFor="let i of List" [value]="i.value">
{{i.viewValue}}<span *ngIf="panelOpen">{{i.viewValue2}}</span>
</mat-option>
</mat-select>
I would like to show additional values in mat option row and hide that additional value after selection. Is There any possibility using panelOpen, Thanks in advance.
If you declare the mat-select as a variable using the # notation, you can then change your ngIf to mySelect.panelOpen where mySelect is the ID you gave the mat-select:
<mat-select #mySelect>
<mat-option *ngFor="let i of List" [value]="i.value">
{{i.viewValue}}
<span *ngIf="mySelect.panelOpen">{{i.viewValue2}}</span>
</mat-option>
</mat-select>
Here's a StackBlitz.

Angular Material Orphaned form label on mat-select

I am running into an issue when testing for accessibility problems on an Angular 8 Material app. I am using the Chrome Plugin WAVE Evaluation Tool to check for accessibility https://chrome.google.com/webstore/detail/wave-evaluation-tool/jbbplnpkjmmeebjpijfedlgcdilocofh.
The problem looks to be only with a Mat Select list.
-- Error
image of Mat list with Orphaned Form Lable
WAVE tool Errors
-- Code ( this is what I started with )
<mat-form-field>
<mat-select>
<mat-option *ngFor="let tag of tags" [value]="tags.value">
{{ tag.viewValue }}
</mat-option>
</mat-select>
<mat-label>Resource Tag</mat-label>
</mat-form-field>
-- Code (then after reading that it was missing the form label I changed it to this)
<mat-form-field>
<mat-select id="tags">
<mat-option *ngFor="let tag of tags" [value]="tags.value">
{{ tag.viewValue }}
</mat-option>
</mat-select>
<mat-label for="tags">Resource Tag</mat-label>
</mat-form-field>
Even after that change, the Orphaned Form Lable is still there.
I also removed all Material elements and just created a default select list using HTML elements that worked and did NOT have a missing form label. From this my guess its something going on in the Material elements.

MatChipList tab navigation

I have a mat-form-field that contains a chip list and another one that contains any other kind of input. I want to be able to navigate away from the chip list into the input field and into the following mat-form-fields but it seems like this behaviour is not supported. Does anyone have a work around for this to be able to navigate this components with tab?
<mat-form-field class="example-chip-list">
<mat-chip-list #chipList>
<mat-chip *ngFor="let fruit of fruits" [selectable]="selectable"
[removable]="removable" (removed)="remove(fruit)">
{{fruit.name}}
<mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
</mat-chip>
<input placeholder="New fruit..."
[matChipInputFor]="chipList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
[matChipInputAddOnBlur]="addOnBlur"
(matChipInputTokenEnd)="add($event)">
</mat-chip-list>
</mat-form-field>
<mat-form-field>
<input placeholder="Another unrelated field" matInput>
</mat-form-field>
example: https://stackblitz.com/edit/angular-ixswwc?file=app/chips-input-example.html
The infinite loop of focus happens because the <input> is inside of the <mat-chip-list>
It could be solved by doing the following
<mat-form-field class="example-chip-list">
<mat-chip-list #chipList>
<mat-chip *ngFor="let fruit of fruits" [selectable]="selectable"
[removable]="removable" (removed)="remove(fruit)">
{{fruit.name}}
<mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
</mat-chip>
</mat-chip-list>
<input placeholder="New fruit..."
[matChipInputFor]="chipList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
[matChipInputAddOnBlur]="addOnBlur"
(matChipInputTokenEnd)="add($event)">
</mat-form-field>
<mat-form-field>
<input placeholder="Another unrelated field" matInput>
</mat-form-field>

Resources