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
6 changes: 6 additions & 0 deletions .changeset/stale-moments-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@patternfly/pfe-core": patch
---

`FloatingDOMController`: support usage within iframes

23 changes: 12 additions & 11 deletions core/pfe-core/controllers/floating-dom-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ function getOverflowAncestors(
): OverflowAncestors {
const scrollableAncestor = getNearestOverflowAncestor(node);
const isBody = scrollableAncestor === node.ownerDocument?.body;
const win = window;
const win = scrollableAncestor.ownerDocument?.defaultView ?? window;

if (isBody) {
const frameElement = getFrameElement(win);
Expand Down Expand Up @@ -1269,8 +1269,8 @@ function getScale(element: Element): Coords {
* @param element - The element to get visual offsets for
* @returns Coordinates object with x and y offsets
*/
function getVisualOffsets(): Coords {
const win = window;
function getVisualOffsets(element: Element): Coords {
const win = element.ownerDocument?.defaultView ?? window;
if (!isWebKit() || !win.visualViewport) {
return noOffsets;
}
Expand Down Expand Up @@ -1323,16 +1323,17 @@ function getBoundingClientRect(
}
}
const visualOffsets = shouldAddVisualOffsets(isFixedStrategy, offsetParent) ?
getVisualOffsets()
getVisualOffsets(element)
: createCoords(0);
let x = (clientRect.left + visualOffsets.x) / scale.x;
let y = (clientRect.top + visualOffsets.y) / scale.y;
let width = clientRect.width / scale.x;
let height = clientRect.height / scale.y;
if (element) {
const win = window;
const offsetWin = offsetParent
&& isElement(offsetParent) ? window : offsetParent;
const win = element.ownerDocument?.defaultView ?? window;
const offsetWin = offsetParent && isElement(offsetParent) ?
offsetParent.ownerDocument?.defaultView ?? window
: offsetParent;
let currentWin = win;
let currentIFrame = getFrameElement(currentWin);
while (currentIFrame && offsetParent && offsetWin !== currentWin) {
Expand All @@ -1349,7 +1350,7 @@ function getBoundingClientRect(
height *= iframeScale.y;
x += left;
y += top;
currentWin = window;
currentWin = currentIFrame.ownerDocument?.defaultView ?? window;
currentIFrame = getFrameElement(currentWin);
}
}
Expand Down Expand Up @@ -1487,7 +1488,7 @@ function getDocumentRect(element: Element): Rect {
* @returns Rect object with viewport dimensions and position
*/
function getViewportRect(element: Element, strategy: Strategy): Rect {
const win = window;
const win = element.ownerDocument?.defaultView ?? window;
const html = getDocumentElement(element)!;
const { visualViewport } = win;
const width = visualViewport ? visualViewport.width : html.clientWidth;
Expand Down Expand Up @@ -1552,7 +1553,7 @@ function getClientRectFromClippingAncestor(
} else if (isElement(clippingAncestor)) {
rect = getInnerBoundingClientRect(clippingAncestor, strategy);
} else {
const visualOffsets = getVisualOffsets();
const visualOffsets = getVisualOffsets(element);
rect = {
x: clippingAncestor.x - visualOffsets.x,
y: clippingAncestor.y - visualOffsets.y,
Expand Down Expand Up @@ -1768,7 +1769,7 @@ function getTrueOffsetParent(element: Element, polyfill?: (element: Element) =>
*/
function getOffsetParent(element: Element, polyfill?: (element: Element) =>
Element | null): Element | Window {
const win = window;
const win = element.ownerDocument?.defaultView ?? window;
if (isTopLayer(element)) {
return win;
}
Expand Down
66 changes: 14 additions & 52 deletions elements/pf-v5-tooltip/docs/pf-v5-tooltip.md
Original file line number Diff line number Diff line change
@@ -1,132 +1,94 @@
{% renderInstallation %} {% endrenderInstallation %}

{% renderOverview %}
### Default <pf-v5-tooltip>
### Default
<pf-v5-tooltip content="This is some content">
<pf-v5-button>Tooltip</pf-v5-button>
<div slot="content">
This is some content
</div>
</pf-v5-tooltip>
{% endrenderOverview %}

{% band header="Usage" %}
### Left Tooltip
{% htmlexample %}
<pf-v5-tooltip position="left">
<pf-v5-tooltip position="left" content="This is some content">
<pf-v5-button>Tooltip</pf-v5-button>
<div slot="content">
This is some content
</div>
</pf-v5-tooltip>
{% endhtmlexample %}

### Left-Start Tooltip
{% htmlexample %}
<pf-v5-tooltip position="left-start">
<pf-v5-tooltip position="left-start" content="This is some content">
<pf-v5-button>Tooltip</pf-v5-button>
<div slot="content">
This is some content
</div>
</pf-v5-tooltip>
{% endhtmlexample %}

### Left-End Tooltip
{% htmlexample %}
<pf-v5-tooltip position="left-end">
<pf-v5-tooltip position="left-end" content="This is some content">
<pf-v5-button>Tooltip</pf-v5-button>
<div slot="content">
This is some content
</div>
</pf-v5-tooltip>
{% endhtmlexample %}

### Right Tooltip
{% htmlexample %}
<pf-v5-tooltip position="right">
<pf-v5-tooltip position="right" content="This is some content">
<pf-v5-button>Tooltip</pf-v5-button>
<div slot="content">
This is some content
</div>
</pf-v5-tooltip>
{% endhtmlexample %}

### Right-Start Tooltip
{% htmlexample %}
<pf-v5-tooltip position="right-start">
<pf-v5-tooltip position="right-start" content="This is some content">
<pf-v5-button>Tooltip</pf-v5-button>
<div slot="content">
This is some content
</div>
</pf-v5-tooltip>
{% endhtmlexample %}

### Right-End Tooltip
{% htmlexample %}
<pf-v5-tooltip position="right-end">
<pf-v5-tooltip position="right-end" content="This is some content">
<pf-v5-button>Tooltip</pf-v5-button>
<div slot="content">
This is some content
</div>
</pf-v5-tooltip>
{% endhtmlexample %}

### Top Tooltip
{% htmlexample %}
<pf-v5-tooltip position="top">
<pf-v5-tooltip position="top" content="This is some content">
<pf-v5-button>Tooltip</pf-v5-button>
<div slot="content">
This is some content
</div>
</pf-v5-tooltip>
{% endhtmlexample %}

### Top-Start Tooltip
{% htmlexample %}
<pf-v5-tooltip position="top-start">
<pf-v5-tooltip position="top-start" content="This is some content">
<pf-v5-button>Tooltip</pf-v5-button>
<div slot="content">
This is some content
</div>
</pf-v5-tooltip>
{% endhtmlexample %}

### Top-End Tooltip
{% htmlexample %}
<pf-v5-tooltip position="top-end">
<pf-v5-tooltip position="top-end" content="This is some content">
<pf-v5-button>Tooltip</pf-v5-button>
<div slot="content">
This is some content
</div>
</pf-v5-tooltip>
{% endhtmlexample %}

### Bottom Tooltip
{% htmlexample %}
<pf-v5-tooltip position="bottom">
<pf-v5-tooltip position="bottom" content="This is some content">
<pf-v5-button>Tooltip</pf-v5-button>
<div slot="content">
This is some content
</div>
</pf-v5-tooltip>
{% endhtmlexample %}

### Bottom-Start Tooltip
{% htmlexample %}
<pf-v5-tooltip position="bottom-start">
<pf-v5-tooltip position="bottom-start" content="This is some content">
<pf-v5-button>Tooltip</pf-v5-button>
<div slot="content">
This is some content
</div>
</pf-v5-tooltip>
{% endhtmlexample %}

### Bottom-End Tooltip
{% htmlexample %}
<pf-v5-tooltip position="bottom-end">
<pf-v5-tooltip position="bottom-end" content="This is some content">
<pf-v5-button>Tooltip</pf-v5-button>
<div slot="content">
This is some content
</div>
</pf-v5-tooltip>
{% endhtmlexample %}
{% endband %}
Expand Down
Loading