Skip to content

Commit c5c8e64

Browse files
authored
fix(material/progress-bar): remove dependency on legacy progress bar (#25581)
Fixes that the non-legacy progress bar was importing several symbols from the legacy version.
1 parent 518b2b6 commit c5c8e64

22 files changed

+176
-206
lines changed

src/material/legacy-progress-bar/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ng_module(
2020
assets = [":progress-bar.css"] + glob(["**/*.html"]),
2121
deps = [
2222
"//src/material/core",
23+
"//src/material/progress-bar",
2324
"@npm//@angular/animations",
2425
"@npm//@angular/common",
2526
"@npm//@angular/core",

src/material/legacy-progress-bar/progress-bar.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import {TestBed, ComponentFixture} from '@angular/core/testing';
22
import {ApplicationRef, Component, DebugElement, Provider, Type} from '@angular/core';
33
import {By} from '@angular/platform-browser';
44
import {dispatchFakeEvent} from '../../cdk/testing/private';
5-
import {MatLegacyProgressBarModule, MAT_LEGACY_PROGRESS_BAR_LOCATION} from './index';
6-
import {MatLegacyProgressBar, MAT_LEGACY_PROGRESS_BAR_DEFAULT_OPTIONS} from './progress-bar';
5+
import {
6+
MatLegacyProgressBarModule,
7+
MAT_LEGACY_PROGRESS_BAR_LOCATION,
8+
MAT_LEGACY_PROGRESS_BAR_DEFAULT_OPTIONS,
9+
} from './index';
10+
import {MatLegacyProgressBar} from './progress-bar';
711

812
describe('MatProgressBar', () => {
913
let fakePath: string;

src/material/legacy-progress-bar/progress-bar.ts

Lines changed: 14 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import {coerceNumberProperty, NumberInput} from '@angular/cdk/coercion';
9-
import {DOCUMENT} from '@angular/common';
109
import {
1110
AfterViewInit,
1211
ChangeDetectionStrategy,
1312
Component,
1413
ElementRef,
1514
EventEmitter,
1615
Inject,
17-
inject,
18-
InjectionToken,
1916
Input,
2017
NgZone,
2118
OnDestroy,
@@ -25,22 +22,21 @@ import {
2522
ViewEncapsulation,
2623
ChangeDetectorRef,
2724
} from '@angular/core';
28-
import {CanColor, mixinColor, ThemePalette} from '@angular/material/core';
25+
import {CanColor, mixinColor} from '@angular/material/core';
26+
import {
27+
MatProgressBarDefaultOptions,
28+
MAT_PROGRESS_BAR_DEFAULT_OPTIONS,
29+
ProgressAnimationEnd,
30+
ProgressBarMode,
31+
MAT_PROGRESS_BAR_LOCATION,
32+
MatProgressBarLocation,
33+
} from '@angular/material/progress-bar';
2934
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
3035
import {fromEvent, Observable, Subscription} from 'rxjs';
3136
import {filter} from 'rxjs/operators';
3237

3338
// TODO(josephperrott): Add ARIA attributes for progress bar "for".
3439

35-
/**
36-
* Last animation end data.
37-
* @deprecated Use `ProgressAnimationEnd` from `@angular/material/progress-bar` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
38-
* @breaking-change 17.0.0
39-
*/
40-
export interface LegacyProgressAnimationEnd {
41-
value: number;
42-
}
43-
4440
// Boilerplate for applying mixins to MatProgressBar.
4541
/** @docs-private */
4642
const _MatProgressBarBase = mixinColor(
@@ -50,71 +46,6 @@ const _MatProgressBarBase = mixinColor(
5046
'primary',
5147
);
5248

53-
/**
54-
* Injection token used to provide the current location to `MatProgressBar`.
55-
* Used to handle server-side rendering and to stub out during unit tests.
56-
* @docs-private
57-
* @deprecated Use `MAT_PROGRESS_BAR_LOCATION` from `@angular/material/progress-bar` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
58-
* @breaking-change 17.0.0
59-
*/
60-
export const MAT_LEGACY_PROGRESS_BAR_LOCATION = new InjectionToken<MatLegacyProgressBarLocation>(
61-
'mat-progress-bar-location',
62-
{providedIn: 'root', factory: MAT_LEGACY_PROGRESS_BAR_LOCATION_FACTORY},
63-
);
64-
65-
/**
66-
* Stubbed out location for `MatProgressBar`.
67-
* @docs-private
68-
* @deprecated Use `MatProgressBarLocation` from `@angular/material/progress-bar` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
69-
* @breaking-change 17.0.0
70-
*/
71-
export interface MatLegacyProgressBarLocation {
72-
getPathname: () => string;
73-
}
74-
75-
/**
76-
* @docs-private
77-
* @deprecated Use `MAT_PROGRESS_BAR_LOCATION_FACTORY` from `@angular/material/progress-bar` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
78-
* @breaking-change 17.0.0
79-
*/
80-
export function MAT_LEGACY_PROGRESS_BAR_LOCATION_FACTORY(): MatLegacyProgressBarLocation {
81-
const _document = inject(DOCUMENT);
82-
const _location = _document ? _document.location : null;
83-
84-
return {
85-
// Note that this needs to be a function, rather than a property, because Angular
86-
// will only resolve it once, but we want the current path on each call.
87-
getPathname: () => (_location ? _location.pathname + _location.search : ''),
88-
};
89-
}
90-
91-
/**
92-
* @deprecated Use `ProgressBarMode` from `@angular/material/progress-bar` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
93-
* @breaking-change 17.0.0
94-
*/
95-
export type LegacyProgressBarMode = 'determinate' | 'indeterminate' | 'buffer' | 'query';
96-
97-
/**
98-
* Default `mat-progress-bar` options that can be overridden.
99-
* @deprecated Use `MatProgressBarDefaultOptions` from `@angular/material/progress-bar` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
100-
* @breaking-change 17.0.0
101-
*/
102-
export interface MatLegacyProgressBarDefaultOptions {
103-
/** Default color of the progress bar. */
104-
color?: ThemePalette;
105-
106-
/** Default mode of the progress bar. */
107-
mode?: LegacyProgressBarMode;
108-
}
109-
110-
/**
111-
* Injection token to be used to override the default options for `mat-progress-bar`.
112-
* @deprecated Use `MAT_PROGRESS_BAR_DEFAULT_OPTIONS` from `@angular/material/progress-bar` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
113-
* @breaking-change 17.0.0
114-
*/
115-
export const MAT_LEGACY_PROGRESS_BAR_DEFAULT_OPTIONS =
116-
new InjectionToken<MatLegacyProgressBarDefaultOptions>('MAT_PROGRESS_BAR_DEFAULT_OPTIONS');
117-
11849
/** Counter used to generate unique IDs for progress bars. */
11950
let progressbarId = 0;
12051

@@ -156,10 +87,10 @@ export class MatLegacyProgressBar
15687
* @deprecated `location` parameter to be made required.
15788
* @breaking-change 8.0.0
15889
*/
159-
@Optional() @Inject(MAT_LEGACY_PROGRESS_BAR_LOCATION) location?: MatLegacyProgressBarLocation,
90+
@Optional() @Inject(MAT_PROGRESS_BAR_LOCATION) location?: MatProgressBarLocation,
16091
@Optional()
161-
@Inject(MAT_LEGACY_PROGRESS_BAR_DEFAULT_OPTIONS)
162-
defaults?: MatLegacyProgressBarDefaultOptions,
92+
@Inject(MAT_PROGRESS_BAR_DEFAULT_OPTIONS)
93+
defaults?: MatProgressBarDefaultOptions,
16394
/**
16495
* @deprecated `_changeDetectorRef` parameter to be made required.
16596
* @breaking-change 11.0.0
@@ -223,7 +154,7 @@ export class MatLegacyProgressBar
223154
* be emitted when animations are disabled, nor will it be emitted for modes with continuous
224155
* animations (indeterminate and query).
225156
*/
226-
@Output() readonly animationEnd = new EventEmitter<LegacyProgressAnimationEnd>();
157+
@Output() readonly animationEnd = new EventEmitter<ProgressAnimationEnd>();
227158

228159
/** Reference to animation end subscription to be unsubscribed on destroy. */
229160
private _animationEndSubscription: Subscription = Subscription.EMPTY;
@@ -235,7 +166,7 @@ export class MatLegacyProgressBar
235166
* 'determinate'.
236167
* Mirrored to mode attribute.
237168
*/
238-
@Input() mode: LegacyProgressBarMode = 'determinate';
169+
@Input() mode: ProgressBarMode = 'determinate';
239170

240171
/** ID of the progress bar. */
241172
progressbarId = `mat-progress-bar-${progressbarId++}`;

src/material/legacy-progress-bar/public-api.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
*/
88

99
export {MatLegacyProgressBarModule} from './progress-bar-module';
10+
export {MatLegacyProgressBar} from './progress-bar';
11+
1012
export {
11-
LegacyProgressAnimationEnd,
12-
MAT_LEGACY_PROGRESS_BAR_LOCATION,
13-
MatLegacyProgressBarLocation,
14-
MAT_LEGACY_PROGRESS_BAR_LOCATION_FACTORY,
15-
LegacyProgressBarMode,
16-
MatLegacyProgressBarDefaultOptions,
17-
MAT_LEGACY_PROGRESS_BAR_DEFAULT_OPTIONS,
18-
MatLegacyProgressBar,
19-
} from './progress-bar';
13+
MatProgressBarDefaultOptions as MatLegacyProgressBarDefaultOptions,
14+
MAT_PROGRESS_BAR_DEFAULT_OPTIONS as MAT_LEGACY_PROGRESS_BAR_DEFAULT_OPTIONS,
15+
ProgressAnimationEnd as LegacyProgressAnimationEnd,
16+
ProgressBarMode as LegacyProgressBarMode,
17+
MAT_PROGRESS_BAR_LOCATION as MAT_LEGACY_PROGRESS_BAR_LOCATION,
18+
MatProgressBarLocation as MatLegacyProgressBarLocation,
19+
MAT_PROGRESS_BAR_LOCATION_FACTORY as MAT_LEGACY_PROGRESS_BAR_LOCATION_FACTORY,
20+
} from '@angular/material/progress-bar';

src/material/legacy-progress-bar/testing/BUILD.bazel

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ts_library(
1111
deps = [
1212
"//src/cdk/coercion",
1313
"//src/cdk/testing",
14+
"//src/material/progress-bar/testing",
1415
],
1516
)
1617

@@ -19,28 +20,13 @@ filegroup(
1920
srcs = glob(["**/*.ts"]),
2021
)
2122

22-
ng_test_library(
23-
name = "harness_tests_lib",
24-
srcs = ["shared.spec.ts"],
25-
deps = [
26-
":testing",
27-
"//src/cdk/testing",
28-
"//src/cdk/testing/testbed",
29-
"//src/material/legacy-progress-bar",
30-
"@npm//@angular/platform-browser",
31-
],
32-
)
33-
3423
ng_test_library(
3524
name = "unit_tests_lib",
36-
srcs = glob(
37-
["**/*.spec.ts"],
38-
exclude = ["shared.spec.ts"],
39-
),
25+
srcs = glob(["**/*.spec.ts"]),
4026
deps = [
41-
":harness_tests_lib",
4227
":testing",
4328
"//src/material/legacy-progress-bar",
29+
"//src/material/progress-bar/testing:harness_tests_lib",
4430
],
4531
)
4632

src/material/legacy-progress-bar/testing/progress-bar-harness-filters.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {MatLegacyProgressBarModule} from '@angular/material/legacy-progress-bar';
2-
import {runHarnessTests} from '@angular/material/legacy-progress-bar/testing/shared.spec';
2+
import {runHarnessTests} from '@angular/material/progress-bar/testing/shared.spec';
33
import {MatLegacyProgressBarHarness} from './progress-bar-harness';
44

55
describe('MatProgressBarHarness', () => {
6-
runHarnessTests(MatLegacyProgressBarModule, MatLegacyProgressBarHarness);
6+
runHarnessTests(MatLegacyProgressBarModule, MatLegacyProgressBarHarness as any);
77
});

src/material/legacy-progress-bar/testing/progress-bar-harness.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {coerceNumberProperty} from '@angular/cdk/coercion';
1010
import {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing';
11-
import {LegacyProgressBarHarnessFilters} from './progress-bar-harness-filters';
11+
import {ProgressBarHarnessFilters} from '@angular/material/progress-bar/testing';
1212

1313
/**
1414
* Harness for interacting with a standard mat-progress-bar in tests.
@@ -26,7 +26,7 @@ export class MatLegacyProgressBarHarness extends ComponentHarness {
2626
* @return a `HarnessPredicate` configured with the given options.
2727
*/
2828
static with(
29-
options: LegacyProgressBarHarnessFilters = {},
29+
options: ProgressBarHarnessFilters = {},
3030
): HarnessPredicate<MatLegacyProgressBarHarness> {
3131
return new HarnessPredicate(MatLegacyProgressBarHarness, options);
3232
}

src/material/legacy-progress-bar/testing/public-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
*/
88

99
export {MatLegacyProgressBarHarness} from './progress-bar-harness';
10-
export {LegacyProgressBarHarnessFilters} from './progress-bar-harness-filters';
10+
export {ProgressBarHarnessFilters as LegacyProgressBarHarnessFilters} from '@angular/material/progress-bar/testing';

src/material/progress-bar/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ ng_module(
2323
assets = [":progress_bar_scss"] + glob(["**/*.html"]),
2424
deps = [
2525
"//src/material/core",
26-
"//src/material/legacy-progress-bar",
2726
"@npm//@angular/core",
2827
],
2928
)

src/material/progress-bar/progress-bar.ts

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,63 @@ import {
2020
AfterViewInit,
2121
OnDestroy,
2222
ChangeDetectorRef,
23+
InjectionToken,
24+
inject,
2325
} from '@angular/core';
24-
import {CanColor, mixinColor} from '@angular/material/core';
26+
import {DOCUMENT} from '@angular/common';
27+
import {CanColor, mixinColor, ThemePalette} from '@angular/material/core';
2528
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
26-
import {
27-
MatLegacyProgressBarDefaultOptions,
28-
MAT_LEGACY_PROGRESS_BAR_DEFAULT_OPTIONS,
29-
LegacyProgressAnimationEnd,
30-
} from '@angular/material/legacy-progress-bar';
3129
import {coerceNumberProperty, NumberInput} from '@angular/cdk/coercion';
3230

31+
/** Last animation end data. */
32+
export interface ProgressAnimationEnd {
33+
value: number;
34+
}
35+
36+
/** Default `mat-progress-bar` options that can be overridden. */
37+
export interface MatProgressBarDefaultOptions {
38+
/** Default color of the progress bar. */
39+
color?: ThemePalette;
40+
41+
/** Default mode of the progress bar. */
42+
mode?: ProgressBarMode;
43+
}
44+
45+
/** Injection token to be used to override the default options for `mat-progress-bar`. */
46+
export const MAT_PROGRESS_BAR_DEFAULT_OPTIONS = new InjectionToken<MatProgressBarDefaultOptions>(
47+
'MAT_PROGRESS_BAR_DEFAULT_OPTIONS',
48+
);
49+
50+
/**
51+
* Injection token used to provide the current location to `MatProgressBar`.
52+
* Used to handle server-side rendering and to stub out during unit tests.
53+
* @docs-private
54+
*/
55+
export const MAT_PROGRESS_BAR_LOCATION = new InjectionToken<MatProgressBarLocation>(
56+
'mat-progress-bar-location',
57+
{providedIn: 'root', factory: MAT_PROGRESS_BAR_LOCATION_FACTORY},
58+
);
59+
60+
/**
61+
* Stubbed out location for `MatProgressBar`.
62+
* @docs-private
63+
*/
64+
export interface MatProgressBarLocation {
65+
getPathname: () => string;
66+
}
67+
68+
/** @docs-private */
69+
export function MAT_PROGRESS_BAR_LOCATION_FACTORY(): MatProgressBarLocation {
70+
const _document = inject(DOCUMENT);
71+
const _location = _document ? _document.location : null;
72+
73+
return {
74+
// Note that this needs to be a function, rather than a property, because Angular
75+
// will only resolve it once, but we want the current path on each call.
76+
getPathname: () => (_location ? _location.pathname + _location.search : ''),
77+
};
78+
}
79+
3380
// Boilerplate for applying mixins to MatProgressBar.
3481
/** @docs-private */
3582
const _MatProgressBarBase = mixinColor(
@@ -74,8 +121,8 @@ export class MatProgressBar
74121
private _changeDetectorRef: ChangeDetectorRef,
75122
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string,
76123
@Optional()
77-
@Inject(MAT_LEGACY_PROGRESS_BAR_DEFAULT_OPTIONS)
78-
defaults?: MatLegacyProgressBarDefaultOptions,
124+
@Inject(MAT_PROGRESS_BAR_DEFAULT_OPTIONS)
125+
defaults?: MatProgressBarDefaultOptions,
79126
) {
80127
super(elementRef);
81128
this._isNoopAnimation = _animationMode === 'NoopAnimations';
@@ -119,7 +166,7 @@ export class MatProgressBar
119166
* be emitted when animations are disabled, nor will it be emitted for modes with continuous
120167
* animations (indeterminate and query).
121168
*/
122-
@Output() readonly animationEnd = new EventEmitter<LegacyProgressAnimationEnd>();
169+
@Output() readonly animationEnd = new EventEmitter<ProgressAnimationEnd>();
123170

124171
/**
125172
* Mode of the progress bar.

0 commit comments

Comments
 (0)