Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getPosition(target, container) {
const offset = container.tagName === 'BODY' ? getOffset(target) : getPosition(target, container);
return offset;
},
updateScrollPoistion() {
const container = this.menuBodyContainerRef.current;
let activeItem = container.querySelector(`.${this.addPrefix('item-focus')}`);
if (!activeItem) {
activeItem = container.querySelector(`.${this.addPrefix('item-active')}`);
}
if (!activeItem) {
return;
}
const position = getPosition(activeItem, container);
const sTop = scrollTop(container);
const sHeight = getHeight(container);
if (sTop > position.top) {
scrollTop(container, Math.max(0, position.top - 20));
} else if (position.top > sTop + sHeight) {
scrollTop(container, Math.max(0, position.top - sHeight + 32));
}
}
Object.entries(time).forEach((item: any) => {
const container: Element = this.container[item[0]];
const node = container.querySelector(`[data-key="${item[0]}-${item[1]}"]`);
if (node && container) {
const { top } = getPosition(node, container);
scrollTopAnimation(this.container[item[0]], top, scrollTop(this.container[item[0]]) !== 0);
}
});
};
this.menus.forEach(menu => {
if (!menu) {
return;
}
let activeItem = menu.querySelector(`.${this.addPrefix('item-focus')}`);
if (!activeItem) {
activeItem = menu.querySelector(`.${this.addPrefix('item-active')}`);
}
if (activeItem) {
const position = getPosition(activeItem, menu);
scrollTop(menu, position.top);
}
});
}