UNPKG

@awsui/components-react

Version:

On July 19th, 2022, we launched [Cloudscape Design System](https://cloudscape.design). Cloudscape is an evolution of AWS-UI. It consists of user interface guidelines, front-end components, design resources, and development tools for building intuitive, en

30 lines 1.13 kB
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { useRef } from 'react'; import { createSingletonHandler } from '@awsui/component-toolkit/internal'; const useEventListenersSingleton = createSingletonHandler(setTarget => { function handleMouseDown(event) { setTarget(event.target); } function handleKeyDown() { setTarget(null); } const controller = new AbortController(); window.addEventListener('mousedown', handleMouseDown, { signal: controller.signal }); window.addEventListener('keydown', handleKeyDown, { signal: controller.signal }); return () => { controller.abort(); }; }); /** * Captures last mouse down target and clears it on keydown. * @returns a callback to get the last detected mouse down target. */ export default function useMouseDownTarget() { const mouseDownTargetRef = useRef(null); useEventListenersSingleton(target => { mouseDownTargetRef.current = target; }); return () => mouseDownTargetRef.current; } //# sourceMappingURL=use-mouse-down-target.js.map