diff --git a/src/internal/utils/__tests__/dom.test.ts b/src/internal/utils/__tests__/dom.test.ts index 1fb23fb57f..eddbe1bf61 100644 --- a/src/internal/utils/__tests__/dom.test.ts +++ b/src/internal/utils/__tests__/dom.test.ts @@ -1,6 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { findUpUntil, parseCssVariable, containsOrEqual } from '../../../../lib/components/internal/utils/dom'; +import { findUpUntil, parseCssVariable } from '../../../../lib/components/internal/utils/dom'; describe('findUpUntil', () => { test('returns null if there is no match', () => { @@ -86,30 +86,3 @@ describe('parseCssVariable', () => { }); }); }); - -describe('containsOrEqual', () => { - test('returns "true", when the node and the container are the same element', () => { - const div = document.createElement('div'); - div.innerHTML = ` -
- `; - expect(containsOrEqual(div.querySelector('#container1'), div.querySelector('#container1') as Node)).toBe(true); - }); - test('returns "true", when the node is descendant from the container', () => { - const div = document.createElement('div'); - div.innerHTML = ` -
-
-
- `; - expect(containsOrEqual(div.querySelector('#container1'), div.querySelector('#node') as Node)).toBe(true); - }); - test('returns "false", when the node is not a child of the container', () => { - const div = document.createElement('div'); - div.innerHTML = ` -
-
- `; - expect(containsOrEqual(div.querySelector('#container1'), div.querySelector('#node') as Node)).toBe(false); - }); -}); diff --git a/src/internal/utils/dom.ts b/src/internal/utils/dom.ts index a512666f0d..57308db3ca 100644 --- a/src/internal/utils/dom.ts +++ b/src/internal/utils/dom.ts @@ -95,16 +95,3 @@ export function parseCssVariable(value: string) { const match = expr.body.match(cssVariableExpression); return match ? match[1] : value; } - -/** - * Checks whether the given node is a descendant of a container. - * @deprecated use nodeContains from component-toolkit - * @param container Container node - * @param node Node that is checked to be a descendant of the container - */ -export function containsOrEqual(container: Node | null, node: Node): boolean { - if (container === null) { - return false; - } - return container === node || container.contains(node); -} diff --git a/src/internal/utils/node-belongs.ts b/src/internal/utils/node-belongs.ts index ac8473c118..bdbc944c1c 100644 --- a/src/internal/utils/node-belongs.ts +++ b/src/internal/utils/node-belongs.ts @@ -1,11 +1,12 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { containsOrEqual, findUpUntil } from './dom'; +import { findUpUntil } from './dom'; +import { nodeContains } from '@cloudscape-design/component-toolkit/dom'; /** * Checks whether the given node (target) belongs to the container. - * The function is similar to containsOrEqual but also accounts for dropdowns with expandToViewport=true. + * The function is similar to nodeContains but also accounts for dropdowns with expandToViewport=true. * * @param container Container node * @param target Node that is checked to be a descendant of the container @@ -16,5 +17,5 @@ export function nodeBelongs(container: Node | null, target: Node | EventTarget | } const portal = findUpUntil(target as HTMLElement, node => !!node.dataset.awsuiReferrerId); const referrer = portal instanceof HTMLElement ? document.getElementById(portal.dataset.awsuiReferrerId ?? '') : null; - return referrer ? containsOrEqual(container, referrer) : containsOrEqual(container, target); + return referrer ? nodeContains(container, referrer) : nodeContains(container, target); }