Skip to content
This repository has been archived by the owner on Nov 9, 2024. It is now read-only.

add Property getNestedPopperElements #1151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 9 additions & 2 deletions src/createTippy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,16 @@ export default function createTippy(
}

function getNestedPopperTree(): PopperElement[] {
return arrayFrom(
popper.querySelectorAll('[data-__NAMESPACE_PREFIX__-root]')
const popperElements: PopperElement[] = [];
if (typeof instance.props.getNestedPopperElements === 'function') {
popperElements.push(...instance.props.getNestedPopperElements(popper));
}

popperElements.push(
...arrayFrom(popper.querySelectorAll('[data-__NAMESPACE_PREFIX__-root]'))
);

return popperElements;
}

function scheduleShow(event?: Event): void {
Expand Down
1 change: 1 addition & 0 deletions src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const defaultProps: DefaultProps = {
delay: 0,
duration: [300, 250],
getReferenceClientRect: null,
getNestedPopperElements: null,
hideOnClick: true,
ignoreAttributes: false,
interactive: false,
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface Props extends LifecycleHooks, RenderProps {
duration: number | [number | null, number | null];
followCursor: boolean | 'horizontal' | 'vertical' | 'initial';
getReferenceClientRect: null | GetReferenceClientRect;
getNestedPopperElements: null | ((popper: PopperElement) => PopperElement[]);
hideOnClick: boolean | 'toggle';
ignoreAttributes: boolean;
inlinePositioning: boolean;
Expand Down
16 changes: 16 additions & 0 deletions website/src/pages/v6/all-props.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ tippy(targets, {
- [duration](#duration) <RenderIcon />
- [followCursor](#followcursor) <PluginIcon />
- [getReferenceClientRect](#getreferenceclientrect)
- [getNestedPopperElements](#getnestedpopperelements)
- [hideOnClick](#hideonclick)
- [ignoreAttributes](#ignoreattributes)
- [inertia](#inertia) <RenderIcon />
Expand Down Expand Up @@ -412,6 +413,21 @@ tippy(targets, {

---

### getNestedPopperElements

Used for keeping tippy open when mouse is over child tippy instances.

```js
tippy(targets, {
// default (uses the reference passed as first argument)
getNestedPopperElements: null,
// function that returns custom popper elements
getNestedPopperElements: (popperElement) => Array.from(popperElement.querySelectorAll('.my-custom-tooltips'),
});
```

---

### hideOnClick

Determines if the tippy hides upon clicking the reference or outside of the
Expand Down