Skip to content

Commit 942041f

Browse files
authored
Merge pull request #468 from warrenspe/issue-467
fix #467 dropdown + window resize bug
2 parents a100e39 + a936f85 commit 942041f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/dropdown.ts

+11
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,14 @@ export class Dropdown extends Component<DropdownOptions> implements Openable {
200200
document.body.addEventListener('click', this._handleDocumentClick);
201201
document.body.addEventListener('touchmove', this._handleDocumentTouchmove);
202202
this.dropdownEl.addEventListener('keydown', this._handleDropdownKeydown);
203+
window.addEventListener('resize', this._handleWindowResize);
203204
}
204205

205206
_removeTemporaryEventHandlers() {
206207
document.body.removeEventListener('click', this._handleDocumentClick);
207208
document.body.removeEventListener('touchmove', this._handleDocumentTouchmove);
208209
this.dropdownEl.removeEventListener('keydown', this._handleDropdownKeydown);
210+
window.removeEventListener('resize', this._handleWindowResize);
209211
}
210212

211213
_handleClick = (e: MouseEvent) => {
@@ -356,6 +358,15 @@ export class Dropdown extends Component<DropdownOptions> implements Openable {
356358
this.filterTimeout = setTimeout(this._resetFilterQuery, 1000);
357359
}
358360

361+
_handleWindowResize = (e: Event) => {
362+
// Only re-place the dropdown if it's still visible
363+
// Accounts for elements hiding via media queries
364+
if (this.el.offsetParent) {
365+
this.recalculateDimensions();
366+
}
367+
}
368+
369+
359370
_resetFilterQuery = () => {
360371
this.filterQuery = [];
361372
}

0 commit comments

Comments
 (0)