@txstate-mws/svelte-components 1.5.1 → 1.5.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/dist/components/PopupMenu.svelte +16 -1
- package/dist/util/util.d.ts +1 -0
- package/dist/util/util.js +15 -0
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ import { isNotBlank, randomid } from 'txstate-utils';
|
|
|
7
7
|
import { Store } from '@txstate-mws/svelte-store';
|
|
8
8
|
import { glue, portal } from '../actions';
|
|
9
9
|
import ScreenReaderOnly from './ScreenReaderOnly.svelte';
|
|
10
|
-
import { modifierKey } from '../util';
|
|
10
|
+
import { getScrollParents, modifierKey } from '../util';
|
|
11
11
|
const dispatch = createEventDispatcher();
|
|
12
12
|
/** The DOM element that will act as the "button" for this menu. The menu will be placed next to the
|
|
13
13
|
button and be controlled by the button. Keyboard access will be enabled when the button has focus.
|
|
@@ -201,6 +201,9 @@ async function onblur(e) {
|
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
function cleanup(element) {
|
|
204
|
+
for (const observer of observers)
|
|
205
|
+
observer.disconnect();
|
|
206
|
+
observers = [];
|
|
204
207
|
if (element) {
|
|
205
208
|
element.removeEventListener('click', onbuttonclick);
|
|
206
209
|
element.removeEventListener('keydown', onkeydown);
|
|
@@ -215,6 +218,7 @@ function cleanup(element) {
|
|
|
215
218
|
onDestroy(() => cleanup(buttonelement));
|
|
216
219
|
// if buttonelement changes we need to handle listeners and aria
|
|
217
220
|
let lastbuttonelement;
|
|
221
|
+
let observers = [];
|
|
218
222
|
function reactToButtonElement(buttonelement) {
|
|
219
223
|
cleanup(lastbuttonelement);
|
|
220
224
|
lastbuttonelement = buttonelement;
|
|
@@ -223,6 +227,17 @@ function reactToButtonElement(buttonelement) {
|
|
|
223
227
|
buttonelement.addEventListener('click', onbuttonclick);
|
|
224
228
|
buttonelement.addEventListener('keydown', onkeydown);
|
|
225
229
|
buttonelement.addEventListener('blur', onblur);
|
|
230
|
+
const parents = getScrollParents(buttonelement);
|
|
231
|
+
for (const parent of [...parents, undefined]) {
|
|
232
|
+
const observer = new IntersectionObserver((entries) => {
|
|
233
|
+
for (const entry of entries) {
|
|
234
|
+
if (entry.intersectionRatio < 1)
|
|
235
|
+
menushown = false;
|
|
236
|
+
}
|
|
237
|
+
}, { root: parent, threshold: 1 });
|
|
238
|
+
observer.observe(buttonelement);
|
|
239
|
+
observers.push(observer);
|
|
240
|
+
}
|
|
226
241
|
}
|
|
227
242
|
}
|
|
228
243
|
$: reactToButtonElement(buttonelement);
|
package/dist/util/util.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export declare function classes(...classNames: (string | undefined)[]): string;
|
|
|
2
2
|
export declare function debounced(fn: (..._: any[]) => any, timeout: number): (...args: any[]) => void;
|
|
3
3
|
export declare function modifierKey(e: any): any;
|
|
4
4
|
export declare function selectionIsLeft(ele: HTMLInputElement | HTMLTextAreaElement): boolean;
|
|
5
|
+
export declare function getScrollParents(element: HTMLElement): any;
|
package/dist/util/util.js
CHANGED
|
@@ -14,3 +14,18 @@ export function modifierKey(e) {
|
|
|
14
14
|
export function selectionIsLeft(ele) {
|
|
15
15
|
return ele.selectionStart === 0 && ele.selectionEnd === 0;
|
|
16
16
|
}
|
|
17
|
+
export function getScrollParents(element) {
|
|
18
|
+
let style = getComputedStyle(element);
|
|
19
|
+
const excludeStaticParent = style.position === 'absolute';
|
|
20
|
+
if (style.position === 'fixed')
|
|
21
|
+
return [document.body];
|
|
22
|
+
for (let parent = element; (parent = parent.parentElement);) {
|
|
23
|
+
style = getComputedStyle(parent);
|
|
24
|
+
if (excludeStaticParent && style.position === 'static') {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (/(auto|scroll|hidden)/.test(style.overflow + style.overflowY + style.overflowX))
|
|
28
|
+
return [parent, ...getScrollParents(parent)];
|
|
29
|
+
}
|
|
30
|
+
return [document.body];
|
|
31
|
+
}
|