Skip to content

Commit ee003d2

Browse files
authored
docs: prevent aria banner from showing up on Material (#32421)
The banner for Angular Aria was showing up for Material as well, because we weren't checking the package name. These changes also fix some minor issues like using an inline SVG instead of `mat-icon`. Fixes #32420.
1 parent a00b489 commit ee003d2

File tree

5 files changed

+30
-26
lines changed

5 files changed

+30
-26
lines changed

docs/src/app/pages/component-viewer/component-overview.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
<h2 class="cdk-visually-hidden" tabindex="-1">
33
Overview for {{docItem.id}}
44
</h2>
5-
<doc-viewer [name]="docItem.id"
5+
<doc-viewer
6+
[name]="docItem.id"
7+
[packageName]="docItem.packageName"
68
[document]="getOverviewDocumentUrl(docItem)"
79
class="docs-component-view-text-content docs-component-overview"
810
(contentRendered)="updateTableOfContents('Overview Content', $event)" />

docs/src/app/shared/doc-viewer/angular-aria-banner/angular-aria-banner.css

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,36 @@
1111
line-height: 1.6;
1212
}
1313

14-
.docs-angular-aria-banner-icon {
15-
font-size: 20px;
14+
mat-icon {
1615
flex-shrink: 0;
17-
fill: var(--mat-sys-primary);
16+
color: var(--mat-sys-primary);
1817
}
1918

2019
.docs-angular-aria-banner-content {
2120
flex: 1;
2221
}
2322

24-
.docs-angular-aria-banner-content strong {
23+
strong {
2524
color: var(--mat-sys-primary);
2625
}
2726

28-
.docs-angular-aria-banner-content a {
27+
a {
2928
color: var(--mat-sys-primary);
3029
text-decoration: underline;
3130
font-weight: 500;
3231
}
3332

33+
p {
34+
margin: 0;
35+
}
36+
3437
@media (max-width: 600px) {
3538
.docs-angular-aria-banner {
3639
padding: 12px;
3740
gap: 8px;
3841
}
3942

40-
.docs-angular-aria-banner-icon {
43+
mat-icon {
4144
font-size: 18px;
4245
}
4346
}
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
<div class="docs-angular-aria-banner">
2-
<svg class="docs-angular-aria-banner-icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24"
3-
width="24px">
4-
<path d="M0 0h24v24H0V0z" fill="none" />
5-
<path
6-
d="M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z" />
7-
</svg>
2+
<mat-icon>info</mat-icon>
3+
84
<div class="docs-angular-aria-banner-content">
95
<strong>Now Available in Angular Aria!</strong>
10-
<br />
11-
The Angular team has introduced a new low-level component library called Angular Aria.
12-
Consider using the
13-
<a [href]="ariaLink" target="_blank" rel="noopener">Angular Aria {{ componentName }}</a>
14-
component as an alternative to this CDK component.
6+
<p>
7+
The Angular team has introduced a new low-level component library called Angular Aria.
8+
Consider using the
9+
<a [href]="ariaLink" target="_blank" rel="noopener">Angular Aria {{ componentName }}</a>
10+
component as an alternative to this CDK component.
11+
</p>
1512
</div>
1613
</div>

docs/src/app/shared/doc-viewer/angular-aria-banner/angular-aria-banner.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import {Component, Input} from '@angular/core';
10+
import {MatIcon} from '@angular/material/icon';
1011

1112
/**
1213
* Mapping of CDK component names to their Angular Aria documentation URLs.
@@ -26,6 +27,7 @@ const ANGULAR_ARIA_LINKS: Record<string, string> = {
2627
selector: 'angular-aria-banner',
2728
templateUrl: 'angular-aria-banner.html',
2829
styleUrl: 'angular-aria-banner.css',
30+
imports: [MatIcon],
2931
})
3032
export class AngularAriaBanner {
3133
@Input() componentName: string = '';

docs/src/app/shared/doc-viewer/doc-viewer.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export class DocViewer implements OnDestroy {
8181
protected portal: Portal<any> | undefined;
8282

8383
readonly name = input<string>();
84+
readonly packageName = input<string>();
8485

8586
/** The document to display, either as a URL to a markdown file or a component to create. */
8687
@Input()
@@ -277,9 +278,13 @@ export class DocViewer implements OnDestroy {
277278
*/
278279
private _injectAngularAriaBanner() {
279280
const componentName = this.name();
280-
const componentsWithAriaBanner = ['listbox', 'tree', 'accordion', 'menu'];
281+
const packageName = this.packageName();
281282

282-
if (!componentName || !componentsWithAriaBanner.includes(componentName.toLowerCase())) {
283+
if (
284+
!componentName ||
285+
packageName !== 'cdk' ||
286+
!['listbox', 'tree', 'accordion', 'menu'].includes(componentName.toLowerCase())
287+
) {
283288
return;
284289
}
285290

@@ -289,12 +294,7 @@ export class DocViewer implements OnDestroy {
289294
bannerContainer.setAttribute('componentName', componentName);
290295

291296
// Insert the banner at the beginning of the document content
292-
const firstChild = this._elementRef.nativeElement.firstChild;
293-
if (firstChild) {
294-
this._elementRef.nativeElement.insertBefore(bannerContainer, firstChild);
295-
} else {
296-
this._elementRef.nativeElement.appendChild(bannerContainer);
297-
}
297+
this._elementRef.nativeElement.prepend(bannerContainer);
298298

299299
// Create and attach the banner component
300300
const portalHost = new DomPortalOutlet(bannerContainer, this._appRef, this._injector);

0 commit comments

Comments
 (0)