UNPKG

@carbon/ibm-products

Version:
47 lines (45 loc) 1.84 kB
/** * Copyright IBM Corp. 2020, 2026 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ require("../../../_virtual/_rolldown/runtime.js"); const require_settings = require("../../../settings.js"); const require_removeCellSelections = require("../utils/removeCellSelections.js"); let react = require("react"); //#region src/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js /** * Copyright IBM Corp. 2022, 2022 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ const useSpreadsheetOutsideClick = ({ isBlurSpreadsheet, spreadsheetRef, blockClass = `${require_settings.pkg.prefix}--data-spreadsheet`, setActiveCellCoordinates, setSelectionAreas, removeActiveCell, setContainerHasFocus, removeCellEditor }) => { (0, react.useEffect)(() => { const handleOutsideClick = (event) => { if (!spreadsheetRef.current || spreadsheetRef.current.contains(event.target) || event.target.classList.contains(`${blockClass}__active-cell--highlight`) || event.target.classList.contains(`${blockClass}--interactive-cell-element`)) return; isBlurSpreadsheet.current = true; setActiveCellCoordinates(null); setSelectionAreas([]); removeActiveCell(); require_removeCellSelections.removeCellSelections({ spreadsheetRef }); setContainerHasFocus(false); }; document.addEventListener("click", handleOutsideClick); return () => { document.removeEventListener("click", handleOutsideClick); }; }, [ isBlurSpreadsheet, spreadsheetRef, removeActiveCell, blockClass, setActiveCellCoordinates, setContainerHasFocus, setSelectionAreas, removeCellEditor ]); }; //#endregion exports.useSpreadsheetOutsideClick = useSpreadsheetOutsideClick;