Skip to content

Commit

Permalink
Adjust search height on resize
Browse files Browse the repository at this point in the history
Identified as a potential issue in #2650

When typing, the keyboard generally obstructs half the screen. However, when the keyboard is closed, search results don't expand to take up full space.
  • Loading branch information
askvortsov1 committed Apr 9, 2021
1 parent b1f166d commit f33024e
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions js/src/forum/components/Search.js
Expand Up @@ -114,19 +114,23 @@ export default class Search extends Component {
);
}

updateMaxHeight() {
// Since extensions might add elements above the search box on mobile,
// we need to calculate and set the max height dynamically.
const resultsElementMargin = 14;
const maxHeight =
window.innerHeight - this.element.querySelector('.Search-input>.FormControl').getBoundingClientRect().bottom - resultsElementMargin;
this.element.querySelector('.Search-results').style['max-height'] = `${maxHeight}px`;
}

onupdate() {
// Highlight the item that is currently selected.
this.setIndex(this.getCurrentNumericIndex());

// If there are no sources, the search view is not shown.
if (!this.sources.length) return;

// Since extensions might add elements above the search box on mobile,
// we need to calculate and set the max height dynamically.
const resultsElementMargin = 14;
const maxHeight =
window.innerHeight - this.element.querySelector('.Search-input>.FormControl').getBoundingClientRect().bottom - resultsElementMargin;
this.element.querySelector('.Search-results').style['max-height'] = `${maxHeight}px`;
this.updateMaxHeight();
}

oncreate(vnode) {
Expand Down Expand Up @@ -191,6 +195,13 @@ export default class Search extends Component {
.one('mouseup', (e) => e.preventDefault())
.select();
});

this.updateMaxHeightHandler = this.updateMaxHeight.bind(this);
window.addEventListener('resize', this.updateMaxHeightHandler);
}

onremove() {
window.removeEventListener('resize', this.updateMaxHeightHandler);
}

/**
Expand Down

0 comments on commit f33024e

Please sign in to comment.