0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Disabled background scroll on search

refs https://github.com/TryGhost/Team/issues/1665

- disables background scroll on main page when search is opened to avoid scroll leak
This commit is contained in:
Rishabh 2022-07-08 12:05:02 +02:00
parent eb59bea5c7
commit f94582225c

View file

@ -25,8 +25,24 @@ export default class App extends React.Component {
this.initSetup();
}
componentDidUpdate(_prevProps, _prevState) {
if (this.state.showPopup !== _prevState?.showPopup && !this.state.showPopup) {
componentDidUpdate(_prevProps, prevState) {
if (prevState.showPopup !== this.state.showPopup) {
/** Remove background scroll when popup is opened */
try {
if (this.state.showPopup) {
/** When modal is opened, store current overflow and set as hidden */
this.bodyScroll = window.document?.body?.style?.overflow;
window.document.body.style.overflow = 'hidden';
} else {
/** When the modal is hidden, reset overflow property for body */
window.document.body.style.overflow = this.bodyScroll || '';
}
} catch (e) {
/** Ignore any errors for scroll handling */
}
}
if (this.state.showPopup !== prevState?.showPopup && !this.state.showPopup) {
this.setState({
searchValue: ''
});