ng-auto-position 0.0.7 โ 0.0.8
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 +72 -71
- package/ng-auto-position-0.0.8.tgz +0 -0
- package/package.json +1 -1
- package/ng-auto-position-0.0.7.tgz +0 -0
package/README.md
CHANGED
|
@@ -1,30 +1,21 @@
|
|
|
1
1
|
# **ng-auto-position**
|
|
2
2
|
|
|
3
|
-

|
|
4
|
-

|
|
5
|
-
|
|
6
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.
|
|
7
4
|
|
|
8
5
|
This directive is designed for cases where **Angular CDK Overlay is too heavy**, but you still need **reliable, production-grade positioning**.
|
|
9
6
|
|
|
10
|
-
## ๐ด Live Demo
|
|
11
|
-
|
|
12
|
-
Try it directly in your browser:
|
|
13
|
-
|
|
14
|
-
๐ [https://ngautoposition-jysw--4200--31fc58ec.local-credentialless.webcontainer.io/](https://ngautoposition-jysw--4200--31fc58ec.local-credentialless.webcontainer.io/)
|
|
15
|
-
|
|
16
7
|
---
|
|
17
8
|
|
|
18
9
|
## **โจ Features**
|
|
19
10
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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.
|
|
28
19
|
|
|
29
20
|
---
|
|
30
21
|
|
|
@@ -40,9 +31,9 @@ npm install ng-auto-position
|
|
|
40
31
|
|
|
41
32
|
Apply the directive and provide the ID of the element it should anchor to.
|
|
42
33
|
|
|
43
|
-
HTML
|
|
34
|
+
HTML
|
|
44
35
|
|
|
45
|
-
```html
|
|
36
|
+
``` html
|
|
46
37
|
<div
|
|
47
38
|
class="flex flex-row"
|
|
48
39
|
style="
|
|
@@ -56,37 +47,43 @@ HTML
|
|
|
56
47
|
padding: 700px;
|
|
57
48
|
"
|
|
58
49
|
>
|
|
59
|
-
<div>
|
|
50
|
+
<div>
|
|
51
|
+
Lorem ipsum, dolor sit amet consectetur adipisicing elit.
|
|
52
|
+
</div>
|
|
60
53
|
<div style="height: fit-content">
|
|
61
|
-
<button style="padding: 4px; border: 2px solid" (click)="toggle()">
|
|
54
|
+
<button style="padding: 4px; border: 2px solid" (click)="toggle()">
|
|
55
|
+
Toggle
|
|
56
|
+
</button>
|
|
62
57
|
@if (show) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
<div
|
|
59
|
+
ngAutoPosition
|
|
60
|
+
style="
|
|
66
61
|
width: 200px;
|
|
67
62
|
height: 200px;
|
|
68
63
|
border: 1px solid;
|
|
69
64
|
background-color: white;
|
|
70
65
|
"
|
|
71
|
-
|
|
66
|
+
></div>
|
|
72
67
|
}
|
|
73
68
|
</div>
|
|
74
|
-
<div>
|
|
69
|
+
<div>
|
|
70
|
+
Lorem ipsum, dolor sit amet consectetur adipisicing elit.
|
|
71
|
+
</div>
|
|
75
72
|
</div>
|
|
76
73
|
```
|
|
77
74
|
|
|
78
75
|
Typescript
|
|
79
76
|
|
|
80
77
|
```typescript
|
|
81
|
-
import { NgAutoPositionElementDirective } from
|
|
82
|
-
import { CommonModule } from
|
|
83
|
-
import { Component } from
|
|
78
|
+
import { NgAutoPositionElementDirective } from '../ng-auto-position.directive';
|
|
79
|
+
import { CommonModule } from '@angular/common';
|
|
80
|
+
import { Component } from '@angular/core';
|
|
84
81
|
|
|
85
82
|
@Component({
|
|
86
|
-
selector:
|
|
83
|
+
selector: 'ng-auto-position-test',
|
|
87
84
|
standalone: true,
|
|
88
85
|
imports: [CommonModule, NgAutoPositionElementDirective],
|
|
89
|
-
templateUrl:
|
|
86
|
+
templateUrl: './ng-autoposition-test.component.html',
|
|
90
87
|
})
|
|
91
88
|
export class NgAutoPositionTestComponent {
|
|
92
89
|
show: boolean = false;
|
|
@@ -95,21 +92,22 @@ export class NgAutoPositionTestComponent {
|
|
|
95
92
|
this.show = !this.show;
|
|
96
93
|
}
|
|
97
94
|
}
|
|
95
|
+
|
|
98
96
|
```
|
|
99
97
|
|
|
100
98
|
---
|
|
101
99
|
|
|
102
100
|
## **โ๏ธ API Inputs**
|
|
103
101
|
|
|
104
|
-
| Input
|
|
105
|
-
|
|
|
106
|
-
| referenceElementId
|
|
107
|
-
| enableAutoReposition | boolean
|
|
108
|
-
| debounceMs
|
|
109
|
-
| offset
|
|
110
|
-
| matchWidth
|
|
111
|
-
| scrollableSelector
|
|
112
|
-
| hideScrollTargets
|
|
102
|
+
| Input | Type | Default | Description |
|
|
103
|
+
| :---- | :---- | :---- | :---- |
|
|
104
|
+
| referenceElementId | string | null | ID of the reference element. |
|
|
105
|
+
| enableAutoReposition | boolean | true | Reposition on window scroll & resize. |
|
|
106
|
+
| debounceMs | number | 0 | Debounce delay for scroll/resize events. |
|
|
107
|
+
| offset | number | 0 | Pixel gap between reference and popup. |
|
|
108
|
+
| matchWidth | boolean | false | Match popup width to reference element width. |
|
|
109
|
+
| scrollableSelector | string | null | Inner element selector to limit height/enable scroll. |
|
|
110
|
+
| hideScrollTargets | string[] | null | IDs or classes (e.g. ['body']) to hide scrollbars. |
|
|
113
111
|
|
|
114
112
|
---
|
|
115
113
|
|
|
@@ -119,25 +117,27 @@ export class NgAutoPositionTestComponent {
|
|
|
119
117
|
|
|
120
118
|
Automatically constrains height and enables internal scrolling if the viewport is too small.
|
|
121
119
|
|
|
122
|
-
HTML
|
|
120
|
+
HTML
|
|
123
121
|
|
|
124
|
-
```
|
|
122
|
+
```
|
|
125
123
|
<button id="actionsBtn">Actions</button>
|
|
126
124
|
|
|
127
|
-
<div
|
|
128
|
-
autoPositionElement
|
|
129
|
-
referenceElementId="actionsBtn"
|
|
130
|
-
scrollableSelector=".menu-items"
|
|
131
|
-
class="dropdown"
|
|
132
|
-
|
|
125
|
+
<div
|
|
126
|
+
autoPositionElement
|
|
127
|
+
referenceElementId="actionsBtn"
|
|
128
|
+
scrollableSelector=".menu-items"
|
|
129
|
+
class="dropdown"
|
|
130
|
+
>
|
|
131
|
+
<div class="menu-items">
|
|
132
|
+
</div>
|
|
133
133
|
</div>
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
-
CSS
|
|
136
|
+
CSS
|
|
137
137
|
|
|
138
138
|
```css
|
|
139
|
-
.menu-items {
|
|
140
|
-
overflow-y: auto;
|
|
139
|
+
.menu-items {
|
|
140
|
+
overflow-y: auto;
|
|
141
141
|
}
|
|
142
142
|
```
|
|
143
143
|
|
|
@@ -145,15 +145,16 @@ CSS
|
|
|
145
145
|
|
|
146
146
|
Prevents the user from scrolling the background while the popup is active.
|
|
147
147
|
|
|
148
|
-
HTML
|
|
148
|
+
HTML
|
|
149
149
|
|
|
150
150
|
```html
|
|
151
|
-
<div
|
|
152
|
-
autoPositionElement
|
|
153
|
-
referenceElementId="menuBtn"
|
|
154
|
-
[hideScrollTargets]="['body', '.layout-container']"
|
|
155
|
-
class="dropdown"
|
|
156
|
-
|
|
151
|
+
<div
|
|
152
|
+
autoPositionElement
|
|
153
|
+
referenceElementId="menuBtn"
|
|
154
|
+
[hideScrollTargets]="['body', '.layout-container']"
|
|
155
|
+
class="dropdown"
|
|
156
|
+
>
|
|
157
|
+
Menu content
|
|
157
158
|
</div>
|
|
158
159
|
```
|
|
159
160
|
|
|
@@ -161,29 +162,29 @@ HTML
|
|
|
161
162
|
|
|
162
163
|
## **๐ง Positioning Behavior Explained**
|
|
163
164
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
165
|
+
* **Reference is fully visible**: Popup is clamped to the viewport to prevent overflow on all sides.
|
|
166
|
+
* **Reference is partially visible**: Popup remains visible and clamped to the viewport.
|
|
167
|
+
* **Reference is outside viewport**: Popup moves with the reference and can go fully off-screen. It never "freezes" or sticks in mid-air.
|
|
167
168
|
|
|
168
169
|
---
|
|
169
170
|
|
|
170
171
|
## **๐งช Angular Compatibility**
|
|
171
172
|
|
|
172
173
|
| Angular Version | Supported |
|
|
173
|
-
|
|
|
174
|
-
| 16+
|
|
174
|
+
| :---- | :---- |
|
|
175
|
+
| 16+ | โ
|
|
|
175
176
|
|
|
176
177
|
### **Standalone Import Example**
|
|
177
178
|
|
|
178
|
-
TypeScript
|
|
179
|
+
TypeScript
|
|
179
180
|
|
|
180
181
|
```typescript
|
|
181
|
-
import { AutoPositionElementDirective } from
|
|
182
|
+
import { AutoPositionElementDirective } from '@roshan-ng/ng-auto-position';
|
|
182
183
|
|
|
183
|
-
@Component({
|
|
184
|
-
standalone: true,
|
|
185
|
-
imports: [AutoPositionElementDirective],
|
|
186
|
-
})
|
|
184
|
+
@Component({
|
|
185
|
+
standalone: true,
|
|
186
|
+
imports: [AutoPositionElementDirective],
|
|
187
|
+
})
|
|
187
188
|
export class DemoComponent {}
|
|
188
189
|
```
|
|
189
190
|
|
|
@@ -195,5 +196,5 @@ MIT ยฉ Roshan
|
|
|
195
196
|
|
|
196
197
|
## **๐ Links**
|
|
197
198
|
|
|
198
|
-
|
|
199
|
-
|
|
199
|
+
* **npm**: [https://www.npmjs.com/package/ng-auto-position](https://www.npmjs.com/package/@roshan-ng/ng-auto-position)
|
|
200
|
+
* **GitHub**: [https://github.com/roshan2197/ng-auto-position](https://github.com/roshan/ng-auto-position)
|
|
Binary file
|
package/package.json
CHANGED
|
Binary file
|