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 #7566: hideOverlaysOnDocumentScrolling fix for dialogs #7568

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
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
30 changes: 24 additions & 6 deletions components/lib/utils/DomHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,13 +607,26 @@ export default class DomHandler {
return element.parentNode === null ? parents : this.getParents(element.parentNode, parents.concat([element.parentNode]));
}

/**
* Gets all scrollable parent elements of a given element
* @param {HTMLElement} element - The element to find scrollable parents for
* @param {boolean} hideOverlaysOnDocumentScrolling - Whether to include window/document level scrolling
* @returns {Array} Array of scrollable parent elements
*/
static getScrollableParents(element, hideOverlaysOnDocumentScrolling = false) {
let scrollableParents = [];

if (element) {
// Get all parent elements
let parents = this.getParents(element);
// Regex to match auto or scroll overflow values
const overflowRegex = /(auto|scroll)/;

/**
* Checks if an element has overflow scroll/auto in any direction
* @param {HTMLElement} node - Element to check
* @returns {boolean} True if element has overflow scroll/auto
*/
const overflowCheck = (node) => {
let styleDeclaration = node ? getComputedStyle(node) : null;

Expand All @@ -622,21 +635,26 @@ export default class DomHandler {
);
};

/**
* Adds a scrollable parent element to the collection
* @param {HTMLElement} node - Element to add
*/
const addScrollableParent = (node) => {
if (hideOverlaysOnDocumentScrolling) {
// nodeType 9 is for document element
// For document/body/html elements, add window instead
scrollableParents.push(node.nodeName === 'BODY' || node.nodeName === 'HTML' || node.nodeType === 9 ? window : node);
} else {
scrollableParents.push(node);
}
};

// Iterate through all parent elements
for (let parent of parents) {
// Check for custom scroll selectors in data attribute
let scrollSelectors = parent.nodeType === 1 && parent.dataset?.scrollselectors;

if (scrollSelectors) {
let selectors = scrollSelectors.split(',');

// Check each selector
for (let selector of selectors) {
let el = this.findSingle(parent, selector);

Expand All @@ -646,16 +664,16 @@ export default class DomHandler {
}
}

// BODY
// Check if the parent itself is scrollable
if (parent.nodeType === 1 && overflowCheck(parent)) {
addScrollableParent(parent);
}
}
}

// we should always at least have the body or window
// Ensure window/body is always included as fallback
if (!scrollableParents.some((node) => node === document.body || node === window)) {
scrollableParents.push(window);
scrollableParents.push(hideOverlaysOnDocumentScrolling ? window : document.body);
}

return scrollableParents;
Expand Down
3 changes: 2 additions & 1 deletion pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export default function MyApp({ Component, pageProps }) {
};

const primereactConfig = {
ripple: true
ripple: true,
hideOverlaysOnDocumentScrolling: false
};

return (
Expand Down
Loading