Files
Stackq/node_modules/runed/dist/utilities/is-focus-within/is-focus-within.svelte.js
T
eewing cf73cd3b4c INIT
2026-02-17 14:10:16 -06:00

21 lines
648 B
JavaScript

import { ActiveElement, } from "../active-element/active-element.svelte.js";
import { extract } from "../extract/extract.svelte.js";
/**
* Tracks whether the focus is within a target element.
* @see {@link https://runed.dev/docs/utilities/is-focus-within}
*/
export class IsFocusWithin {
#node;
#activeElement;
constructor(node, options = {}) {
this.#node = node;
this.#activeElement = new ActiveElement(options);
}
current = $derived.by(() => {
const node = extract(this.#node);
if (node == null)
return false;
return node.contains(this.#activeElement.current);
});
}