ng-auto-position 0.0.0 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +167 -14
- package/ng-auto-position-0.0.2.tgz +0 -0
- package/package.json +37 -1
- package/ng-auto-position-0.0.0.tgz +0 -0
package/README.md
CHANGED
|
@@ -1,27 +1,180 @@
|
|
|
1
|
-
#
|
|
1
|
+
# **ng-auto-position**
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A lightweight **Angular standalone directive** that automatically positions dropdowns, popovers, and floating panels relative to a reference element, while correctly handling scrolling, resizing, viewport boundaries, and scroll locking.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This directive is designed for cases where **Angular CDK Overlay is too heavy**, but you still need **reliable, production-grade positioning**.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
---
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## **✨ Features**
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
- ✅ **Smart Positioning**: Auto positions popup **above or below** a reference element.
|
|
12
|
+
- ✅ **Dynamic Tracking**: Popup **follows the reference** while scrolling (no freezing).
|
|
13
|
+
- ✅ **Boundary Detection**: Viewport clamping when the reference is visible.
|
|
14
|
+
- ✅ **Natural Exit**: Popup moves out of viewport when the reference fully leaves.
|
|
15
|
+
- ✅ **Responsive**: Optional repositioning on scroll & resize.
|
|
16
|
+
- ✅ **Layout Sync**: Optional width matching with reference element.
|
|
17
|
+
- ✅ **UX Control**: Optional background scroll locking and internal scroll handling.
|
|
18
|
+
- ✅ **Modern**: Standalone directive (Angular 16+), no Angular CDK dependency.
|
|
12
19
|
|
|
13
|
-
|
|
20
|
+
---
|
|
14
21
|
|
|
15
|
-
|
|
22
|
+
## **📦 Installation**
|
|
16
23
|
|
|
17
|
-
|
|
24
|
+
npm install ng-auto-position
|
|
18
25
|
|
|
19
|
-
|
|
26
|
+
---
|
|
20
27
|
|
|
21
|
-
##
|
|
28
|
+
## **📌 Basic Usage**
|
|
22
29
|
|
|
23
|
-
|
|
30
|
+
### **1\. Component Template**
|
|
24
31
|
|
|
25
|
-
|
|
32
|
+
Apply the directive and provide the ID of the element it should anchor to.
|
|
26
33
|
|
|
27
|
-
|
|
34
|
+
HTML
|
|
35
|
+
|
|
36
|
+
```html
|
|
37
|
+
<div
|
|
38
|
+
class="flex flex-row"
|
|
39
|
+
style="
|
|
40
|
+
display: flex;
|
|
41
|
+
flex-direction: column;
|
|
42
|
+
position: relative;
|
|
43
|
+
left: 100vw;
|
|
44
|
+
top: 100vh;
|
|
45
|
+
height: 100vh;
|
|
46
|
+
width: 200vw;
|
|
47
|
+
padding: 700px;
|
|
48
|
+
"
|
|
49
|
+
>
|
|
50
|
+
<div>Lorem ipsum, dolor sit amet consectetur adipisicing elit.</div>
|
|
51
|
+
<div style="height: fit-content">
|
|
52
|
+
<button style="padding: 4px; border: 2px solid" (click)="toggle()">Toggle</button>
|
|
53
|
+
@if (show) {
|
|
54
|
+
<div
|
|
55
|
+
ngAutoPosition
|
|
56
|
+
style="
|
|
57
|
+
width: 200px;
|
|
58
|
+
height: 200px;
|
|
59
|
+
border: 1px solid;
|
|
60
|
+
background-color: white;
|
|
61
|
+
"
|
|
62
|
+
></div>
|
|
63
|
+
}
|
|
64
|
+
</div>
|
|
65
|
+
<div>Lorem ipsum, dolor sit amet consectetur adipisicing elit.</div>
|
|
66
|
+
</div>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Typescript
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { NgAutoPositionElementDirective } from "../ng-auto-position.directive";
|
|
73
|
+
import { CommonModule } from "@angular/common";
|
|
74
|
+
import { Component } from "@angular/core";
|
|
75
|
+
|
|
76
|
+
@Component({
|
|
77
|
+
selector: "ng-auto-position-test",
|
|
78
|
+
standalone: true,
|
|
79
|
+
imports: [CommonModule, NgAutoPositionElementDirective],
|
|
80
|
+
templateUrl: "./ng-autoposition-test.component.html",
|
|
81
|
+
})
|
|
82
|
+
export class NgAutoPositionTestComponent {
|
|
83
|
+
show: boolean = false;
|
|
84
|
+
|
|
85
|
+
toggle() {
|
|
86
|
+
this.show = !this.show;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## **⚙️ API Inputs**
|
|
94
|
+
|
|
95
|
+
| Input | Type | Default | Description |
|
|
96
|
+
| :------------------- | :------- | :------ | :---------------------------------------------------- |
|
|
97
|
+
| referenceElementId | string | null | ID of the reference element. |
|
|
98
|
+
| enableAutoReposition | boolean | true | Reposition on window scroll & resize. |
|
|
99
|
+
| debounceMs | number | 0 | Debounce delay for scroll/resize events. |
|
|
100
|
+
| offset | number | 0 | Pixel gap between reference and popup. |
|
|
101
|
+
| matchWidth | boolean | false | Match popup width to reference element width. |
|
|
102
|
+
| scrollableSelector | string | null | Inner element selector to limit height/enable scroll. |
|
|
103
|
+
| hideScrollTargets | string[] | null | IDs or classes (e.g. ['body']) to hide scrollbars. |
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## **🧩 Advanced Examples**
|
|
108
|
+
|
|
109
|
+
### **1\. Dropdown with internal scrolling**
|
|
110
|
+
|
|
111
|
+
Automatically constrains height and enables internal scrolling if the viewport is too small.
|
|
112
|
+
|
|
113
|
+
HTML
|
|
114
|
+
|
|
115
|
+
```html
|
|
116
|
+
<button id="actionsBtn">Actions</button>
|
|
117
|
+
|
|
118
|
+
<div autoPositionElement referenceElementId="actionsBtn" scrollableSelector=".menu-items" class="dropdown">
|
|
119
|
+
<div class="menu-items"></div>
|
|
120
|
+
</div>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
CSS
|
|
124
|
+
|
|
125
|
+
```css
|
|
126
|
+
.menu-items {
|
|
127
|
+
overflow-y: auto;
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### **2\. Lock background scrolling**
|
|
132
|
+
|
|
133
|
+
Prevents the user from scrolling the background while the popup is active.
|
|
134
|
+
|
|
135
|
+
HTML
|
|
136
|
+
|
|
137
|
+
```html
|
|
138
|
+
<div autoPositionElement referenceElementId="menuBtn" [hideScrollTargets]="['body', '.layout-container']" class="dropdown">Menu content</div>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## **🧠 Positioning Behavior Explained**
|
|
144
|
+
|
|
145
|
+
- **Reference is fully visible**: Popup is clamped to the viewport to prevent overflow on all sides.
|
|
146
|
+
- **Reference is partially visible**: Popup remains visible and clamped to the viewport.
|
|
147
|
+
- **Reference is outside viewport**: Popup moves with the reference and can go fully off-screen. It never "freezes" or sticks in mid-air.
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## **🧪 Angular Compatibility**
|
|
152
|
+
|
|
153
|
+
| Angular Version | Supported |
|
|
154
|
+
| :-------------- | :-------- |
|
|
155
|
+
| 16+ | ✅ |
|
|
156
|
+
|
|
157
|
+
### **Standalone Import Example**
|
|
158
|
+
|
|
159
|
+
TypeScript
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
import { AutoPositionElementDirective } from "@roshan-ng/ng-auto-position";
|
|
163
|
+
|
|
164
|
+
@Component({
|
|
165
|
+
standalone: true,
|
|
166
|
+
imports: [AutoPositionElementDirective],
|
|
167
|
+
})
|
|
168
|
+
export class DemoComponent {}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## **📄 License**
|
|
174
|
+
|
|
175
|
+
MIT © Roshan
|
|
176
|
+
|
|
177
|
+
## **🔗 Links**
|
|
178
|
+
|
|
179
|
+
- **npm**: [https://www.npmjs.com/package/ng-auto-position](https://www.npmjs.com/package/@roshan-ng/ng-auto-position)
|
|
180
|
+
- **GitHub**: [https://github.com/roshan2197/ng-auto-position](https://github.com/roshan/ng-auto-position)
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ng-auto-position",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Angular directive for auto positioning dropdowns and popovers",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@angular/animations": "^17.3.0",
|
|
@@ -16,6 +16,42 @@
|
|
|
16
16
|
"tslib": "^2.3.0",
|
|
17
17
|
"zone.js": "~0.14.3"
|
|
18
18
|
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"angular",
|
|
21
|
+
"angular-ui",
|
|
22
|
+
"angular-directive",
|
|
23
|
+
"angular-standalone",
|
|
24
|
+
"angular16",
|
|
25
|
+
"angular17",
|
|
26
|
+
"angular18",
|
|
27
|
+
"dropdown",
|
|
28
|
+
"popover",
|
|
29
|
+
"tooltip",
|
|
30
|
+
"menu",
|
|
31
|
+
"context-menu",
|
|
32
|
+
"popup",
|
|
33
|
+
"overlay",
|
|
34
|
+
"floating",
|
|
35
|
+
"floating-ui",
|
|
36
|
+
"auto-position",
|
|
37
|
+
"positioning",
|
|
38
|
+
"smart-positioning",
|
|
39
|
+
"viewport",
|
|
40
|
+
"scroll-aware",
|
|
41
|
+
"responsive-ui",
|
|
42
|
+
"cdk-alternative",
|
|
43
|
+
"no-cdk",
|
|
44
|
+
"lightweight",
|
|
45
|
+
"standalone-directive",
|
|
46
|
+
"frontend",
|
|
47
|
+
"ui",
|
|
48
|
+
"ux"
|
|
49
|
+
],
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "https://github.com/roshan2197/ng-auto-position"
|
|
53
|
+
},
|
|
54
|
+
"homepage": "https://github.com/roshan2197/ng-auto-position",
|
|
19
55
|
"module": "fesm2022/ng-auto-position.mjs",
|
|
20
56
|
"typings": "index.d.ts",
|
|
21
57
|
"exports": {
|
|
Binary file
|