From 35f4d9e8d0595560adf4e19577cc485d80a595a6 Mon Sep 17 00:00:00 2001 From: krutoo Date: Fri, 20 Mar 2026 22:28:52 +0500 Subject: [PATCH] docs(dom): Improved docs for findClosest() options --- docs/docs/dom/find-closest.mdx | 14 ++++++++++++++ docs/tsconfig.json | 2 ++ 2 files changed, 16 insertions(+) diff --git a/docs/docs/dom/find-closest.mdx b/docs/docs/dom/find-closest.mdx index a9383e3..4fd1a02 100644 --- a/docs/docs/dom/find-closest.mdx +++ b/docs/docs/dom/find-closest.mdx @@ -16,3 +16,17 @@ const element = document.querySelector('#something'); // element or null returns const closestTarget = findClosest(element, el => el.classList.contains('target')); ``` + +### Option `needBreakLoop` + +By default `findClosest` traverses DOM tree until predicate returns true or there is no `parentElement`. + +In some cases you may need to NOT mark element as suitable but also break loop and not search anymore. + +For this cases you can use `needBreakLoop` option: + +```js +const foundElement = findClosest(element, el => el.classList.contains('target'), { + needBreakLoop: el => el.id === 'root', +}); +``` diff --git a/docs/tsconfig.json b/docs/tsconfig.json index c12352b..5d64d85 100644 --- a/docs/tsconfig.json +++ b/docs/tsconfig.json @@ -17,10 +17,12 @@ "paths": { "#components/*": ["./src/components/*"], "@krutoo/utils": ["../src/mod.ts"], + "@krutoo/utils/di": ["../src/di/mod.ts"], "@krutoo/utils/dom": ["../src/dom/mod.ts"], "@krutoo/utils/math": ["../src/math/mod.ts"], "@krutoo/utils/misc": ["../src/misc/mod.ts"], "@krutoo/utils/react": ["../src/react/mod.ts"], + "@krutoo/utils/router": ["../src/router/mod.ts"], "@krutoo/utils/rspack": ["../src/rspack/mod.ts"], "@krutoo/utils/types": ["../src/types/mod.ts"] }