MatChipList tab navigation - angular-material

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>

Related

Angular Material's mat-autocomplete input is not getting disabled as expected

I'm trying to disable an Angular Material Autocomplete component. I would have expected to just be able to set disabled on the input, but that does nothing. (I also tried setting disabled on mat-form-field and mat-autocomplete.) Setting matAutocompleteDisabled on input prevented the options from showing, but still allowed typing in the field. Setting readonly on input prevented typing, but it doesn't change the UI, so seems like that will be confusing for the user. Is this a bug, or am I missing something?
Here's the closest I've come so far, using readonly (and disabled isn't working as expected)
<form class="example-form">
<mat-form-field class="example-full-width">
<input type="text"
disabled readonly
placeholder="Pick one"
aria-label="Number"
matInput
[formControl]="myControl"
[matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let option of options" [value]="option">
{{option}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</form>
You should use formControl to set it, something like:
this.formGroupName.controls['myControl'].disable()
Use [attr.disabled]="true". It will set the disabled to true.
You can do css trick for this purpose.
Apply some class to parent tag of input. In you case upper tag is <mat-form-field class="example-full-width"> so i add disable-block class in this. And applied below css.
.disable-block {
pointer-events: none;
opacity: .7;
}
Full code here.
HTML
<form class="example-form">
<mat-form-field class="example-full-width disable-block">
<input type="text" disabled readonly placeholder="Pick one" aria-label="Number" matInput [formControl]="myControl" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let option of options" [value]="option">
{{option}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</form>
CSS
.disable-block {
pointer-events: none;
opacity: .7;
}
If you want more lighter text field then you can decrease opacity to .6 or .5 or more want you want.
Hope this will solve you problem.

How to implement data-list via mat-select of angular-material?

Here is the code of an original dataList (select which has an option of customed typing):
<input type="text" list="selectCity" placeholder="select city" />
<data-list id="selectCity">
<option [value]="New York" />
<option [value]="London" />
<option [value]="Paris" />
<option [value]="Beijing" />
<option [value]="Montreal" />
</data-list>
I want to create something like this via <mat-select> .
I saw few questions about it, but the answers were something like- "you can make another input that accepts the customed value..",
but in my app I want to help the user to get the city easily among a very long list of cities. so that solution cannot help me.
I tried something with <mat-form-field> and <input> but that made some problems...
Can you give me any effective solution for this?
<mat-form-field appearance="fill">
<mat-label>select city</mat-label>
<mat-select>
<mat-option value="option">New York</mat-option>
<mat-option value="option">London</mat-option>
<mat-option value="option">Paris</mat-option>
</mat-select>
</mat-form-field>
In this example, you can type a letter, and reach to the first option that starts with that letter.
It will be helpful in case the options are sorted in alphabetical order.
Else, see here: https://material.angular.io/components/autocomplete/examples

Select in the menu

I would like to create a mat-select controls in mat-menu. In the documentation I don't see any examples with that scenario. I tried it out, and it seems to be working, the problem is when options are expanded, the menu disposes. How can I keep it open? Here is the tester I am working with
You need to stop event propagation ($event.stopPropagation()) on the menu item. Here's an example of how this can be done;
<div mat-menu-item [disableRipple]="true" (click)="$event.stopPropagation()">
<mat-form-field>
<mat-label>Some label</mat-label>
<mat-select [formControl]="someFormControl">
<mat-option *ngFor="let item of someList" [value]="item.value">{{item.description}}</mat-option>
</mat-select>
<button type="button" mat-button matSuffix mat-icon-button (click)="someFormControl.setValue(null); $event.stopPropagation();" title="Clear">
<mat-icon>close</mat-icon>
</button>
</mat-form-field>
</div>
Also you probably want to disable ripple ([disableRipple]="true") so you do not get the ripple visual feedback that menu items normally have.

material datepicker icon configuration

I need to change material date picker icon and also I want date toggle to happen on clicking input box .Current behaviour is on clicking existing datepicker icon the date will be toggled.
<mat-form-field appearance="outline">
<input matInput #startInput [matDatepicker]="startPicker" placeholder="mm/dd/yyyy"
(dateInput)="startDateChangeEvent('input', $event)" (dateChange)="startDateChangeEvent('change', $event)">
<mat-hint style="color:red">{{startDateErrorMsg}}</mat-hint>
<mat-datepicker-toggle matSuffix [for]="startPicker"></mat-datepicker-toggle>
<mat-datepicker #startPicker></mat-datepicker>
</mat-form-field>
To change material date picker icon you can add mat-icon instead of mat-datepicker-toggle and for toggle to happen on clicking input box you have to (click)="startPicker.open()" in input like given below:
<mat-form-field appearance="outline">
<input matInput #startInput [matDatepicker]="startPicker" placeholder="mm/dd/yyyy"
(click)="startPicker.open()"
(dateInput)="startDateChangeEvent('input', $event)" (dateChange)="startDateChangeEvent('change', $event)">
<mat-hint style="color:red">{{startDateErrorMsg}}</mat-hint>
<span matSuffix>
<mat-icon>home</mat-icon>
</span>
<mat-datepicker #startPicker></mat-datepicker>
</mat-form-field>

Angular app on IOS doesn't show me keyboard, when i click on input. Why?

My Angular application doesn't show me keyboard, when i click on input for the first time. Second click and other shows it.
I don't have ngTouch and any function on inputs.
<div class="input-wrapper">
<input type="email" name="login" tabindex="1" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" ng-model="form.userData.login" placeholder="{{'LOGIN_OR_EMAIL' | translate}}" required>
</div>
Nothing special in html
if you have
-webkit-user-select:none;
user-select:none;
in your css remove them.

Resources