Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
Comment thread
ling1726 marked this conversation as resolved.
"type": "minor",
"comment": "feat: Update position when target or container dimensions change",
"packageName": "@fluentui/react-positioning",
"email": "lingfangao@hotmail.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@ interface PositionManagerOptions {
* @returns manager that handles positioning out of the react lifecycle
*/
export function createPositionManager(options: PositionManagerOptions): PositionManager {
const { container, target, arrow, strategy, middleware, placement, useTransform = true } = options;
let isDestroyed = false;
const { container, target, arrow, strategy, middleware, placement, useTransform = true } = options;
if (!target || !container) {
return {
updatePosition: () => undefined,
dispose: () => undefined,
};
}

// When the dimensions of the target or the container change - trigger a position update
const resizeObserver = new ResizeObserver(() => updatePosition());

let isFirstUpdate = true;
const scrollParents: Set<HTMLElement> = new Set<HTMLElement>();
const targetWindow = container.ownerDocument.defaultView;
Expand All @@ -77,6 +80,11 @@ export function createPositionManager(options: PositionManagerOptions): Position
scrollParent.addEventListener('scroll', updatePosition, { passive: true });
});

resizeObserver.observe(container);
if (isHTMLElement(target)) {
resizeObserver.observe(target);
}

isFirstUpdate = false;
}

Expand Down Expand Up @@ -129,6 +137,8 @@ export function createPositionManager(options: PositionManagerOptions): Position
scrollParent.removeEventListener('scroll', updatePosition);
});
scrollParents.clear();

resizeObserver.disconnect();
};

if (targetWindow) {
Expand Down