Skip to content

Commit 149f980

Browse files
committed
fix(material/progress-bar): remove dependency on legacy progress bar
Fixes that the non-legacy progress bar was importing several symbols from the legacy version.
1 parent f379e80 commit 149f980

21 files changed

+165
-167
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 & 59 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,19 +22,22 @@ 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): Benchpress tests.
3439
// TODO(josephperrott): Add ARIA attributes for progress bar "for".
3540

36-
/** Last animation end data. */
37-
export interface LegacyProgressAnimationEnd {
38-
value: number;
39-
}
40-
4141
// Boilerplate for applying mixins to MatProgressBar.
4242
/** @docs-private */
4343
const _MatProgressBarBase = mixinColor(
@@ -47,51 +47,6 @@ const _MatProgressBarBase = mixinColor(
4747
'primary',
4848
);
4949

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_LEGACY_PROGRESS_BAR_LOCATION = new InjectionToken<MatLegacyProgressBarLocation>(
56-
'mat-progress-bar-location',
57-
{providedIn: 'root', factory: MAT_LEGACY_PROGRESS_BAR_LOCATION_FACTORY},
58-
);
59-
60-
/**
61-
* Stubbed out location for `MatProgressBar`.
62-
* @docs-private
63-
*/
64-
export interface MatLegacyProgressBarLocation {
65-
getPathname: () => string;
66-
}
67-
68-
/** @docs-private */
69-
export function MAT_LEGACY_PROGRESS_BAR_LOCATION_FACTORY(): MatLegacyProgressBarLocation {
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-
80-
export type LegacyProgressBarMode = 'determinate' | 'indeterminate' | 'buffer' | 'query';
81-
82-
/** Default `mat-progress-bar` options that can be overridden. */
83-
export interface MatLegacyProgressBarDefaultOptions {
84-
/** Default color of the progress bar. */
85-
color?: ThemePalette;
86-
87-
/** Default mode of the progress bar. */
88-
mode?: LegacyProgressBarMode;
89-
}
90-
91-
/** Injection token to be used to override the default options for `mat-progress-bar`. */
92-
export const MAT_LEGACY_PROGRESS_BAR_DEFAULT_OPTIONS =
93-
new InjectionToken<MatLegacyProgressBarDefaultOptions>('MAT_PROGRESS_BAR_DEFAULT_OPTIONS');
94-
9550
/** Counter used to generate unique IDs for progress bars. */
9651
let progressbarId = 0;
9752

@@ -131,10 +86,10 @@ export class MatLegacyProgressBar
13186
* @deprecated `location` parameter to be made required.
13287
* @breaking-change 8.0.0
13388
*/
134-
@Optional() @Inject(MAT_LEGACY_PROGRESS_BAR_LOCATION) location?: MatLegacyProgressBarLocation,
89+
@Optional() @Inject(MAT_PROGRESS_BAR_LOCATION) location?: MatProgressBarLocation,
13590
@Optional()
136-
@Inject(MAT_LEGACY_PROGRESS_BAR_DEFAULT_OPTIONS)
137-
defaults?: MatLegacyProgressBarDefaultOptions,
91+
@Inject(MAT_PROGRESS_BAR_DEFAULT_OPTIONS)
92+
defaults?: MatProgressBarDefaultOptions,
13893
/**
13994
* @deprecated `_changeDetectorRef` parameter to be made required.
14095
* @breaking-change 11.0.0
@@ -198,7 +153,7 @@ export class MatLegacyProgressBar
198153
* be emitted when animations are disabled, nor will it be emitted for modes with continuous
199154
* animations (indeterminate and query).
200155
*/
201-
@Output() readonly animationEnd = new EventEmitter<LegacyProgressAnimationEnd>();
156+
@Output() readonly animationEnd = new EventEmitter<ProgressAnimationEnd>();
202157

203158
/** Reference to animation end subscription to be unsubscribed on destroy. */
204159
private _animationEndSubscription: Subscription = Subscription.EMPTY;
@@ -210,7 +165,7 @@ export class MatLegacyProgressBar
210165
* 'determinate'.
211166
* Mirrored to mode attribute.
212167
*/
213-
@Input() mode: LegacyProgressBarMode = 'determinate';
168+
@Input() mode: ProgressBarMode = 'determinate';
214169

215170
/** ID of the progress bar. */
216171
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

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
/** Harness for interacting with a standard mat-progress-bar in tests. */
1414
export class MatLegacyProgressBarHarness extends ComponentHarness {
@@ -22,7 +22,7 @@ export class MatLegacyProgressBarHarness extends ComponentHarness {
2222
* @return a `HarnessPredicate` configured with the given options.
2323
*/
2424
static with(
25-
options: LegacyProgressBarHarnessFilters = {},
25+
options: ProgressBarHarnessFilters = {},
2626
): HarnessPredicate<MatLegacyProgressBarHarness> {
2727
return new HarnessPredicate(MatLegacyProgressBarHarness, options);
2828
}

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,14 +20,61 @@ 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';
29+
30+
/** Last animation end data. */
31+
export interface ProgressAnimationEnd {
32+
value: number;
33+
}
34+
35+
/** Default `mat-progress-bar` options that can be overridden. */
36+
export interface MatProgressBarDefaultOptions {
37+
/** Default color of the progress bar. */
38+
color?: ThemePalette;
39+
40+
/** Default mode of the progress bar. */
41+
mode?: ProgressBarMode;
42+
}
43+
44+
/** Injection token to be used to override the default options for `mat-progress-bar`. */
45+
export const MAT_PROGRESS_BAR_DEFAULT_OPTIONS = new InjectionToken<MatProgressBarDefaultOptions>(
46+
'MAT_PROGRESS_BAR_DEFAULT_OPTIONS',
47+
);
48+
49+
/**
50+
* Injection token used to provide the current location to `MatProgressBar`.
51+
* Used to handle server-side rendering and to stub out during unit tests.
52+
* @docs-private
53+
*/
54+
export const MAT_PROGRESS_BAR_LOCATION = new InjectionToken<MatProgressBarLocation>(
55+
'mat-progress-bar-location',
56+
{providedIn: 'root', factory: MAT_PROGRESS_BAR_LOCATION_FACTORY},
57+
);
58+
59+
/**
60+
* Stubbed out location for `MatProgressBar`.
61+
* @docs-private
62+
*/
63+
export interface MatProgressBarLocation {
64+
getPathname: () => string;
65+
}
66+
67+
/** @docs-private */
68+
export function MAT_PROGRESS_BAR_LOCATION_FACTORY(): MatProgressBarLocation {
69+
const _document = inject(DOCUMENT);
70+
const _location = _document ? _document.location : null;
71+
72+
return {
73+
// Note that this needs to be a function, rather than a property, because Angular
74+
// will only resolve it once, but we want the current path on each call.
75+
getPathname: () => (_location ? _location.pathname + _location.search : ''),
76+
};
77+
}
3178

3279
// Boilerplate for applying mixins to MatProgressBar.
3380
/** @docs-private */
@@ -73,8 +120,8 @@ export class MatProgressBar
73120
private _changeDetectorRef: ChangeDetectorRef,
74121
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string,
75122
@Optional()
76-
@Inject(MAT_LEGACY_PROGRESS_BAR_DEFAULT_OPTIONS)
77-
defaults?: MatLegacyProgressBarDefaultOptions,
123+
@Inject(MAT_PROGRESS_BAR_DEFAULT_OPTIONS)
124+
defaults?: MatProgressBarDefaultOptions,
78125
) {
79126
super(elementRef);
80127
this._isNoopAnimation = _animationMode === 'NoopAnimations';
@@ -118,7 +165,7 @@ export class MatProgressBar
118165
* be emitted when animations are disabled, nor will it be emitted for modes with continuous
119166
* animations (indeterminate and query).
120167
*/
121-
@Output() readonly animationEnd = new EventEmitter<LegacyProgressAnimationEnd>();
168+
@Output() readonly animationEnd = new EventEmitter<ProgressAnimationEnd>();
122169

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

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,3 @@
88

99
export * from './progress-bar';
1010
export * from './module';
11-
12-
export {
13-
LegacyProgressAnimationEnd as ProgressAnimationEnd,
14-
MAT_LEGACY_PROGRESS_BAR_LOCATION as MAT_PROGRESS_BAR_LOCATION,
15-
MatLegacyProgressBarLocation as MatProgressBarLocation,
16-
MAT_LEGACY_PROGRESS_BAR_LOCATION_FACTORY as MAT_PROGRESS_BAR_LOCATION_FACTORY,
17-
MAT_LEGACY_PROGRESS_BAR_DEFAULT_OPTIONS as MAT_PROGRESS_BAR_DEFAULT_OPTIONS,
18-
MatLegacyProgressBarDefaultOptions as MatProgressBarDefaultOptions,
19-
} from '@angular/material/legacy-progress-bar';

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,30 @@ ng_module(
1111
deps = [
1212
"//src/cdk/coercion",
1313
"//src/cdk/testing",
14-
"//src/material/legacy-progress-bar/testing",
14+
],
15+
)
16+
17+
ng_test_library(
18+
name = "harness_tests_lib",
19+
srcs = ["shared.spec.ts"],
20+
deps = [
21+
":testing",
22+
"//src/cdk/testing",
23+
"//src/cdk/testing/testbed",
24+
"//src/material/progress-bar",
25+
"@npm//@angular/platform-browser",
1526
],
1627
)
1728

1829
ng_test_library(
1930
name = "unit_tests_lib",
20-
srcs = glob(["**/*.spec.ts"]),
31+
srcs = glob(
32+
["**/*.spec.ts"],
33+
exclude = ["shared.spec.ts"],
34+
),
2135
deps = [
2236
":testing",
23-
"//src/material/legacy-progress-bar/testing:harness_tests_lib",
37+
":harness_tests_lib",
2438
"//src/material/progress-bar",
2539
],
2640
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
import {BaseHarnessFilters} from '@angular/cdk/testing';
1010

1111
/** A set of criteria that can be used to filter a list of `MatProgressBarHarness` instances. */
12-
export interface LegacyProgressBarHarnessFilters extends BaseHarnessFilters {}
12+
export interface ProgressBarHarnessFilters extends BaseHarnessFilters {}

0 commit comments

Comments
 (0)