UNPKG

@carbon/ibm-products

Version:

Carbon for IBM Products

43 lines (38 loc) 1.65 kB
/** * Copyright IBM Corp. 2020, 2025 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; var React = require('react'); // Moves the placement of the active cell const useMoveActiveCell = _ref => { let { spreadsheetRef, activeCellCoordinates, containerHasFocus, createActiveCell, activeCellContent, isActiveHeaderCellChanged } = _ref; let performCreateActiveCell; //new active cell is created when the activeCellContent changes or navigate through headers // Otherwise new active cell will display the old value in a glance React.useEffect(() => { performCreateActiveCell(); }, [activeCellContent, performCreateActiveCell, isActiveHeaderCellChanged]); performCreateActiveCell = React.useCallback(() => { const activeCellPlacementElement = spreadsheetRef?.current.querySelector(`[data-row-index="${activeCellCoordinates?.row}"][data-column-index="${activeCellCoordinates?.column}"]`); const shouldPlaceActiveCellInHeader = activeCellCoordinates?.row === 'header' && true; const selectAllElement = spreadsheetRef?.current.querySelector(`[data-row-index="header"][data-column-index="header"]`); if (containerHasFocus) { createActiveCell({ placementElement: activeCellCoordinates ? activeCellPlacementElement : selectAllElement, coords: activeCellCoordinates, addToHeader: shouldPlaceActiveCellInHeader }); } }, [spreadsheetRef, activeCellCoordinates, containerHasFocus, createActiveCell]); }; exports.useMoveActiveCell = useMoveActiveCell;