Skip to content

Commit

Permalink
Fix #5889: BlockUI in unstyled mode
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Feb 14, 2024
1 parent 335c4f7 commit d040177
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
31 changes: 18 additions & 13 deletions components/lib/blockui/BlockUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,31 @@ export const BlockUI = React.forwardRef((inProps, ref) => {
};

const unblock = () => {
const callback = () => {
setVisibleState(false);
if (!maskRef.current) {
removeMask();

if (props.fullScreen) {
DomHandler.unblockBodyScroll();
activeElementRef.current && activeElementRef.current.focus();
}

props.onUnblocked && props.onUnblocked();
};
return;
}

if (maskRef.current) {
DomHandler.addClass(maskRef.current, 'p-component-overlay-leave');
if (!isUnstyled && DomHandler.hasCSSAnimation(maskRef.current)) {
maskRef.current.addEventListener('animationend', () => {
ZIndexUtils.clear(maskRef.current);
callback();
removeMask();
});
} else {
callback();
removeMask();
}
};

const removeMask = () => {
setVisibleState(false);

if (props.fullScreen) {
DomHandler.unblockBodyScroll();
activeElementRef.current && activeElementRef.current.focus();
}

props.onUnblocked && props.onUnblocked();
};

const onPortalMounted = () => {
Expand Down
22 changes: 22 additions & 0 deletions components/lib/utils/DomHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1214,4 +1214,26 @@ export default class DomHandler {
// Seem the same
return true;
}

static hasCSSAnimation(element) {
if (element) {
const style = getComputedStyle(element);
const animationDuration = parseFloat(style.getPropertyValue('animation-duration') || '0');

return animationDuration > 0;
}

return false;
}

static hasCSSTransition(element) {
if (element) {
const style = getComputedStyle(element);
const transitionDuration = parseFloat(style.getPropertyValue('transition-duration') || '0');

return transitionDuration > 0;
}

return false;
}
}

0 comments on commit d040177

Please sign in to comment.