react-beautiful-dnd
Version:
A beautiful, accessible drag and drop library for lists with React.js
28 lines (21 loc) • 660 B
JavaScript
// @flow
import type { HTMLElement } from '../../src/types';
const isScrollable = (...values: string[]): boolean =>
values.some((value: string): boolean =>
(value === 'auto' || value === 'scroll'));
const isElementScrollable = (el: HTMLElement) => {
const style = window.getComputedStyle(el);
return isScrollable(style.overflow, style.overflowY);
};
const getClosestScrollable = (el: ?HTMLElement): ?HTMLElement => {
// cannot do anything else!
if (el == null) {
return null;
}
if (!isElementScrollable(el)) {
return getClosestScrollable(el.parentElement);
}
// success!
return el;
};
export default getClosestScrollable;