UNPKG

@julo-ui/sliders

Version:

A React Slider component that implements input[type='range']

26 lines (24 loc) 807 B
// src/range-slider/usecase/use-handle-focus-thumb.ts import { useCallback } from "react"; function useHandleFocusThumb(options) { const { focusThumbOnChange, rootRef, ids, activeIndex } = options; const onFocusThumb = useCallback( (index) => { var _a; const targetIndex = index != null ? index : activeIndex; if (targetIndex === -1 || !focusThumbOnChange) return; const id = ids.getThumb(targetIndex); const thumb = (_a = rootRef.current) == null ? void 0 : _a.ownerDocument.getElementById(id); if (thumb) { setTimeout(() => thumb.focus()); } }, [activeIndex, focusThumbOnChange, ids, rootRef] ); return { onFocusThumb }; } var use_handle_focus_thumb_default = useHandleFocusThumb; export { use_handle_focus_thumb_default };