Skip to content

Commit

Permalink
Fix primefaces#5523: BlockUI return activeElement focus
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Dec 5, 2023
1 parent 6e8730c commit 55ebf95
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions components/lib/blockui/BlockUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const BlockUI = React.forwardRef((inProps, ref) => {
const [visibleState, setVisibleState] = React.useState(props.blocked);
const elementRef = React.useRef(null);
const maskRef = React.useRef(null);
const activeElementRef = React.useRef(null);

const { ptm, cx, isUnstyled } = BlockUIBase.setMetaData({
props
Expand All @@ -22,13 +23,18 @@ export const BlockUI = React.forwardRef((inProps, ref) => {

const block = () => {
setVisibleState(true);
activeElementRef.current = document.activeElement;
};

const unblock = () => {
const callback = () => {
setVisibleState(false);

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

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

Expand All @@ -46,7 +52,7 @@ export const BlockUI = React.forwardRef((inProps, ref) => {
const onPortalMounted = () => {
if (props.fullScreen) {
DomHandler.blockBodyScroll();
document.activeElement.blur();
activeElementRef.current && activeElementRef.current.blur();
}

if (props.autoZIndex) {
Expand All @@ -67,9 +73,7 @@ export const BlockUI = React.forwardRef((inProps, ref) => {
}, [props.blocked]);

useUnmountEffect(() => {
if (props.fullScreen) {
DomHandler.unblockBodyScroll();
}
props.fullScreen && DomHandler.unblockBodyScroll();

ZIndexUtils.clear(maskRef.current);
});
Expand Down

0 comments on commit 55ebf95

Please sign in to comment.