Interactions
The Move primitives enable pointer and keyboard move interactions on an element.
import { Component, signal } from "@angular/core";
import { NgpMove, NgpMoveEvent } from "ng-primitives/interactions";
@Component({
selector: "app-move",
imports: [NgpMove],
template: `
<div
[style.left.px]="x()"
[style.top.px]="y()"
(ngpMove)="onMove($event)"
tabindex="0"
>
Move me!
</div>
`,
styles: `
div {
padding: 1rem;
border-radius: 0.5rem;
color: var(--ngp-text-primary);
border: 1px solid var(--ngp-border);
font-weight: 500;
background-color: var(--ngp-background);
box-shadow: none;
cursor: move;
user-select: none;
touch-action: none;
position: absolute;
width: 100px;
height: 100px;
display: flex;
justify-content: center;
align-items: center;
outline: none;
}
div:focus-visible {
outline: 2px solid var(--ngp-focus-ring);
}
div[data-move] {
box-shadow: var(--ngp-button-shadow);
}
`,
})
export default class MoveExample {
readonly x = signal<number>(60);
readonly y = signal<number>(60);
onMove(event: NgpMoveEvent) {
this.x.update((x) => x + event.deltaX);
this.y.update((y) => y + event.deltaY);
}
}
Import the Move primitives from ng-primitives/interactions
.
import { NgpMove } from 'ng-primitives/interactions';
Assemble the move directives in your template.
<div (ngpMove)="onMove($event)"></div>
The following directives are available to import from the ng-primitives/interactions
package:
The `NgpMove` directive is used to enable the pointer and keyboard move interactions on an element. Whether movement is disabled.
Emit when the move event begins.
Emit when the element is moved.
Emit when the move event ends.
[ngpMove]
ngpMove
The following data attributes are available to use with the NgpMove
directive:
Attribute | Description |
---|---|
data-move |
Applied when the element is being moved. |
Copyright © 2025 Angular Primitives