Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(material/tooltip): migrate MDC examples (#25495)
- Loading branch information
1 parent
a8f847c
commit 2fc05f5
Showing
54 changed files
with
605 additions
and
156 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/components-examples/material/legacy-tooltip/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
ng_module( | ||
name = "legacy-tooltip", | ||
srcs = glob( | ||
["**/*.ts"], | ||
exclude = ["**/*.spec.ts"], | ||
), | ||
assets = glob([ | ||
"**/*.html", | ||
"**/*.css", | ||
]), | ||
deps = [ | ||
"//src/cdk/scrolling", | ||
"//src/cdk/testing", | ||
"//src/cdk/testing/testbed", | ||
"//src/material/legacy-button", | ||
"//src/material/legacy-checkbox", | ||
"//src/material/legacy-input", | ||
"//src/material/legacy-select", | ||
"//src/material/legacy-tooltip", | ||
"//src/material/legacy-tooltip/testing", | ||
"@npm//@angular/forms", | ||
"@npm//@angular/platform-browser", | ||
"@npm//@angular/platform-browser-dynamic", | ||
"@npm//@types/jasmine", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "source-files", | ||
srcs = glob([ | ||
"**/*.html", | ||
"**/*.css", | ||
"**/*.ts", | ||
]), | ||
) | ||
|
||
ng_test_library( | ||
name = "unit_tests_lib", | ||
srcs = glob(["**/*.spec.ts"]), | ||
deps = [ | ||
":legacy-tooltip", | ||
"//src/cdk/testing", | ||
"//src/cdk/testing/testbed", | ||
"//src/material/legacy-tooltip", | ||
"//src/material/legacy-tooltip/testing", | ||
"@npm//@angular/platform-browser", | ||
"@npm//@angular/platform-browser-dynamic", | ||
], | ||
) | ||
|
||
ng_web_test_suite( | ||
name = "unit_tests", | ||
deps = [":unit_tests_lib"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import {CommonModule} from '@angular/common'; | ||
import {NgModule} from '@angular/core'; | ||
import {ReactiveFormsModule} from '@angular/forms'; | ||
import {ScrollingModule} from '@angular/cdk/scrolling'; | ||
import {MatLegacyButtonModule} from '@angular/material/legacy-button'; | ||
import {MatLegacyCheckboxModule} from '@angular/material/legacy-checkbox'; | ||
import {MatLegacyInputModule} from '@angular/material/legacy-input'; | ||
import {MatLegacySelectModule} from '@angular/material/legacy-select'; | ||
import {MatLegacyTooltipModule} from '@angular/material/legacy-tooltip'; | ||
import {TooltipAutoHideExample} from './tooltip-auto-hide/tooltip-auto-hide-example'; | ||
import {TooltipCustomClassExample} from './tooltip-custom-class/tooltip-custom-class-example'; | ||
import {TooltipDelayExample} from './tooltip-delay/tooltip-delay-example'; | ||
import {TooltipDisabledExample} from './tooltip-disabled/tooltip-disabled-example'; | ||
import {TooltipManualExample} from './tooltip-manual/tooltip-manual-example'; | ||
import {TooltipMessageExample} from './tooltip-message/tooltip-message-example'; | ||
import {TooltipModifiedDefaultsExample} from './tooltip-modified-defaults/tooltip-modified-defaults-example'; | ||
import {TooltipOverviewExample} from './tooltip-overview/tooltip-overview-example'; | ||
import {TooltipPositionExample} from './tooltip-position/tooltip-position-example'; | ||
import {TooltipPositionAtOriginExample} from './tooltip-position-at-origin/tooltip-position-at-origin-example'; | ||
import {TooltipHarnessExample} from './tooltip-harness/tooltip-harness-example'; | ||
|
||
export { | ||
TooltipAutoHideExample, | ||
TooltipCustomClassExample, | ||
TooltipDelayExample, | ||
TooltipDisabledExample, | ||
TooltipHarnessExample, | ||
TooltipManualExample, | ||
TooltipMessageExample, | ||
TooltipModifiedDefaultsExample, | ||
TooltipOverviewExample, | ||
TooltipPositionExample, | ||
TooltipPositionAtOriginExample, | ||
}; | ||
|
||
const EXAMPLES = [ | ||
TooltipAutoHideExample, | ||
TooltipCustomClassExample, | ||
TooltipDelayExample, | ||
TooltipDisabledExample, | ||
TooltipHarnessExample, | ||
TooltipManualExample, | ||
TooltipMessageExample, | ||
TooltipModifiedDefaultsExample, | ||
TooltipOverviewExample, | ||
TooltipPositionExample, | ||
TooltipPositionAtOriginExample, | ||
]; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
MatLegacyButtonModule, | ||
MatLegacyCheckboxModule, | ||
MatLegacyInputModule, | ||
MatLegacySelectModule, | ||
MatLegacyTooltipModule, | ||
ReactiveFormsModule, | ||
ScrollingModule, // Required for the auto-scrolling example | ||
], | ||
declarations: EXAMPLES, | ||
exports: EXAMPLES, | ||
}) | ||
export class TooltipExamplesModule {} |
10 changes: 10 additions & 0 deletions
10
...mponents-examples/material/legacy-tooltip/tooltip-auto-hide/tooltip-auto-hide-example.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.example-button { | ||
display: block; | ||
margin: 80px auto 400px; | ||
} | ||
|
||
.example-container { | ||
height: 200px; | ||
overflow: auto; | ||
border: 1px solid #ccc; | ||
} |
19 changes: 19 additions & 0 deletions
19
...ponents-examples/material/legacy-tooltip/tooltip-auto-hide/tooltip-auto-hide-example.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<mat-form-field appearance="fill"> | ||
<mat-label>Tooltip position</mat-label> | ||
<mat-select [formControl]="position"> | ||
<mat-option *ngFor="let positionOption of positionOptions" [value]="positionOption"> | ||
{{positionOption}} | ||
</mat-option> | ||
</mat-select> | ||
</mat-form-field> | ||
|
||
<div class="example-container" cdkScrollable> | ||
<button mat-raised-button #tooltip="matTooltip" | ||
matTooltip="Info about the action" | ||
[matTooltipPosition]="position.value!" | ||
matTooltipHideDelay="100000" | ||
aria-label="Button that displays a tooltip that hides when scrolled out of the container" | ||
class="example-button"> | ||
Action | ||
</button> | ||
</div> |
16 changes: 16 additions & 0 deletions
16
...omponents-examples/material/legacy-tooltip/tooltip-auto-hide/tooltip-auto-hide-example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {Component} from '@angular/core'; | ||
import {FormControl} from '@angular/forms'; | ||
import {TooltipPosition} from '@angular/material/legacy-tooltip'; | ||
|
||
/** | ||
* @title Tooltip that demonstrates auto-hiding when it clips out of its scrolling container. | ||
*/ | ||
@Component({ | ||
selector: 'tooltip-auto-hide-example', | ||
templateUrl: 'tooltip-auto-hide-example.html', | ||
styleUrls: ['tooltip-auto-hide-example.css'], | ||
}) | ||
export class TooltipAutoHideExample { | ||
positionOptions: TooltipPosition[] = ['below', 'above', 'left', 'right']; | ||
position = new FormControl(this.positionOptions[0]); | ||
} |
7 changes: 7 additions & 0 deletions
7
...ts-examples/material/legacy-tooltip/tooltip-custom-class/tooltip-custom-class-example.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.example-button { | ||
margin-top: 16px; | ||
} | ||
|
||
.example-tooltip-uppercase { | ||
text-transform: uppercase; | ||
} |
7 changes: 7 additions & 0 deletions
7
...s-examples/material/legacy-tooltip/tooltip-custom-class/tooltip-custom-class-example.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<button mat-raised-button | ||
matTooltip="Info about the action" | ||
matTooltipClass="example-tooltip-uppercase" | ||
aria-label="Button that shows a red tooltip" | ||
class="example-button"> | ||
Uppercase-tooltip Action | ||
</button> |
14 changes: 14 additions & 0 deletions
14
...nts-examples/material/legacy-tooltip/tooltip-custom-class/tooltip-custom-class-example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {Component, ViewEncapsulation} from '@angular/core'; | ||
|
||
/** | ||
* @title Tooltip that can have a custom class applied. | ||
*/ | ||
@Component({ | ||
selector: 'tooltip-custom-class-example', | ||
templateUrl: 'tooltip-custom-class-example.html', | ||
styleUrls: ['tooltip-custom-class-example.css'], | ||
// Need to remove view encapsulation so that the custom tooltip style defined in | ||
// `tooltip-custom-class-example.css` will not be scoped to this component's view. | ||
encapsulation: ViewEncapsulation.None, | ||
}) | ||
export class TooltipCustomClassExample {} |
4 changes: 4 additions & 0 deletions
4
src/components-examples/material/legacy-tooltip/tooltip-delay/tooltip-delay-example.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.mat-form-field + .mat-form-field, | ||
.mat-raised-button { | ||
margin-left: 8px; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/components-examples/material/legacy-tooltip/tooltip-delay/tooltip-delay-example.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<mat-form-field class="example-user-input" appearance="fill"> | ||
<mat-label>Show delay</mat-label> | ||
<input matInput type="number" [formControl]="showDelay" | ||
aria-label="Adds a delay between hovering over the button and displaying the tooltip"> | ||
<mat-hint>milliseconds</mat-hint> | ||
</mat-form-field> | ||
|
||
<mat-form-field class="example-user-input" appearance="fill"> | ||
<mat-label>Hide delay</mat-label> | ||
<input matInput type="number" [formControl]="hideDelay" | ||
aria-label="Adds a delay between hovering away from the button and hiding the tooltip"> | ||
<mat-hint>milliseconds</mat-hint> | ||
</mat-form-field> | ||
|
||
<button mat-raised-button matTooltip="Info about the action" | ||
[matTooltipShowDelay]="showDelay.value" | ||
[matTooltipHideDelay]="hideDelay.value" | ||
aria-label="Button that displays a tooltip with a customized delay in showing and hiding"> | ||
Action | ||
</button> |
15 changes: 15 additions & 0 deletions
15
src/components-examples/material/legacy-tooltip/tooltip-delay/tooltip-delay-example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {Component} from '@angular/core'; | ||
import {FormControl} from '@angular/forms'; | ||
|
||
/** | ||
* @title Tooltip with a show and hide delay | ||
*/ | ||
@Component({ | ||
selector: 'tooltip-delay-example', | ||
templateUrl: 'tooltip-delay-example.html', | ||
styleUrls: ['tooltip-delay-example.css'], | ||
}) | ||
export class TooltipDelayExample { | ||
showDelay = new FormControl(1000); | ||
hideDelay = new FormControl(2000); | ||
} |
3 changes: 3 additions & 0 deletions
3
...components-examples/material/legacy-tooltip/tooltip-disabled/tooltip-disabled-example.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.example-disabled-checkbox { | ||
margin-left: 8px; | ||
} |
10 changes: 10 additions & 0 deletions
10
...omponents-examples/material/legacy-tooltip/tooltip-disabled/tooltip-disabled-example.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<button mat-raised-button | ||
matTooltip="Info about the action" | ||
[matTooltipDisabled]="disabled.value" | ||
aria-label="Button that displays a tooltip that can be programmatically disabled"> | ||
Action | ||
</button> | ||
|
||
<mat-checkbox [formControl]="disabled" class="example-disabled-checkbox"> | ||
Tooltip disabled | ||
</mat-checkbox> |
14 changes: 14 additions & 0 deletions
14
src/components-examples/material/legacy-tooltip/tooltip-disabled/tooltip-disabled-example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {Component} from '@angular/core'; | ||
import {FormControl} from '@angular/forms'; | ||
|
||
/** | ||
* @title Tooltip that can be disabled | ||
*/ | ||
@Component({ | ||
selector: 'tooltip-disabled-example', | ||
templateUrl: 'tooltip-disabled-example.html', | ||
styleUrls: ['tooltip-disabled-example.css'], | ||
}) | ||
export class TooltipDisabledExample { | ||
disabled = new FormControl(false); | ||
} |
2 changes: 2 additions & 0 deletions
2
src/components-examples/material/legacy-tooltip/tooltip-harness/tooltip-harness-example.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<button [matTooltip]="message" id="one">Trigger 1</button> | ||
<button matTooltip="Static message" id="two">Trigger 2</button> |
54 changes: 54 additions & 0 deletions
54
...mponents-examples/material/legacy-tooltip/tooltip-harness/tooltip-harness-example.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import {ComponentFixture, TestBed} from '@angular/core/testing'; | ||
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed'; | ||
import {MatLegacyTooltipHarness} from '@angular/material/legacy-tooltip/testing'; | ||
import {HarnessLoader} from '@angular/cdk/testing'; | ||
import {MatLegacyTooltipModule} from '@angular/material/legacy-tooltip'; | ||
import {TooltipHarnessExample} from './tooltip-harness-example'; | ||
import {NoopAnimationsModule} from '@angular/platform-browser/animations'; | ||
|
||
describe('TooltipHarnessExample', () => { | ||
let fixture: ComponentFixture<TooltipHarnessExample>; | ||
let loader: HarnessLoader; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [MatLegacyTooltipModule, NoopAnimationsModule], | ||
declarations: [TooltipHarnessExample], | ||
}).compileComponents(); | ||
fixture = TestBed.createComponent(TooltipHarnessExample); | ||
fixture.detectChanges(); | ||
loader = TestbedHarnessEnvironment.loader(fixture); | ||
}); | ||
|
||
it('should load all tooltip harnesses', async () => { | ||
const tooltips = await loader.getAllHarnesses(MatLegacyTooltipHarness); | ||
expect(tooltips.length).toBe(2); | ||
}); | ||
|
||
it('should be able to show a tooltip', async () => { | ||
const tooltip = await loader.getHarness(MatLegacyTooltipHarness.with({selector: '#one'})); | ||
expect(await tooltip.isOpen()).toBe(false); | ||
await tooltip.show(); | ||
expect(await tooltip.isOpen()).toBe(true); | ||
}); | ||
|
||
it('should be able to hide a tooltip', async () => { | ||
const tooltip = await loader.getHarness(MatLegacyTooltipHarness.with({selector: '#one'})); | ||
expect(await tooltip.isOpen()).toBe(false); | ||
await tooltip.show(); | ||
expect(await tooltip.isOpen()).toBe(true); | ||
await tooltip.hide(); | ||
expect(await tooltip.isOpen()).toBe(false); | ||
}); | ||
|
||
it('should be able to get the text of a tooltip', async () => { | ||
const tooltip = await loader.getHarness(MatLegacyTooltipHarness.with({selector: '#one'})); | ||
await tooltip.show(); | ||
expect(await tooltip.getTooltipText()).toBe('Tooltip message'); | ||
}); | ||
|
||
it('should return empty when getting the tooltip text while closed', async () => { | ||
const tooltip = await loader.getHarness(MatLegacyTooltipHarness.with({selector: '#one'})); | ||
expect(await tooltip.getTooltipText()).toBe(''); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
src/components-examples/material/legacy-tooltip/tooltip-harness/tooltip-harness-example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {Component} from '@angular/core'; | ||
|
||
/** | ||
* @title Testing with MatTooltipHarness | ||
*/ | ||
@Component({ | ||
selector: 'tooltip-harness-example', | ||
templateUrl: 'tooltip-harness-example.html', | ||
}) | ||
export class TooltipHarnessExample { | ||
message = 'Tooltip message'; | ||
} |
3 changes: 3 additions & 0 deletions
3
src/components-examples/material/legacy-tooltip/tooltip-manual/tooltip-manual-example.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.example-action-button { | ||
margin-top: 16px; | ||
} |
28 changes: 28 additions & 0 deletions
28
src/components-examples/material/legacy-tooltip/tooltip-manual/tooltip-manual-example.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<div> | ||
<span> Click the following buttons to... </span> | ||
<button mat-button | ||
(click)="tooltip.show()" | ||
aria-label="Show tooltip on the button at the end of this section" | ||
class="example-action-button"> | ||
show | ||
</button> | ||
<button mat-button | ||
(click)="tooltip.hide()" | ||
aria-label="Hide tooltip on the button at the end of this section" | ||
class="example-action-button"> | ||
hide | ||
</button> | ||
<button mat-button | ||
(click)="tooltip.toggle()" | ||
aria-label="Show/Hide tooltip on the button at the end of this section" | ||
class="example-action-button"> | ||
toggle show/hide | ||
</button> | ||
</div> | ||
|
||
<button mat-raised-button #tooltip="matTooltip" | ||
matTooltip="Info about the action" | ||
matTooltipPosition="right" | ||
aria-tooltip="Button that displays and hides a tooltip triggered by other buttons"> | ||
Action | ||
</button> |
Oops, something went wrong.