镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
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
Expand Up @@ -2,3 +2,4 @@ material/list/nav-list: 130473
material/radio/without-group: 121448
material/menu/without-lazy-content: 210751
material/datepicker/range-picker/without-form-field: 330101
material/button-toggle/standalone: 119400
7 changes: 7 additions & 0 deletions integration/size-test/material/button-toggle/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 = "standalone",
file = "standalone.ts",
deps = ["//src/material/button-toggle"],
)
23 changes: 23 additions & 0 deletions integration/size-test/material/button-toggle/standalone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Component, NgModule} from '@angular/core';
import {platformBrowser} from '@angular/platform-browser';
import {MatButtonToggleModule} from '@angular/material/button-toggle';

/**
* Basic component using a standalone `MatButtonToggle`. Other parts of the button-toggle
* module such as `MatButtonToggleGroup` are not used and should be tree-shaken away.
*/
@Component({
template: `
<mat-button-toggle>Center text</mat-button-toggle>
`,
})
export class TestComponent {}

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

platformBrowser().bootstrapModule(AppModule);
15 changes: 12 additions & 3 deletions src/material/button-toggle/button-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ export interface MatButtonToggleDefaultOptions {
export const MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS =
new InjectionToken<MatButtonToggleDefaultOptions>('MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS');


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

/**
* Provider Expression that allows mat-button-toggle-group to register as a ControlValueAccessor.
Expand Down Expand Up @@ -89,7 +95,10 @@ export class MatButtonToggleChange {
/** Exclusive selection button toggle group that behaves like a radio-button group. */
@Directive({
selector: 'mat-button-toggle-group',
providers: [MAT_BUTTON_TOGGLE_GROUP_VALUE_ACCESSOR],
providers: [
MAT_BUTTON_TOGGLE_GROUP_VALUE_ACCESSOR,
{provide: MAT_BUTTON_TOGGLE_GROUP, useExisting: MatButtonToggleGroup},
],
host: {
'role': 'group',
'class': 'mat-button-toggle-group',
Expand Down Expand Up @@ -476,7 +485,7 @@ export class MatButtonToggle extends _MatButtonToggleMixinBase implements OnInit
@Output() readonly change: EventEmitter<MatButtonToggleChange> =
new EventEmitter<MatButtonToggleChange>();

constructor(@Optional() toggleGroup: MatButtonToggleGroup,
constructor(@Optional() @Inject(MAT_BUTTON_TOGGLE_GROUP) toggleGroup: MatButtonToggleGroup,
private _changeDetectorRef: ChangeDetectorRef,
private _elementRef: ElementRef<HTMLElement>,
private _focusMonitor: FocusMonitor,
Expand Down
2 changes: 2 additions & 0 deletions tools/public_api_guard/material/button-toggle.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export declare const MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS: InjectionToken<MatButtonToggleDefaultOptions>;

export declare const MAT_BUTTON_TOGGLE_GROUP: InjectionToken<MatButtonToggleGroup>;

export declare const MAT_BUTTON_TOGGLE_GROUP_VALUE_ACCESSOR: any;

export declare class MatButtonToggle extends _MatButtonToggleMixinBase implements OnInit, AfterViewInit, CanDisableRipple, OnDestroy {
Expand Down