Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/docs/dom/find-closest.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
```
2 changes: 2 additions & 0 deletions docs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
Expand Down
Loading