-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #500 - Improvement in behavior of components that have overlay …
…panels in scrollable containers
- Loading branch information
1 parent
27178a0
commit 63020fe
Showing
2 changed files
with
80 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import DomHandler from './DomHandler'; | ||
import UniqueComponentId from './UniqueComponentId'; | ||
|
||
export default class ConnectedOverlayScrollHandler { | ||
|
||
constructor(element, elementId = UniqueComponentId(), listener = () => {}) { | ||
this.element = element; | ||
this.elementId = elementId; | ||
this.listener = listener; | ||
} | ||
|
||
bindScrollListener() { | ||
this.scrollableParents = DomHandler.getScrollableParents(this.element); | ||
this.scrollListeners = {}; | ||
for (let i = 0; i < this.scrollableParents.length; i++) { | ||
let parent = this.scrollableParents[i]; | ||
let namespace = `${this.elementId}_${i}`; | ||
|
||
if (!this.scrollListeners[namespace]) { | ||
this.scrollListeners[namespace] = this.listener; | ||
parent.addEventListener('scroll', this.scrollListeners[namespace]); | ||
} | ||
} | ||
} | ||
|
||
unbindScrollListener() { | ||
if (this.scrollableParents) { | ||
for (let i = 0; i < this.scrollableParents.length; i++) { | ||
let parent = this.scrollableParents[i]; | ||
let namespace = `${this.elementId}_${i}`; | ||
|
||
if (this.scrollListeners[namespace]) { | ||
parent.removeEventListener('scroll', this.scrollListeners[namespace]); | ||
this.scrollListeners[namespace] = null; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters