@crisp-ui-kit/crisp 0.31.1 → 0.31.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.
@@ -721,6 +721,36 @@ function RecordsTable({ labels, columns: columnsProp = exports.defaultColumns, r
721
721
  const setSortField = (i, key) => setSorts(sorts.map((s, j) => (j === i ? { ...s, key } : s)));
722
722
  const setSortDir = (i, dir) => setSorts(sorts.map((s, j) => (j === i ? { ...s, dir } : s)));
723
723
  const removeSort = (i) => setSorts(sorts.filter((_, j) => j !== i));
724
+ /**
725
+ * Keep the selected cell on screen.
726
+ *
727
+ * Focus stays on the scroll region, never on a cell, so the browser has
728
+ * nothing to scroll to: the arrow keys moved the outline and the viewport
729
+ * stayed put. Measured in Chrome on a 384px-tall region over 40 rows —
730
+ * twenty ArrowDowns left `scrollTop` at 0 with the selected cell 761px below
731
+ * the top edge, i.e. the user was driving a selection they could not see
732
+ * (#257).
733
+ *
734
+ * `nearest` on both axes: a cell already in view is left exactly where it
735
+ * is, which is what makes this safe to run after a click too.
736
+ *
737
+ * No `behavior` of our own — the page's `scroll-behavior` decides, and Attio
738
+ * jumps rather than glides — except under reduced motion, where an explicit
739
+ * "auto" is the only thing that beats a host page that set
740
+ * `scroll-behavior: smooth` on the scroller (#208's rule: JS motion reads
741
+ * the preference itself, because CSS cannot reach an explicit argument).
742
+ */
743
+ const reduceMotion = (0, core_1.usePrefersReducedMotion)();
744
+ React.useEffect(() => {
745
+ if (!selCell)
746
+ return;
747
+ const cell = scrollRef.current?.querySelector(`[data-cell="${CSS.escape(`${selCell.id}:${selCell.key}`)}"]`);
748
+ cell?.scrollIntoView({
749
+ block: "nearest",
750
+ inline: "nearest",
751
+ ...(reduceMotion ? { behavior: "auto" } : null),
752
+ });
753
+ }, [selCell, reduceMotion]);
724
754
  const commitEdit = (id, key, raw) => {
725
755
  const col = cols.find((c) => c.key === key);
726
756
  const numeric = col?.type === "number" || col?.type === "currency";
@@ -1069,7 +1099,7 @@ function RecordsTable({ labels, columns: columnsProp = exports.defaultColumns, r
1069
1099
  // row instead of a bare "182,000", and the same header is
1070
1100
  // repeated in every cell's context (#231).
1071
1101
  const Cell = (i === 0 ? "th" : "td");
1072
- return ((0, jsx_runtime_1.jsxs)(Cell, { scope: i === 0 ? "row" : undefined, className: `recordstable-td${i === 0 ? " recordstable-col-entity" : ""}${canEdit ? " recordstable-td--editable" : ""}${isPicker ? " recordstable-td--picker" : ""}`, "data-enriched": col.enriched ? "" : undefined, "data-selected": selCell?.id === row.id && selCell?.key === col.key
1102
+ return ((0, jsx_runtime_1.jsxs)(Cell, { scope: i === 0 ? "row" : undefined, "data-cell": `${row.id}:${col.key}`, className: `recordstable-td${i === 0 ? " recordstable-col-entity" : ""}${canEdit ? " recordstable-td--editable" : ""}${isPicker ? " recordstable-td--picker" : ""}`, "data-enriched": col.enriched ? "" : undefined, "data-selected": selCell?.id === row.id && selCell?.key === col.key
1073
1103
  ? ""
1074
1104
  : undefined, onClick: () => {
1075
1105
  if (isPicker)
@@ -14,7 +14,7 @@ import { Menu, MenuItem, useMenuKeyboard } from "../../components/menu/index.js"
14
14
  import { MultiSelect } from "../../components/multiselect/index.js";
15
15
  import { Select } from "../../components/select/index.js";
16
16
  import { Switch } from "../../components/switch/index.js";
17
- import { isRtlElement } from "../../core/index.js";
17
+ import { isRtlElement, usePrefersReducedMotion } from "../../core/index.js";
18
18
  import { companyLogos } from "./company-logos.js";
19
19
  import { recordstableRecipe } from "./recordstable.recipe.js";
20
20
  const EDITABLE = new Set(["text", "number", "url", "currency"]);
@@ -681,6 +681,36 @@ export function RecordsTable({ labels, columns: columnsProp = defaultColumns, ro
681
681
  const setSortField = (i, key) => setSorts(sorts.map((s, j) => (j === i ? { ...s, key } : s)));
682
682
  const setSortDir = (i, dir) => setSorts(sorts.map((s, j) => (j === i ? { ...s, dir } : s)));
683
683
  const removeSort = (i) => setSorts(sorts.filter((_, j) => j !== i));
684
+ /**
685
+ * Keep the selected cell on screen.
686
+ *
687
+ * Focus stays on the scroll region, never on a cell, so the browser has
688
+ * nothing to scroll to: the arrow keys moved the outline and the viewport
689
+ * stayed put. Measured in Chrome on a 384px-tall region over 40 rows —
690
+ * twenty ArrowDowns left `scrollTop` at 0 with the selected cell 761px below
691
+ * the top edge, i.e. the user was driving a selection they could not see
692
+ * (#257).
693
+ *
694
+ * `nearest` on both axes: a cell already in view is left exactly where it
695
+ * is, which is what makes this safe to run after a click too.
696
+ *
697
+ * No `behavior` of our own — the page's `scroll-behavior` decides, and Attio
698
+ * jumps rather than glides — except under reduced motion, where an explicit
699
+ * "auto" is the only thing that beats a host page that set
700
+ * `scroll-behavior: smooth` on the scroller (#208's rule: JS motion reads
701
+ * the preference itself, because CSS cannot reach an explicit argument).
702
+ */
703
+ const reduceMotion = usePrefersReducedMotion();
704
+ React.useEffect(() => {
705
+ if (!selCell)
706
+ return;
707
+ const cell = scrollRef.current?.querySelector(`[data-cell="${CSS.escape(`${selCell.id}:${selCell.key}`)}"]`);
708
+ cell?.scrollIntoView({
709
+ block: "nearest",
710
+ inline: "nearest",
711
+ ...(reduceMotion ? { behavior: "auto" } : null),
712
+ });
713
+ }, [selCell, reduceMotion]);
684
714
  const commitEdit = (id, key, raw) => {
685
715
  const col = cols.find((c) => c.key === key);
686
716
  const numeric = col?.type === "number" || col?.type === "currency";
@@ -1029,7 +1059,7 @@ export function RecordsTable({ labels, columns: columnsProp = defaultColumns, ro
1029
1059
  // row instead of a bare "182,000", and the same header is
1030
1060
  // repeated in every cell's context (#231).
1031
1061
  const Cell = (i === 0 ? "th" : "td");
1032
- return (_jsxs(Cell, { scope: i === 0 ? "row" : undefined, className: `recordstable-td${i === 0 ? " recordstable-col-entity" : ""}${canEdit ? " recordstable-td--editable" : ""}${isPicker ? " recordstable-td--picker" : ""}`, "data-enriched": col.enriched ? "" : undefined, "data-selected": selCell?.id === row.id && selCell?.key === col.key
1062
+ return (_jsxs(Cell, { scope: i === 0 ? "row" : undefined, "data-cell": `${row.id}:${col.key}`, className: `recordstable-td${i === 0 ? " recordstable-col-entity" : ""}${canEdit ? " recordstable-td--editable" : ""}${isPicker ? " recordstable-td--picker" : ""}`, "data-enriched": col.enriched ? "" : undefined, "data-selected": selCell?.id === row.id && selCell?.key === col.key
1033
1063
  ? ""
1034
1064
  : undefined, onClick: () => {
1035
1065
  if (isPicker)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crisp-ui-kit/crisp",
3
- "version": "0.31.1",
3
+ "version": "0.31.2",
4
4
  "description": "A lean React design system, measured pixel-for-pixel from Attio.",
5
5
  "license": "MIT",
6
6
  "type": "module",