Loading...
Loading...
ALWAYS use when working with Angular CDK (Component Dev Kit), building custom accessible components, or using drag-drop, overlay, portal, or virtual scrolling.
npx skill4agent add oguzhan18/angular-ecosystem-skills angular-cdkcdkTrapFocuscdkFocusRegionimport { OverlayModule } from '@angular/cdk/overlay';
import { PortalModule } from '@angular/cdk/portal';
@Component({
standalone: true,
imports: [OverlayModule, PortalModule],
// ...
})
export class CustomDropdownComponent {}import { OverlayRef, Overlay } from '@angular/cdk/overlay';
export class TooltipService {
private overlayRef: OverlayRef;
constructor(private overlay: Overlay) {
this.overlayRef = this.overlay.create({
hasBackdrop: true,
positionStrategy: this.overlay.position()
.connectedTo(origin, { originX: 'center', originY: 'bottom' })
.withOffsetX(0)
.withOffsetY(8)
});
}
}import { CdkDragDrop, moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop';
drop(event: CdkDragDrop<string[]>) {
if (event.previousContainer === event.container) {
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
} else {
transferArrayItem(
event.previousContainer.data,
event.container.data,
event.previousIndex,
event.currentIndex
);
}
}import { ScrollingModule } from '@angular/cdk/scrolling';
@Component({
standalone: true,
imports: [ScrollingModule],
template: `
<cdk-virtual-scroll-viewport itemSize="50" class="viewport">
<div *cdkVirtualFor="let item of items">{{item.name}}</div>
</cdk-virtual-scroll-viewport>
`
})
export class ListComponent {}import { DomPortalOutlet, TemplatePortal } from '@angular/cdk/portal';
@Component({ template: `<ng-template #dialogTemplate>Content</ng-template>` })
export class DialogComponent {
@ViewChild('dialogTemplate') dialogTemplate!: TemplatePortal;
attach() {
const portalOutlet = new DomPortalOutlet(this.document.body);
portalOutlet.attach(this.dialogTemplate);
}
}import { A11yModule, CdkTrapFocus, LiveAnnouncer } from '@angular/cdk/a11y';
@Component({
standalone: true,
imports: [A11yModule],
template: `
<div cdkTrapFocus>
<button cdkFocusInitial>First</button>
<button>Second</button>
</div>
`
})
export class AccessibleComponent {
constructor(private liveAnnouncer: LiveAnnouncer) {
this.liveAnnouncer.announce('Message for screen readers');
}
}import { LayoutModule } from '@angular/cdk/layout';
@Component({
standalone: true,
imports: [LayoutModule],
template: `
<div *ngIf="isHandset$ | async">
Mobile content
</div>
`
})
export class ResponsiveComponent {
isHandset$ = this.breakpointObserver.observe('(max-width: 599px)');
}