UNPKG

@chief-editor/ui

Version:

UI Component for chief editor

1 lines 1.22 kB
import{useHotKey}from"@rc-hooks/hotkey";import{useRefGetter}from"@rc-hooks/use";import React,{Fragment,useCallback}from"react";export function SelectHotKey(e){var t=e.handlers,o=void 0===t?{}:t,l=e.focusableElementRef,n=useRefGetter(o),r=useCallback((function(){var e,t,o,r;return document.activeElement&&document.activeElement===l.current&&(null===(t=(e=l.current).scrollIntoView)||void 0===t||t.call(e,{behavior:"smooth",block:"nearest"}),null===(r=(o=n()).stepUp)||void 0===r||r.call(o)),!1}),[]),c=useCallback((function(){var e,t,o,r;return document.activeElement&&document.activeElement===l.current&&(null===(t=(e=l.current).scrollIntoView)||void 0===t||t.call(e,{behavior:"smooth",block:"nearest"}),null===(r=(o=n()).stepDown)||void 0===r||r.call(o)),!1}),[]),u=useCallback((function(){var e,t,o,r;document.activeElement&&document.activeElement===l.current&&(null===(t=(e=l.current).scrollIntoView)||void 0===t||t.call(e,{behavior:"smooth",block:"nearest"}),null===(r=(o=n()).selectBackFill)||void 0===r||r.call(o))}),[]);return useHotKey("up",r,"keydown"),useHotKey("up",r,"keypress"),useHotKey("down",c,"keydown"),useHotKey("down",c,"keypress"),useHotKey("enter",u,"keydown"),React.createElement(Fragment,null)}