Skip to content

Commit b110cdd

Browse files
committed
add troubleshooting section for select
1 parent 8e7a8c6 commit b110cdd

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

src/lib/select/select.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,43 @@ globally cause input errors to show when the input is dirty and invalid.
119119
```
120120

121121
### Keyboard interaction
122+
122123
- <kbd>DOWN_ARROW</kbd>: Focus next option
123124
- <kbd>UP_ARROW</kbd>: Focus previous option
124125
- <kbd>ENTER</kbd> or <kbd>SPACE</kbd>: Select focused item
125126

126127
### Accessibility
128+
127129
The select component without text or label should be given a meaningful label via
128130
`aria-label` or `aria-labelledby`.
129131

130132
The select component has `role="listbox"` and options inside select have `role="option"`.
133+
134+
### Troubleshooting
135+
136+
#### Error: Cannot change `multiple` mode of select after initialization
137+
138+
This error is thrown if you attempt to bind the `multiple` property on `<mat-select>` to a dynamic
139+
value. (e.g. `[multiple]="isMultiple"` where the value of `isMultiple` changes over the course of
140+
the component's lifetime). If you need to change this dynamically, use `ngIf` or `ngSwitch` instead:
141+
142+
```html
143+
<mat-select *ngIf="isMultiple" multiple>
144+
...
145+
</mat-select>
146+
<mat-select *ngIf="!isMultiple">
147+
...
148+
</mat-select>
149+
```
150+
151+
#### Error: Cannot assign truthy non-array value to select in `multiple` mode
152+
153+
This error is thrown if you attempt to assign a value other than `null`, `undefined`, or an array to
154+
a `<mat-select multiple>`. For example, something like `mySelect.value = 'option1'`. What you likely
155+
meant to do was `mySelect.value = ['option1']`.
156+
157+
#### Error: Cannot assign a non-function value to `compareWith`
158+
159+
This error occurs if you attempt to assign something other than a function to the `compareWith`
160+
property. For more information on proper usage of `compareWith` see the
161+
[angular forms documentation](https://angular.io/api/forms/SelectControlValueAccessor#caveat-option-selection)).

src/lib/select/select.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
ScrollStrategy,
1919
ViewportRuler,
2020
} from '@angular/cdk/overlay';
21-
import {filter, first, startWith, takeUntil, RxChain} from '@angular/cdk/rxjs';
21+
import {filter, first, RxChain, startWith, takeUntil} from '@angular/cdk/rxjs';
2222
import {
2323
AfterContentInit,
2424
Attribute,
@@ -28,40 +28,42 @@ import {
2828
ContentChild,
2929
ContentChildren,
3030
Directive,
31+
DoCheck,
3132
ElementRef,
3233
EventEmitter,
3334
Inject,
3435
InjectionToken,
3536
Input,
3637
isDevMode,
37-
NgZone, OnChanges,
38+
NgZone,
39+
OnChanges,
3840
OnDestroy,
3941
OnInit,
4042
Optional,
4143
Output,
4244
QueryList,
4345
Renderer2,
44-
Self, SimpleChanges,
46+
Self,
47+
SimpleChanges,
4548
ViewChild,
4649
ViewEncapsulation,
47-
DoCheck,
4850
} from '@angular/core';
4951
import {
5052
ControlValueAccessor,
53+
FormControl,
5154
FormGroupDirective,
5255
NgControl,
53-
NgForm,
54-
FormControl
56+
NgForm
5557
} from '@angular/forms';
5658
import {
5759
CanDisable,
60+
ErrorStateMatcher,
5861
HasTabIndex,
5962
MatOptgroup,
6063
MatOption,
6164
MatOptionSelectionChange,
6265
mixinDisabled,
6366
mixinTabIndex,
64-
ErrorStateMatcher,
6567
} from '@angular/material/core';
6668
import {MatFormField, MatFormFieldControl} from '@angular/material/form-field';
6769
import {Observable} from 'rxjs/Observable';

0 commit comments

Comments
 (0)