Skip to content

Commit 8c8537d

Browse files
committed
fix: use dom-query/isActiveElement in createScope
1 parent ef15a7c commit 8c8537d

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

packages/core/src/scope.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { getActiveElement, getDocument } from "@zag-js/dom-query"
1+
import { getActiveElement, getDocument, isActiveElement } from "@zag-js/dom-query"
22
import type { Scope } from "./types"
33

44
export function createScope(props: Pick<Scope, "id" | "ids" | "getRootNode">) {
55
const getRootNode = () => (props.getRootNode?.() ?? document) as Document | ShadowRoot
66
const getDoc = () => getDocument(getRootNode())
77
const getWin = () => getDoc().defaultView ?? window
88
const getActiveElementFn = () => getActiveElement(getRootNode())
9-
const isActiveElement = (elem: HTMLElement | null) => elem === getActiveElementFn()
109
const getById = <T extends Element = HTMLElement>(id: string) => getRootNode().getElementById(id) as T | null
1110
return {
1211
...props,

packages/utilities/dom-query/src/scope.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { setElementValue } from "./form"
2-
import { getActiveElement, getDocument } from "./node"
2+
import { getActiveElement, getDocument, isActiveElement } from "./node"
33
import type { HTMLElementWithValue } from "./types"
44

55
export interface ScopeContext {
@@ -12,7 +12,7 @@ export function createScope<T>(methods: T) {
1212
getDoc: (ctx: ScopeContext) => getDocument(dom.getRootNode(ctx)),
1313
getWin: (ctx: ScopeContext) => dom.getDoc(ctx).defaultView ?? window,
1414
getActiveElement: (ctx: ScopeContext) => getActiveElement(dom.getRootNode(ctx)),
15-
isActiveElement: (ctx: ScopeContext, elem: HTMLElement | null) => elem === dom.getActiveElement(ctx),
15+
isActiveElement,
1616
getById: <T extends Element = HTMLElement>(ctx: ScopeContext, id: string) =>
1717
dom.getRootNode(ctx).getElementById(id) as T | null,
1818
setValue: <T extends HTMLElementWithValue>(elem: T | null, value: string | number | null | undefined) => {

0 commit comments

Comments
 (0)