Skip to content

Commit 66d0f2d

Browse files
authored
build: minor improvement to dev app density toggling (#28571)
Fixes a minor gripe where the density tooltip closes when the button is pressed so the user needs to re-focus to see which density is currently active.
1 parent 4f518f9 commit 66d0f2d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/dev-app/dev-app/dev-app-layout.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ <h1>Angular Material Demos</h1>
120120
}
121121
</button>
122122
<button
123+
#densityTooltip="matTooltip"
123124
mat-icon-button
124-
(click)="toggleDensity()"
125+
(click)="toggleDensity(undefined, densityTooltip)"
125126
[matTooltip]="'Density: ' + state.density">
126127
<mat-icon>grid_on</mat-icon>
127128
</button>

src/dev-app/dev-app/dev-app-layout.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {MatButtonModule} from '@angular/material/button';
1515
import {RouterModule} from '@angular/router';
1616
import {MatIconModule, MatIconRegistry} from '@angular/material/icon';
1717
import {MatToolbarModule} from '@angular/material/toolbar';
18-
import {MatTooltipModule} from '@angular/material/tooltip';
18+
import {MatTooltip, MatTooltipModule} from '@angular/material/tooltip';
1919
import {DevAppDirectionality} from './dev-app-directionality';
2020
import {DevAppRippleOptions} from './ripple-options';
2121
import {getAppState, setAppState} from './dev-app-state';
@@ -143,13 +143,19 @@ export class DevAppLayout {
143143
location.reload();
144144
}
145145

146-
toggleDensity(index?: number) {
146+
toggleDensity(index?: number, tooltipInstance?: MatTooltip) {
147147
if (index == null) {
148148
index = (this._densityScales.indexOf(this.state.density) + 1) % this._densityScales.length;
149149
}
150150

151151
this.state.density = this._densityScales[index];
152152
setAppState(this.state);
153+
154+
// Keep the tooltip open so we can see what the density was changed to. Ideally we'd
155+
// always show the density in a badge, but the M2 badge is too large for the toolbar.
156+
if (tooltipInstance) {
157+
requestAnimationFrame(() => tooltipInstance.show(0));
158+
}
153159
}
154160

155161
toggleRippleDisabled(value = !this.state.rippleDisabled) {

0 commit comments

Comments
 (0)