@txstate-mws/svelte-components 1.5.0 → 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.
@@ -79,7 +79,7 @@ export function glue(el, { target, align = 'auto', cover = false, adjustparenthe
79
79
  store?.update(v => ({ ...v, valign, halign }));
80
80
  }
81
81
  const { destroy: watchDestroy } = watchForMutations(reposition);
82
- window.addEventListener('scroll', reposition);
82
+ document.addEventListener('scroll', reposition, { capture: true });
83
83
  return {
84
84
  update({ target: utarget, align: ualign = 'auto', cover: ucover = false, store: ustore }) {
85
85
  align = ualign;
@@ -98,7 +98,7 @@ export function glue(el, { target, align = 'auto', cover = false, adjustparenthe
98
98
  },
99
99
  destroy() {
100
100
  watchDestroy();
101
- window.removeEventListener('scroll', reposition);
101
+ document.removeEventListener('scroll', reposition);
102
102
  if (adjustparentheight) {
103
103
  if (formerMinHeight)
104
104
  parent.style.minHeight = formerMinHeight;
@@ -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);
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@txstate-mws/svelte-components",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "description": "Svelte components that are generically useful.",
5
5
  "scripts": {
6
6
  "prepublishOnly": "svelte-package",