Fixed #500 - Improvement in behavior of components that have overlay panels in scrollable containers
parent
27178a0a51
commit
63020feb8e
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -245,6 +245,42 @@ export default class DomHandler {
|
||||||
element.style.left = left + 'px';
|
element.style.left = left + 'px';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getParents(element, parents = []) {
|
||||||
|
return element['parentNode'] === null ? parents : this.getParents(element.parentNode, parents.concat([element.parentNode]));
|
||||||
|
}
|
||||||
|
|
||||||
|
static getScrollableParents(element) {
|
||||||
|
let scrollableParents = [];
|
||||||
|
|
||||||
|
if (element) {
|
||||||
|
let parents = this.getParents(element);
|
||||||
|
const overflowRegex = /(auto|scroll)/;
|
||||||
|
const overflowCheck = (node) => {
|
||||||
|
let styleDeclaration = window['getComputedStyle'](node, null);
|
||||||
|
return overflowRegex.test(styleDeclaration.getPropertyValue('overflow')) || overflowRegex.test(styleDeclaration.getPropertyValue('overflowX')) || overflowRegex.test(styleDeclaration.getPropertyValue('overflowY'));
|
||||||
|
};
|
||||||
|
|
||||||
|
for (let parent of parents) {
|
||||||
|
let scrollSelectors = parent.nodeType === 1 && parent.dataset['scrollselectors'];
|
||||||
|
if (scrollSelectors) {
|
||||||
|
let selectors = scrollSelectors.split(',');
|
||||||
|
for (let selector of selectors) {
|
||||||
|
let el = this.findSingle(parent, selector);
|
||||||
|
if (el && overflowCheck(el)) {
|
||||||
|
scrollableParents.push(el);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parent.nodeType === 9 || overflowCheck(parent)) {
|
||||||
|
scrollableParents.push(parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return scrollableParents;
|
||||||
|
}
|
||||||
|
|
||||||
static getHiddenElementOuterHeight(element) {
|
static getHiddenElementOuterHeight(element) {
|
||||||
element.style.visibility = 'hidden';
|
element.style.visibility = 'hidden';
|
||||||
element.style.display = 'block';
|
element.style.display = 'block';
|
||||||
|
|
Loading…
Reference in New Issue