Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions goldens/size-test.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
material/list/nav-list: 130473
material/radio/without-group: 121448
7 changes: 7 additions & 0 deletions integration/size-test/material/radio/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load("//integration/size-test:index.bzl", "size_test")

size_test(
name = "without-group",
file = "without-group.ts",
deps = ["//src/material/radio"],
)
23 changes: 23 additions & 0 deletions integration/size-test/material/radio/without-group.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Component, NgModule} from '@angular/core';
import {MatRadioModule} from '@angular/material/radio';
import {platformBrowser} from '@angular/platform-browser';

/**
* Basic component using `MatRadioButton`. Doesn't use a `MatRadioGroup`, so the class
* should be tree-shaken away properly.
*/
@Component({
template: `
<mat-radio-button value="hello"></mat-radio-button>
`,
})
export class TestComponent {}

@NgModule({
imports: [MatRadioModule],
declarations: [TestComponent],
bootstrap: [TestComponent],
})
export class AppModule {}

platformBrowser().bootstrapModule(AppModule);
16 changes: 14 additions & 2 deletions src/material-experimental/mdc-radio/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
ElementRef,
forwardRef,
Inject,
InjectionToken,
OnDestroy,
Optional,
QueryList,
Expand Down Expand Up @@ -50,6 +51,14 @@ export const MAT_RADIO_GROUP_CONTROL_VALUE_ACCESSOR: any = {
multi: true
};

/**
* Injection token that can be used to inject instances of `MatRadioGroup`. It serves as
* alternative token to the actual `MatRadioGroup` class which could cause unnecessary
* retention of the class and its component metadata.
*/
export const MAT_RADIO_GROUP =

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: This is a separate token in the MDC-based implementation as the non-MDC implementation should not interfere with the MDC-based one.

new InjectionToken<_MatRadioGroupBase<_MatRadioButtonBase>>('MatRadioGroup');

/** Configuration for the ripple animation. */
const RIPPLE_ANIMATION_CONFIG: RippleAnimationConfig = {
enterDuration: numbers.DEACTIVATION_TIMEOUT_MS,
Expand All @@ -62,7 +71,10 @@ const RIPPLE_ANIMATION_CONFIG: RippleAnimationConfig = {
@Directive({
selector: 'mat-radio-group',
exportAs: 'matRadioGroup',
providers: [MAT_RADIO_GROUP_CONTROL_VALUE_ACCESSOR],
providers: [
MAT_RADIO_GROUP_CONTROL_VALUE_ACCESSOR,
{provide: MAT_RADIO_GROUP, useExisting: MatRadioGroup},
],
host: {
'role': 'radiogroup',
'class': 'mat-mdc-radio-group',
Expand Down Expand Up @@ -117,7 +129,7 @@ export class MatRadioButton extends _MatRadioButtonBase implements AfterViewInit
_radioFoundation = new MDCRadioFoundation(this._radioAdapter);
_classes: {[key: string]: boolean} = {};

constructor(@Optional() radioGroup: MatRadioGroup,
constructor(@Optional() @Inject(MAT_RADIO_GROUP) radioGroup: MatRadioGroup,
elementRef: ElementRef,
_changeDetector: ChangeDetectorRef,
_focusMonitor: FocusMonitor,
Expand Down
22 changes: 16 additions & 6 deletions src/material/radio/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ export class MatRadioChange {
public value: any) {}
}

/**
* Injection token that can be used to inject instances of `MatRadioGroup`. It serves as
* alternative token to the actual `MatRadioGroup` class which could cause unnecessary
* retention of the class and its component metadata.
*/
export const MAT_RADIO_GROUP =
new InjectionToken<_MatRadioGroupBase<_MatRadioButtonBase>>('MatRadioGroup');

/**
* Base class with all of the `MatRadioGroup` functionality.
* @docs-private
Expand Down Expand Up @@ -311,7 +319,10 @@ export abstract class _MatRadioGroupBase<T extends _MatRadioButtonBase> implemen
@Directive({
selector: 'mat-radio-group',
exportAs: 'matRadioGroup',
providers: [MAT_RADIO_GROUP_CONTROL_VALUE_ACCESSOR],
providers: [
MAT_RADIO_GROUP_CONTROL_VALUE_ACCESSOR,
{provide: MAT_RADIO_GROUP, useExisting: MatRadioGroup},
],
host: {
'role': 'radiogroup',
'class': 'mat-radio-group',
Expand Down Expand Up @@ -475,14 +486,13 @@ export abstract class _MatRadioButtonBase extends _MatRadioButtonMixinBase imple
/** The native `<input type=radio>` element */
@ViewChild('input') _inputElement: ElementRef<HTMLInputElement>;

constructor(@Optional() radioGroup: _MatRadioGroupBase<_MatRadioButtonBase>,
constructor(radioGroup: _MatRadioGroupBase<_MatRadioButtonBase>,
elementRef: ElementRef,
protected _changeDetector: ChangeDetectorRef,
private _focusMonitor: FocusMonitor,
private _radioDispatcher: UniqueSelectionDispatcher,
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string,
@Optional() @Inject(MAT_RADIO_DEFAULT_OPTIONS)
private _providerOverride?: MatRadioDefaultOptions) {
public _animationMode?: string,
private _providerOverride?: MatRadioDefaultOptions) {
super(elementRef);

// Assertions. Ideally these should be stripped out by the compiler.
Expand Down Expand Up @@ -626,7 +636,7 @@ export abstract class _MatRadioButtonBase extends _MatRadioButtonMixinBase imple
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MatRadioButton extends _MatRadioButtonBase {
constructor(@Optional() radioGroup: MatRadioGroup,
constructor(@Optional() @Inject(MAT_RADIO_GROUP) radioGroup: MatRadioGroup,
elementRef: ElementRef,
changeDetector: ChangeDetectorRef,
focusMonitor: FocusMonitor,
Expand Down
4 changes: 3 additions & 1 deletion tools/public_api_guard/material/radio.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export declare abstract class _MatRadioButtonBase extends _MatRadioButtonMixinBa
static ngAcceptInputType_disabled: BooleanInput;
static ngAcceptInputType_required: BooleanInput;
static ɵdir: i0.ɵɵDirectiveDefWithMeta<_MatRadioButtonBase, never, never, { "id": "id"; "name": "name"; "ariaLabel": "aria-label"; "ariaLabelledby": "aria-labelledby"; "ariaDescribedby": "aria-describedby"; "checked": "checked"; "value": "value"; "labelPosition": "labelPosition"; "disabled": "disabled"; "required": "required"; "color": "color"; }, { "change": "change"; }, never>;
static ɵfac: i0.ɵɵFactoryDef<_MatRadioButtonBase, [{ optional: true; }, null, null, null, null, { optional: true; }, { optional: true; }]>;
static ɵfac: i0.ɵɵFactoryDef<_MatRadioButtonBase, never>;
}

export declare abstract class _MatRadioGroupBase<T extends _MatRadioButtonBase> implements AfterContentInit, ControlValueAccessor {
Expand Down Expand Up @@ -78,6 +78,8 @@ export declare const MAT_RADIO_DEFAULT_OPTIONS: InjectionToken<MatRadioDefaultOp

export declare function MAT_RADIO_DEFAULT_OPTIONS_FACTORY(): MatRadioDefaultOptions;

export declare const MAT_RADIO_GROUP: InjectionToken<_MatRadioGroupBase<_MatRadioButtonBase>>;

export declare const MAT_RADIO_GROUP_CONTROL_VALUE_ACCESSOR: any;

export declare class MatRadioButton extends _MatRadioButtonBase {
Expand Down