Skip to content

Commit

Permalink
chore: add "data-portal-node" attr in usePortalMountNode() (microsoft…
Browse files Browse the repository at this point in the history
  • Loading branch information
layershifter authored and robertpenner committed Apr 11, 2024
1 parent 81e34cd commit 32372c0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "chore: add \"data-portal-node\" attr in usePortalMountNode()",
"packageName": "@fluentui/react-portal",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`Portal renders a default state 1`] = `
<div
class=""
data-portal-node="true"
dir="ltr"
>
test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('usePortalMountNode', () => {
const { result } = renderHook(() => usePortalMountNode({}));

expect(result.current).toBeInstanceOf(HTMLDivElement);
expect(result.current).toHaveAttribute('data-portal-node', 'true');
expect(document.body.contains(result.current)).toBeTruthy();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export const usePortalMountNode = (options: UsePortalMountNodeOptions): HTMLElem

element.classList.add(...classesToApply);
element.setAttribute('dir', dir);
element.setAttribute('data-portal-node', 'true');

focusVisibleRef.current = element;

return () => {
Expand All @@ -77,6 +79,8 @@ export const usePortalMountNode = (options: UsePortalMountNodeOptions): HTMLElem
// Force replace all classes
element.className = className;
element.setAttribute('dir', dir);
element.setAttribute('data-portal-node', 'true');

focusVisibleRef.current = element;
}, [className, dir, element, focusVisibleRef]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
A portal renders content outside of a DOM tree, at the end of the document.
A portal renders content outside of a DOM tree, at the end of the document. This allows content to escape traditional boundaries caused by `"overflow: hidden"` CSS rules and keeps it on the top without using `z-index` rules. This is useful for example in `Menu` and `Tooltip` scenarios, where the content should always overlay everything else.

This allows content to escape traditional boundaries caused by "overflow: hidden" CSS rules and keeps it on the top without using z-index rules.
This is useful for example in Menu and Tooltip scenarios, where the content should always overlay everything else.

`Portal` component is a thin wrapper around React's [`ReactDOM.createPortal()`](https://reactjs.org/docs/portals.html).
`Portal` component is a thin wrapper around React's [`ReactDOM.createPortal()`](https://reactjs.org/docs/portals.html) that propagates Fluent styling (allows to use `tokens`) and text-direction handling to the content. You can identify DOM created by `Portal` by looking for the `data-portal-node` attribute.

0 comments on commit 32372c0

Please sign in to comment.