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:
parent
eb59bea5c7
commit
f94582225c
1 changed files with 18 additions and 2 deletions
|
@ -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: ''
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue