@nectary/components 0.41.0 → 0.41.1
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/package.json +1 -1
- package/pop/index.js +45 -7
package/package.json
CHANGED
package/pop/index.js
CHANGED
|
@@ -19,6 +19,7 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
19
19
|
#controller = null;
|
|
20
20
|
#keydownContext;
|
|
21
21
|
#visibilityContext;
|
|
22
|
+
#targetStyleValue = null;
|
|
22
23
|
|
|
23
24
|
constructor() {
|
|
24
25
|
super();
|
|
@@ -155,7 +156,11 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
155
156
|
}
|
|
156
157
|
|
|
157
158
|
#getTargetRect() {
|
|
158
|
-
|
|
159
|
+
let item = getFirstSlotElement(this.#$targetSlot, true);
|
|
160
|
+
|
|
161
|
+
if (item === null && this.#isOpen()) {
|
|
162
|
+
item = getFirstSlotElement(this.#$targetOpenSlot, true);
|
|
163
|
+
}
|
|
159
164
|
|
|
160
165
|
if (item === null) {
|
|
161
166
|
return getRect(this.#$target);
|
|
@@ -168,6 +173,16 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
168
173
|
return getRect(item);
|
|
169
174
|
}
|
|
170
175
|
|
|
176
|
+
#getFirstTargetElement(slot) {
|
|
177
|
+
const item = getFirstSlotElement(slot, true);
|
|
178
|
+
|
|
179
|
+
if (item === null) {
|
|
180
|
+
return this.#$target;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return item;
|
|
184
|
+
}
|
|
185
|
+
|
|
171
186
|
#onExpand() {
|
|
172
187
|
if (!this.#isConnected || this.#isOpen()) {
|
|
173
188
|
return;
|
|
@@ -187,14 +202,27 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
187
202
|
if (this.modal) {
|
|
188
203
|
getFirstFocusableElement(this.#$contentSlot)?.focus();
|
|
189
204
|
} else {
|
|
205
|
+
const $targetEl = this.#getFirstTargetElement(this.#$targetSlot);
|
|
206
|
+
const targetElComputedStyle = getComputedStyle($targetEl);
|
|
207
|
+
const marginLeft = parseInt(targetElComputedStyle.marginLeft);
|
|
208
|
+
const marginRight = parseInt(targetElComputedStyle.marginRight);
|
|
209
|
+
const marginTop = parseInt(targetElComputedStyle.marginTop);
|
|
210
|
+
const marginBottom = parseInt(targetElComputedStyle.marginBottom);
|
|
190
211
|
const targetRect = this.#getTargetRect();
|
|
191
|
-
const widthPx = `${targetRect.width}px`;
|
|
192
|
-
const heightPx = `${targetRect.height}px`;
|
|
193
212
|
this.#$target.style.setProperty('display', 'block');
|
|
194
|
-
this.#$target.style.setProperty('width',
|
|
195
|
-
this.#$target.style.setProperty('height',
|
|
196
|
-
this.#$targetOpenWrapper.style.setProperty('width',
|
|
197
|
-
this.#$targetOpenWrapper.style.setProperty('height',
|
|
213
|
+
this.#$target.style.setProperty('width', `${targetRect.width + marginLeft + marginRight}px`);
|
|
214
|
+
this.#$target.style.setProperty('height', `${targetRect.height + marginTop + marginBottom}px`);
|
|
215
|
+
this.#$targetOpenWrapper.style.setProperty('width', `${targetRect.width}px`);
|
|
216
|
+
this.#$targetOpenWrapper.style.setProperty('height', `${targetRect.height}px`);
|
|
217
|
+
this.#targetStyleValue = $targetEl.getAttribute('style');
|
|
218
|
+
$targetEl.style.setProperty('margin', '0');
|
|
219
|
+
$targetEl.style.setProperty('position', 'static');
|
|
220
|
+
|
|
221
|
+
if (targetElComputedStyle.transform !== 'none') {
|
|
222
|
+
const matrix = new DOMMatrixReadOnly(targetElComputedStyle.transform);
|
|
223
|
+
$targetEl.style.setProperty('transform', matrix.translate(-matrix.e, -matrix.f).toString());
|
|
224
|
+
}
|
|
225
|
+
|
|
198
226
|
getFirstSlotElement(this.#$targetSlot)?.setAttribute('slot', 'target-open');
|
|
199
227
|
this.#$targetOpenSlot.addEventListener('keydown', this.#onTargetKeydown);
|
|
200
228
|
|
|
@@ -238,6 +266,16 @@ defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
|
238
266
|
this.#$targetOpenSlot.removeEventListener('blur', this.#captureActiveElement, true);
|
|
239
267
|
}
|
|
240
268
|
|
|
269
|
+
const targetEl = this.#getFirstTargetElement(this.#$targetOpenSlot);
|
|
270
|
+
targetEl.style.removeProperty('margin');
|
|
271
|
+
targetEl.style.removeProperty('position');
|
|
272
|
+
targetEl.style.removeProperty('transform');
|
|
273
|
+
|
|
274
|
+
if (this.#targetStyleValue !== null) {
|
|
275
|
+
targetEl.setAttribute('style', this.#targetStyleValue);
|
|
276
|
+
this.#targetStyleValue = null;
|
|
277
|
+
}
|
|
278
|
+
|
|
241
279
|
getFirstSlotElement(this.#$targetOpenSlot)?.setAttribute('slot', 'target');
|
|
242
280
|
this.#$target.style.removeProperty('display');
|
|
243
281
|
this.#$target.style.removeProperty('width');
|