Skip to content

Commit

Permalink
feat(Dialog): allow observing content resize without a re-render trig…
Browse files Browse the repository at this point in the history
…gered
  • Loading branch information
YossiSaadi committed Jan 8, 2025
1 parent cda32ae commit bd6d877
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion packages/core/src/components/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ export interface DialogProps extends VibeComponentProps {
* If string use it as selector to prevent scroll.
*/
disableContainerScroll?: boolean | string;
/**
* Enables the observation of content resize for the popper element.
* When set to `true`, a ResizeObserver is attached to the popper content,
* automatically triggering repositioning when the size of the content changes.
*
* This is useful for dialogs, tooltips, or popovers with dynamic content
* that may grow or shrink without a re-render being triggered.
*/
observeContentResize?: boolean;
}

export interface DialogState {
Expand Down Expand Up @@ -191,7 +200,8 @@ export default class Dialog extends PureComponent<DialogProps, DialogState> {
hideWhenReferenceHidden: false,
shouldCallbackOnMount: false,
instantShowAndHide: false,
addKeyboardHideShowTriggersByDefault: false
addKeyboardHideShowTriggersByDefault: false,
observeContentResize: false
};
private showTimeout: NodeJS.Timeout;
private hideTimeout: NodeJS.Timeout;
Expand Down Expand Up @@ -498,6 +508,7 @@ export default class Dialog extends PureComponent<DialogProps, DialogState> {
hideWhenReferenceHidden,
disableContainerScroll,
containerSelector,
observeContentResize,
id,
"data-testid": dataTestId
} = this.props;
Expand Down Expand Up @@ -573,6 +584,22 @@ export default class Dialog extends PureComponent<DialogProps, DialogState> {
return state;
}
},
{
name: "observeContentResize",
enabled: observeContentResize,
phase: "beforeWrite",
fn() {},
effect({ state, instance }) {
const observer = new ResizeObserver(() => {
instance.update();
});
observer.observe(state.elements.popper);

return () => {
observer.disconnect();
};
}
},
...modifiers
]}
>
Expand Down

0 comments on commit bd6d877

Please sign in to comment.