preline
Version:
Preline UI is an open-source set of prebuilt UI components based on the utility-first Tailwind CSS framework.
32 lines (22 loc) • 870 B
text/typescript
import HSSelect from './core';
import { debounce } from '../../utils';
window.addEventListener('load', () => {
HSSelect.autoInit();
});
const onDocumentScrollRecalculateDirection = debounce((evt?: Event) => {
if (!window.$hsSelectCollection) return false;
const target = window.$hsSelectCollection.find((el) => el.element.isOpened());
if (!target) return false;
const activeElement = document.activeElement as HTMLElement | null;
const evtTarget = (evt?.target || null) as HTMLElement | null;
if (
(activeElement && target.element.containsDropdownElement(activeElement)) ||
(evtTarget && target.element.containsDropdownElement(evtTarget))
)
return false;
target.element.recalculateDirection();
}, 150);
document.addEventListener('scroll', onDocumentScrollRecalculateDirection);
if (typeof window !== 'undefined') {
window.HSSelect = HSSelect;
}