Skip to content

Commit

Permalink
Fix primefaces#3080: StyleClass improved handling of visible elements (
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Jul 23, 2022
1 parent 56cf90a commit f4dc9e1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 1 addition & 4 deletions components/lib/styleclass/StyleClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ export const StyleClass = React.forwardRef((props, ref) => {
DomHandler.addClass(targetRef.current, props.toggleClassName);
}
else {
if (targetRef.current.offsetParent === null)
enter();
else
leave();
DomHandler.isVisible(targetRef.current) ? leave() : enter();
}
}
});
Expand Down
7 changes: 6 additions & 1 deletion components/lib/utils/DomHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,12 @@ export default class DomHandler {
}

static isVisible(element) {
return element && element.offsetParent != null;
// https://stackoverflow.com/a/59096915/502366 (in future use IntersectionObserver)
return element && (
element.clientHeight !== 0 ||
element.getClientRects().length !== 0 ||
getComputedStyle(element).display !== 'none'
);
}

static isExist(element) {
Expand Down

0 comments on commit f4dc9e1

Please sign in to comment.