@comitor/ui 3.6.0 → 3.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1477,8 +1477,8 @@ function useDataGrid({
1477
1477
  },
1478
1478
  [store, propsRef]
1479
1479
  );
1480
- const onRowSelectionChange = React.useCallback(
1481
- (updater) => {
1480
+ const applyRowSelection = React.useCallback(
1481
+ (updater, keepFocus) => {
1482
1482
  const currentState = store.getState();
1483
1483
  const newRowSelection = typeof updater === "function" ? updater(currentState.rowSelection) : updater;
1484
1484
  const selectedCells = getRowSelectionCells(
@@ -1493,13 +1493,17 @@ function useDataGrid({
1493
1493
  selectionRange: null,
1494
1494
  isSelecting: false
1495
1495
  });
1496
- store.setState("focusedCell", null);
1496
+ if (!keepFocus) store.setState("focusedCell", null);
1497
1497
  store.setState("editingCell", null);
1498
1498
  });
1499
1499
  propsRef.current.onRowSelectionChange?.(updater);
1500
1500
  },
1501
1501
  [store, columnIds, propsRef]
1502
1502
  );
1503
+ const onRowSelectionChange = React.useCallback(
1504
+ (updater) => applyRowSelection(updater, false),
1505
+ [applyRowSelection]
1506
+ );
1503
1507
  const onRowSelect = React.useCallback(
1504
1508
  (rowId, selected, shiftKey) => {
1505
1509
  const currentState = store.getState();
@@ -1521,22 +1525,28 @@ function useDataGrid({
1521
1525
  newRowSelection[row.id] = selected;
1522
1526
  }
1523
1527
  }
1524
- onRowSelectionChange(newRowSelection);
1528
+ applyRowSelection(newRowSelection, true);
1525
1529
  } else {
1526
- onRowSelectionChange({
1527
- ...currentState.rowSelection,
1528
- [currentRow.id]: selected
1529
- });
1530
+ applyRowSelection(
1531
+ {
1532
+ ...currentState.rowSelection,
1533
+ [currentRow.id]: selected
1534
+ },
1535
+ true
1536
+ );
1530
1537
  }
1531
1538
  } else {
1532
- onRowSelectionChange({
1533
- ...currentState.rowSelection,
1534
- [currentRow.id]: selected
1535
- });
1539
+ applyRowSelection(
1540
+ {
1541
+ ...currentState.rowSelection,
1542
+ [currentRow.id]: selected
1543
+ },
1544
+ true
1545
+ );
1536
1546
  }
1537
1547
  store.setState("lastClickedRowId", rowId);
1538
1548
  },
1539
- [store, onRowSelectionChange]
1549
+ [store, applyRowSelection]
1540
1550
  );
1541
1551
  const onRowHeightChange = React.useCallback(
1542
1552
  (updater) => {
@@ -1628,6 +1638,12 @@ function useDataGrid({
1628
1638
  getIsSearchMatch,
1629
1639
  getIsActiveSearchMatch,
1630
1640
  getVisualRowIndex,
1641
+ /*
1642
+ * Dời focus tới một ô mà KHÔNG đụng lựa chọn (thêm ở `3.6.1`) — cho phím di chuyển của app (`J`/`K`).
1643
+ * `onCellClick` không dùng được cho việc đó: nó là đường của CÚ BẤM, nên xoá lựa chọn dòng và mở trình
1644
+ * sửa khi bấm lại ô đang focus. Không cuộn — gọi kèm `scrollToCell` nếu ô có thể nằm ngoài khung.
1645
+ */
1646
+ focusCell,
1631
1647
  scrollToCell: (rowIndex, columnId, align = "auto") => {
1632
1648
  const container = dataGridRef.current;
1633
1649
  if (!container) return;
@@ -1690,6 +1706,7 @@ function useDataGrid({
1690
1706
  getIsSearchMatch,
1691
1707
  getIsActiveSearchMatch,
1692
1708
  getVisualRowIndex,
1709
+ focusCell,
1693
1710
  onRowHeightChange,
1694
1711
  onRowSelect,
1695
1712
  onDataUpdate,