Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:Dialog:breakpoints not work #5586

Merged
merged 2 commits into from
Dec 13, 2023
Merged
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
22 changes: 16 additions & 6 deletions components/lib/dialog/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ export const Dialog = React.forwardRef((inProps, ref) => {
unbindDocumentKeyDownListener();
};

const destroyStyle = () => {
styleElement.current = DomHandler.removeInlineStyle(styleElement.current);
};

const createStyle = () => {
styleElement.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce);

Expand All @@ -391,8 +395,8 @@ export const Dialog = React.forwardRef((inProps, ref) => {
for (let breakpoint in props.breakpoints) {
innerHTML += `
@media screen and (max-width: ${breakpoint}) {
.p-dialog[${attributeSelector.current}] {
width: ${props.breakpoints[breakpoint]};
[data-pc-name="dialog"][${attributeSelector.current}] {
width: ${props.breakpoints[breakpoint]} !important;
}
}
`;
Expand All @@ -401,16 +405,22 @@ export const Dialog = React.forwardRef((inProps, ref) => {
styleElement.current.innerHTML = innerHTML;
};

useUpdateEffect(() => {
if (props.breakpoints) {
createStyle();
}

return () => {
destroyStyle();
};
}, [props.breakpoints]);

useMountEffect(() => {
updateGlobalDialogsRegistry(true);

if (props.visible) {
setMaskVisibleState(true);
}

if (props.breakpoints) {
createStyle();
}
});

useUpdateEffect(() => {
Expand Down
Loading