Skip to content

Commit f520024

Browse files
committed
refactor(material/select): convert to standalone
Converts `material/select` to standalone.
1 parent abd94f8 commit f520024

File tree

6 files changed

+70
-12
lines changed

6 files changed

+70
-12
lines changed

src/material/select/module.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ import {CdkScrollableModule} from '@angular/cdk/scrolling';
1515
import {MatSelect, MatSelectTrigger, MAT_SELECT_SCROLL_STRATEGY_PROVIDER} from './select';
1616

1717
@NgModule({
18-
imports: [CommonModule, OverlayModule, MatOptionModule, MatCommonModule],
18+
imports: [
19+
CommonModule,
20+
OverlayModule,
21+
MatOptionModule,
22+
MatCommonModule,
23+
MatSelect,
24+
MatSelectTrigger,
25+
],
1926
exports: [
2027
CdkScrollableModule,
2128
MatFormFieldModule,
@@ -24,7 +31,6 @@ import {MatSelect, MatSelectTrigger, MAT_SELECT_SCROLL_STRATEGY_PROVIDER} from '
2431
MatOptionModule,
2532
MatCommonModule,
2633
],
27-
declarations: [MatSelect, MatSelectTrigger],
2834
providers: [MAT_SELECT_SCROLL_STRATEGY_PROVIDER],
2935
})
3036
export class MatSelectModule {}

src/material/select/public-api.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,15 @@
99
export * from './module';
1010
export * from './select';
1111
export * from './select-animations';
12+
13+
// Re-export these since they're required to be used together with `mat-select`.
14+
// Also they used to be provided implicitly with `MatSelectModule`.
15+
export {MatOption, MatOptgroup} from '@angular/material/core';
16+
export {
17+
MatFormField,
18+
MatLabel,
19+
MatHint,
20+
MatError,
21+
MatPrefix,
22+
MatSuffix,
23+
} from '@angular/material/form-field';

src/material/select/select.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ describe('MDC-based MatSelect', () => {
9999
NoopAnimationsModule,
100100
OverlayModule,
101101
],
102-
declarations: declarations,
103102
providers: [
104103
{provide: Directionality, useFactory: () => (dir = {value: 'ltr', change: EMPTY})},
105104
{
@@ -110,6 +109,7 @@ describe('MDC-based MatSelect', () => {
110109
},
111110
...providers,
112111
],
112+
declarations: declarations,
113113
}).compileComponents();
114114

115115
overlayContainerElement = TestBed.inject(OverlayContainer).getContainerElement();
@@ -2868,8 +2868,8 @@ describe('MDC-based MatSelect', () => {
28682868
FormsModule,
28692869
NoopAnimationsModule,
28702870
],
2871-
declarations: [FloatLabelSelect],
28722871
providers: [{provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: {floatLabel: 'always'}}],
2872+
declarations: [FloatLabelSelect],
28732873
});
28742874

28752875
const fixture = TestBed.createComponent(FloatLabelSelect);

src/material/select/select.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
ViewChild,
6060
ViewEncapsulation,
6161
booleanAttribute,
62+
inject,
6263
numberAttribute,
6364
} from '@angular/core';
6465
import {
@@ -97,12 +98,20 @@ import {
9798
getMatSelectNonArrayValueError,
9899
getMatSelectNonFunctionValueError,
99100
} from './select-errors';
101+
import {NgClass} from '@angular/common';
100102

101103
let nextUniqueId = 0;
102104

103105
/** Injection token that determines the scroll handling while a select is open. */
104106
export const MAT_SELECT_SCROLL_STRATEGY = new InjectionToken<() => ScrollStrategy>(
105107
'mat-select-scroll-strategy',
108+
{
109+
providedIn: 'root',
110+
factory: () => {
111+
const overlay = inject(Overlay);
112+
return () => overlay.scrollStrategies.reposition();
113+
},
114+
},
106115
);
107116

108117
/** @docs-private */
@@ -196,6 +205,8 @@ export class MatSelectChange {
196205
{provide: MatFormFieldControl, useExisting: MatSelect},
197206
{provide: MAT_OPTION_PARENT_COMPONENT, useExisting: MatSelect},
198207
],
208+
standalone: true,
209+
imports: [CdkOverlayOrigin, CdkConnectedOverlay, NgClass],
199210
})
200211
export class MatSelect
201212
implements
@@ -1414,5 +1425,6 @@ export class MatSelect
14141425
@Directive({
14151426
selector: 'mat-select-trigger',
14161427
providers: [{provide: MAT_SELECT_TRIGGER, useExisting: MatSelectTrigger}],
1428+
standalone: true,
14171429
})
14181430
export class MatSelectTrigger {}

src/material/select/testing/select-harness.spec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ describe('MatSelectHarness', () => {
1616

1717
beforeEach(async () => {
1818
await TestBed.configureTestingModule({
19-
imports: [MatSelectModule, MatFormFieldModule, NoopAnimationsModule, ReactiveFormsModule],
20-
declarations: [SelectHarnessTest],
19+
imports: [
20+
MatSelectModule,
21+
MatFormFieldModule,
22+
NoopAnimationsModule,
23+
ReactiveFormsModule,
24+
SelectHarnessTest,
25+
],
2126
}).compileComponents();
2227

2328
fixture = TestBed.createComponent(SelectHarnessTest);
@@ -301,6 +306,8 @@ describe('MatSelectHarness', () => {
301306
</mat-select>
302307
</mat-form-field>
303308
`,
309+
standalone: true,
310+
imports: [MatSelectModule, MatFormFieldModule, ReactiveFormsModule],
304311
})
305312
class SelectHarnessTest {
306313
formControl = new FormControl(undefined as string | undefined, [Validators.required]);

tools/public_api_guard/material/select.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,23 @@ import { ErrorStateMatcher } from '@angular/material/core';
1919
import { EventEmitter } from '@angular/core';
2020
import { FormGroupDirective } from '@angular/forms';
2121
import * as i0 from '@angular/core';
22-
import * as i2 from '@angular/common';
23-
import * as i3 from '@angular/cdk/overlay';
24-
import * as i4 from '@angular/material/core';
22+
import * as i1 from '@angular/common';
23+
import * as i2 from '@angular/cdk/overlay';
24+
import * as i3 from '@angular/material/core';
2525
import * as i5 from '@angular/cdk/scrolling';
2626
import * as i6 from '@angular/material/form-field';
2727
import { InjectionToken } from '@angular/core';
2828
import { LiveAnnouncer } from '@angular/cdk/a11y';
29+
import { MatError } from '@angular/material/form-field';
2930
import { MatFormField } from '@angular/material/form-field';
3031
import { MatFormFieldControl } from '@angular/material/form-field';
32+
import { MatHint } from '@angular/material/form-field';
33+
import { MatLabel } from '@angular/material/form-field';
3134
import { MatOptgroup } from '@angular/material/core';
3235
import { MatOption } from '@angular/material/core';
3336
import { MatOptionSelectionChange } from '@angular/material/core';
37+
import { MatPrefix } from '@angular/material/form-field';
38+
import { MatSuffix } from '@angular/material/form-field';
3439
import { NgControl } from '@angular/forms';
3540
import { NgForm } from '@angular/forms';
3641
import { NgZone } from '@angular/core';
@@ -65,6 +70,20 @@ export function MAT_SELECT_SCROLL_STRATEGY_PROVIDER_FACTORY(overlay: Overlay): (
6570
// @public
6671
export const MAT_SELECT_TRIGGER: InjectionToken<MatSelectTrigger>;
6772

73+
export { MatError }
74+
75+
export { MatFormField }
76+
77+
export { MatHint }
78+
79+
export { MatLabel }
80+
81+
export { MatOptgroup }
82+
83+
export { MatOption }
84+
85+
export { MatPrefix }
86+
6887
// @public (undocumented)
6988
export class MatSelect implements AfterContentInit, OnChanges, OnDestroy, OnInit, DoCheck, ControlValueAccessor, MatFormFieldControl<any> {
7089
constructor(_viewportRuler: ViewportRuler, _changeDetectorRef: ChangeDetectorRef, _ngZone: NgZone, defaultErrorStateMatcher: ErrorStateMatcher, _elementRef: ElementRef, _dir: Directionality, parentForm: NgForm, parentFormGroup: FormGroupDirective, _parentFormField: MatFormField, ngControl: NgControl, tabIndex: string, scrollStrategyFactory: any, _liveAnnouncer: LiveAnnouncer, _defaultOptions?: MatSelectConfig | undefined);
@@ -197,7 +216,7 @@ export class MatSelect implements AfterContentInit, OnChanges, OnDestroy, OnInit
197216
protected _viewportRuler: ViewportRuler;
198217
writeValue(value: any): void;
199218
// (undocumented)
200-
static ɵcmp: i0.ɵɵComponentDeclaration<MatSelect, "mat-select", ["matSelect"], { "userAriaDescribedBy": { "alias": "aria-describedby"; "required": false; }; "panelClass": { "alias": "panelClass"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; "disableRipple": { "alias": "disableRipple"; "required": false; }; "tabIndex": { "alias": "tabIndex"; "required": false; }; "hideSingleSelectionIndicator": { "alias": "hideSingleSelectionIndicator"; "required": false; }; "placeholder": { "alias": "placeholder"; "required": false; }; "required": { "alias": "required"; "required": false; }; "multiple": { "alias": "multiple"; "required": false; }; "disableOptionCentering": { "alias": "disableOptionCentering"; "required": false; }; "compareWith": { "alias": "compareWith"; "required": false; }; "value": { "alias": "value"; "required": false; }; "ariaLabel": { "alias": "aria-label"; "required": false; }; "ariaLabelledby": { "alias": "aria-labelledby"; "required": false; }; "errorStateMatcher": { "alias": "errorStateMatcher"; "required": false; }; "typeaheadDebounceInterval": { "alias": "typeaheadDebounceInterval"; "required": false; }; "sortComparator": { "alias": "sortComparator"; "required": false; }; "id": { "alias": "id"; "required": false; }; "panelWidth": { "alias": "panelWidth"; "required": false; }; }, { "openedChange": "openedChange"; "_openedStream": "opened"; "_closedStream": "closed"; "selectionChange": "selectionChange"; "valueChange": "valueChange"; }, ["customTrigger", "options", "optionGroups"], ["mat-select-trigger", "*"], false, never>;
219+
static ɵcmp: i0.ɵɵComponentDeclaration<MatSelect, "mat-select", ["matSelect"], { "userAriaDescribedBy": { "alias": "aria-describedby"; "required": false; }; "panelClass": { "alias": "panelClass"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; "disableRipple": { "alias": "disableRipple"; "required": false; }; "tabIndex": { "alias": "tabIndex"; "required": false; }; "hideSingleSelectionIndicator": { "alias": "hideSingleSelectionIndicator"; "required": false; }; "placeholder": { "alias": "placeholder"; "required": false; }; "required": { "alias": "required"; "required": false; }; "multiple": { "alias": "multiple"; "required": false; }; "disableOptionCentering": { "alias": "disableOptionCentering"; "required": false; }; "compareWith": { "alias": "compareWith"; "required": false; }; "value": { "alias": "value"; "required": false; }; "ariaLabel": { "alias": "aria-label"; "required": false; }; "ariaLabelledby": { "alias": "aria-labelledby"; "required": false; }; "errorStateMatcher": { "alias": "errorStateMatcher"; "required": false; }; "typeaheadDebounceInterval": { "alias": "typeaheadDebounceInterval"; "required": false; }; "sortComparator": { "alias": "sortComparator"; "required": false; }; "id": { "alias": "id"; "required": false; }; "panelWidth": { "alias": "panelWidth"; "required": false; }; }, { "openedChange": "openedChange"; "_openedStream": "opened"; "_closedStream": "closed"; "selectionChange": "selectionChange"; "valueChange": "valueChange"; }, ["customTrigger", "options", "optionGroups"], ["mat-select-trigger", "*"], true, never>;
201220
// (undocumented)
202221
static ɵfac: i0.ɵɵFactoryDeclaration<MatSelect, [null, null, null, null, null, { optional: true; }, { optional: true; }, { optional: true; }, { optional: true; }, { optional: true; self: true; }, { attribute: "tabindex"; }, null, null, { optional: true; }]>;
203222
}
@@ -233,17 +252,19 @@ export class MatSelectModule {
233252
// (undocumented)
234253
static ɵinj: i0.ɵɵInjectorDeclaration<MatSelectModule>;
235254
// (undocumented)
236-
static ɵmod: i0.ɵɵNgModuleDeclaration<MatSelectModule, [typeof i1.MatSelect, typeof i1.MatSelectTrigger], [typeof i2.CommonModule, typeof i3.OverlayModule, typeof i4.MatOptionModule, typeof i4.MatCommonModule], [typeof i5.CdkScrollableModule, typeof i6.MatFormFieldModule, typeof i1.MatSelect, typeof i1.MatSelectTrigger, typeof i4.MatOptionModule, typeof i4.MatCommonModule]>;
255+
static ɵmod: i0.ɵɵNgModuleDeclaration<MatSelectModule, never, [typeof i1.CommonModule, typeof i2.OverlayModule, typeof i3.MatOptionModule, typeof i3.MatCommonModule, typeof i4.MatSelect, typeof i4.MatSelectTrigger], [typeof i5.CdkScrollableModule, typeof i6.MatFormFieldModule, typeof i4.MatSelect, typeof i4.MatSelectTrigger, typeof i3.MatOptionModule, typeof i3.MatCommonModule]>;
237256
}
238257

239258
// @public
240259
export class MatSelectTrigger {
241260
// (undocumented)
242-
static ɵdir: i0.ɵɵDirectiveDeclaration<MatSelectTrigger, "mat-select-trigger", never, {}, {}, never, never, false, never>;
261+
static ɵdir: i0.ɵɵDirectiveDeclaration<MatSelectTrigger, "mat-select-trigger", never, {}, {}, never, never, true, never>;
243262
// (undocumented)
244263
static ɵfac: i0.ɵɵFactoryDeclaration<MatSelectTrigger, never>;
245264
}
246265

266+
export { MatSuffix }
267+
247268
// (No @packageDocumentation comment for this package)
248269

249270
```

0 commit comments

Comments
 (0)