@charcuterie/ui 4.27.2 → 4.28.0

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.
Files changed (112) hide show
  1. package/dist/Accordion/AccordionSection.d.ts.map +1 -1
  2. package/dist/Accordion/AccordionSection.js +43 -4
  3. package/dist/Accordion/AccordionSection.js.map +1 -1
  4. package/dist/Combobox/Combobox.d.ts.map +1 -1
  5. package/dist/Combobox/Combobox.js +3 -3
  6. package/dist/Combobox/Combobox.js.map +1 -1
  7. package/dist/DatePicker/DatePicker.d.ts.map +1 -1
  8. package/dist/DatePicker/DatePicker.js +3 -3
  9. package/dist/DatePicker/DatePicker.js.map +1 -1
  10. package/dist/Dialog/Dialog.d.ts +7 -1
  11. package/dist/Dialog/Dialog.d.ts.map +1 -1
  12. package/dist/Dialog/Dialog.js +2 -2
  13. package/dist/Dialog/Dialog.js.map +1 -1
  14. package/dist/GroupedList/GroupedList.d.ts +9 -2
  15. package/dist/GroupedList/GroupedList.d.ts.map +1 -1
  16. package/dist/GroupedList/GroupedList.js +39 -5
  17. package/dist/GroupedList/GroupedList.js.map +1 -1
  18. package/dist/GroupedList/GroupedListRow.d.ts +4 -1
  19. package/dist/GroupedList/GroupedListRow.d.ts.map +1 -1
  20. package/dist/GroupedList/GroupedListRow.js +3 -3
  21. package/dist/GroupedList/GroupedListRow.js.map +1 -1
  22. package/dist/GroupedList/GroupedListRows.d.ts +16 -0
  23. package/dist/GroupedList/GroupedListRows.d.ts.map +1 -0
  24. package/dist/GroupedList/GroupedListRows.js +17 -0
  25. package/dist/GroupedList/GroupedListRows.js.map +1 -0
  26. package/dist/Listbox/Listbox.d.ts.map +1 -1
  27. package/dist/Listbox/Listbox.js +6 -4
  28. package/dist/Listbox/Listbox.js.map +1 -1
  29. package/dist/Menu/Menu.d.ts.map +1 -1
  30. package/dist/Menu/Menu.js +6 -4
  31. package/dist/Menu/Menu.js.map +1 -1
  32. package/dist/Modal/Modal.d.ts +7 -1
  33. package/dist/Modal/Modal.d.ts.map +1 -1
  34. package/dist/Modal/Modal.js +1 -1
  35. package/dist/Modal/Modal.js.map +1 -1
  36. package/dist/Motion/useLastPresentValue.d.ts +21 -0
  37. package/dist/Motion/useLastPresentValue.d.ts.map +1 -0
  38. package/dist/Motion/useLastPresentValue.js +30 -0
  39. package/dist/Motion/useLastPresentValue.js.map +1 -0
  40. package/dist/Motion/useListMotion.d.ts +111 -0
  41. package/dist/Motion/useListMotion.d.ts.map +1 -0
  42. package/dist/Motion/useListMotion.js +358 -0
  43. package/dist/Motion/useListMotion.js.map +1 -0
  44. package/dist/Motion/usePresence.d.ts +81 -0
  45. package/dist/Motion/usePresence.d.ts.map +1 -0
  46. package/dist/Motion/usePresence.js +131 -0
  47. package/dist/Motion/usePresence.js.map +1 -0
  48. package/dist/Motion/useValueChangeMotion.d.ts +52 -0
  49. package/dist/Motion/useValueChangeMotion.d.ts.map +1 -0
  50. package/dist/Motion/useValueChangeMotion.js +87 -0
  51. package/dist/Motion/useValueChangeMotion.js.map +1 -0
  52. package/dist/Overlay/OverlayPanel.d.ts +18 -1
  53. package/dist/Overlay/OverlayPanel.d.ts.map +1 -1
  54. package/dist/Overlay/OverlayPanel.js +40 -10
  55. package/dist/Overlay/OverlayPanel.js.map +1 -1
  56. package/dist/Overlay/SharedBackdrop.d.ts +3 -0
  57. package/dist/Overlay/SharedBackdrop.d.ts.map +1 -1
  58. package/dist/Overlay/SharedBackdrop.js +8 -2
  59. package/dist/Overlay/SharedBackdrop.js.map +1 -1
  60. package/dist/Overlay/useAnchoredOverlay.d.ts +17 -3
  61. package/dist/Overlay/useAnchoredOverlay.d.ts.map +1 -1
  62. package/dist/Overlay/useAnchoredOverlay.js +23 -5
  63. package/dist/Overlay/useAnchoredOverlay.js.map +1 -1
  64. package/dist/Popover/Popover.d.ts.map +1 -1
  65. package/dist/Popover/Popover.js +4 -2
  66. package/dist/Popover/Popover.js.map +1 -1
  67. package/dist/ReorderList/ReorderList.d.ts +6 -0
  68. package/dist/ReorderList/ReorderList.d.ts.map +1 -1
  69. package/dist/ReorderList/ReorderList.js +23 -6
  70. package/dist/ReorderList/ReorderList.js.map +1 -1
  71. package/dist/TableViewport/TableViewport.d.ts.map +1 -1
  72. package/dist/TableViewport/TableViewport.js +9 -1
  73. package/dist/TableViewport/TableViewport.js.map +1 -1
  74. package/dist/Tooltip/Tooltip.d.ts.map +1 -1
  75. package/dist/Tooltip/Tooltip.js +16 -13
  76. package/dist/Tooltip/Tooltip.js.map +1 -1
  77. package/dist/index.d.ts +22 -0
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +12 -0
  80. package/dist/index.js.map +1 -1
  81. package/dist/styles.css +191 -1
  82. package/package.json +2 -2
  83. package/src/Accordion/AccordionSection.tsx +63 -4
  84. package/src/Combobox/Combobox.tsx +8 -2
  85. package/src/DatePicker/DatePicker.tsx +7 -1
  86. package/src/Dialog/Dialog.tsx +8 -0
  87. package/src/GroupedList/GroupedList.mdx +3 -2
  88. package/src/GroupedList/GroupedList.test.tsx +283 -0
  89. package/src/GroupedList/GroupedList.tsx +88 -44
  90. package/src/GroupedList/GroupedListRow.tsx +8 -0
  91. package/src/GroupedList/GroupedListRows.tsx +51 -0
  92. package/src/Listbox/Listbox.tsx +9 -1
  93. package/src/Menu/Menu.tsx +9 -1
  94. package/src/Modal/Modal.tsx +8 -0
  95. package/src/Motion/useLastPresentValue.test.tsx +66 -0
  96. package/src/Motion/useLastPresentValue.ts +38 -0
  97. package/src/Motion/useListMotion.test.tsx +527 -0
  98. package/src/Motion/useListMotion.ts +674 -0
  99. package/src/Motion/usePresence.test.tsx +223 -0
  100. package/src/Motion/usePresence.ts +252 -0
  101. package/src/Motion/useValueChangeMotion.test.tsx +131 -0
  102. package/src/Motion/useValueChangeMotion.ts +110 -0
  103. package/src/Overlay/OverlayPanel.tsx +78 -14
  104. package/src/Overlay/SharedBackdrop.tsx +17 -2
  105. package/src/Overlay/useAnchoredOverlay.ts +56 -4
  106. package/src/Popover/Popover.tsx +9 -1
  107. package/src/ReorderList/ReorderList.test.tsx +76 -0
  108. package/src/ReorderList/ReorderList.tsx +86 -48
  109. package/src/TableViewport/TableViewport.tsx +4 -0
  110. package/src/Tooltip/Tooltip.tsx +32 -4
  111. package/src/index.ts +30 -0
  112. package/src/styles.css +191 -1
@@ -34,6 +34,12 @@ export type DialogProps = {
34
34
  * the case: every keystroke landed on "Close".
35
35
  */
36
36
  initialFocus?: RefObject<HTMLElement | null>
37
+ /**
38
+ * `false` only for a caller that animates the panel itself, as
39
+ * `TableViewport` does when it grows a table out of the page. Every
40
+ * other panel keeps the library's enter and exit motion.
41
+ */
42
+ hasMotion?: boolean
37
43
  isDismissable?: boolean
38
44
  isVisible: boolean
39
45
  /**
@@ -91,6 +97,7 @@ export const Dialog = ({
91
97
  className,
92
98
  footer,
93
99
  heading,
100
+ hasMotion = true,
94
101
  headingLevel = 2,
95
102
  initialFocus,
96
103
  isDismissable = true,
@@ -106,6 +113,7 @@ export const Dialog = ({
106
113
  <Modal
107
114
  aria-labelledby={headingId}
108
115
  className={toClassName(SIZE_CLASS[size], className)}
116
+ hasMotion={hasMotion}
109
117
  initialFocus={initialFocus}
110
118
  isDismissable={isDismissable}
111
119
  isVisible={isVisible}
@@ -118,8 +118,9 @@ wide list and drops under the text in a narrow one.
118
118
  - `isHighlighted` rings the row and pulses the ring twice — "this one just changed", after a
119
119
  scan or a save. `highlightIntent` picks the colour (`accent` by default). The ring stays
120
120
  while the flag does, so the app decides how long it lasts, usually with a timer. **To pulse
121
- an already-highlighted row again, change its `key`**: a new key is a new row, and a new row
122
- starts the pulse from the beginning. Under `prefers-reduced-motion` and on ePaper the ring
121
+ an already-highlighted row again, change its `highlightKey`**, not its `key`. Rows enter,
122
+ leave, and slide by key, so a new `key` would make the row leave while a copy of it
123
+ entered; a new `highlightKey` restarts only the ring's pulse. Under `prefers-reduced-motion` and on ePaper the ring
123
124
  does not pulse; it is simply there. The pulse lives in `@charcuterie/ui/styles.css`, which
124
125
  every app already imports.
125
126
 
@@ -2,6 +2,8 @@ import {
2
2
  composeStories,
3
3
  composeStory,
4
4
  } from "@storybook/react"
5
+ import { flushSync } from "react-dom"
6
+ import { createRoot } from "react-dom/client"
5
7
  import {
6
8
  expect,
7
9
  userEvent,
@@ -15,6 +17,8 @@ import { expectNoAxeViolations } from "../expectNoAxeViolations.testHelpers.ts"
15
17
  import { mountStory } from "../mountStory.testHelpers.ts"
16
18
  import { expectAgentDrivable } from "../testing/index.ts"
17
19
  import meta, * as stories from "./GroupedList.stories.tsx"
20
+ import type { GroupedListGroup } from "./GroupedList.tsx"
21
+ import { GroupedList } from "./GroupedList.tsx"
18
22
 
19
23
  const {
20
24
  AllStates,
@@ -779,3 +783,282 @@ test("every row state passes axe in both schemes", async () => {
779
783
  await expectNoAxeViolations(canvasElement)
780
784
  }
781
785
  })
786
+
787
+ test("a new highlightKey pulses the ring again without replacing the row", async () => {
788
+ const host = document.createElement("div")
789
+
790
+ document.body.append(host)
791
+
792
+ const root = createRoot(host)
793
+
794
+ const toGroups = (
795
+ highlightKey: number,
796
+ ): GroupedListGroup[] => [
797
+ {
798
+ heading: "Chores",
799
+ items: [
800
+ {
801
+ highlightKey,
802
+ isHighlighted: true,
803
+ key: "dishes",
804
+ label: "Dishes",
805
+ },
806
+ ],
807
+ key: "chores",
808
+ },
809
+ ]
810
+
811
+ try {
812
+ flushSync(() => {
813
+ root.render(<GroupedList groups={toGroups(1)} />)
814
+ })
815
+
816
+ const row = host.querySelector("li") as HTMLElement
817
+
818
+ const ring = row.querySelector(".charcuterie-highlight")
819
+
820
+ expect(ring).not.toBeNull()
821
+
822
+ flushSync(() => {
823
+ root.render(<GroupedList groups={toGroups(2)} />)
824
+ })
825
+
826
+ // The same row, which neither left nor entered…
827
+ expect(host.querySelector("li")).toBe(row)
828
+ expect(row).not.toHaveClass("charcuterie-item-enter")
829
+
830
+ // …wearing a new ring, which starts its pulse from the beginning.
831
+ const nextRing = row.querySelector(
832
+ ".charcuterie-highlight",
833
+ )
834
+
835
+ expect(nextRing).not.toBeNull()
836
+ expect(nextRing).not.toBe(ring)
837
+ } finally {
838
+ root.unmount()
839
+
840
+ host.remove()
841
+ }
842
+ })
843
+
844
+ test("a group an action creates enters, and a group it empties leaves with its last row", async () => {
845
+ // About the motion, so the suite's freeze is lifted for this test.
846
+ const frozenStyle = document.getElementById(
847
+ "charcuterie-freeze-motion",
848
+ )
849
+
850
+ frozenStyle?.remove()
851
+
852
+ const host = document.createElement("div")
853
+
854
+ // Long enough that a loaded host cannot finish the exit first.
855
+ host.style.setProperty("--duration-fast", "600ms")
856
+ host.style.setProperty("--duration-normal", "600ms")
857
+
858
+ document.body.append(host)
859
+
860
+ const root = createRoot(host)
861
+
862
+ const chores: GroupedListGroup = {
863
+ heading: "Chores",
864
+ items: [{ key: "dishes", label: "Dishes" }],
865
+ key: "chores",
866
+ }
867
+
868
+ const reading: GroupedListGroup = {
869
+ heading: "Reading",
870
+ items: [{ key: "book", label: "Book" }],
871
+ key: "reading",
872
+ }
873
+
874
+ const groupOf = (heading: string) =>
875
+ [...host.querySelectorAll("h3")]
876
+ .find((element) => element.textContent === heading)
877
+ ?.closest("[data-motion-key]")
878
+
879
+ try {
880
+ flushSync(() => {
881
+ root.render(<GroupedList groups={[chores]} />)
882
+ })
883
+
884
+ // On the first render, nothing moves.
885
+ expect(groupOf("Chores")?.className).not.toContain(
886
+ "charcuterie-item-enter",
887
+ )
888
+
889
+ flushSync(() => {
890
+ root.render(
891
+ <GroupedList groups={[chores, reading]} />,
892
+ )
893
+ })
894
+
895
+ expect(groupOf("Reading")).toHaveClass(
896
+ "charcuterie-item-enter",
897
+ )
898
+
899
+ flushSync(() => {
900
+ root.render(
901
+ <GroupedList
902
+ groups={[chores, { ...reading, items: [] }]}
903
+ />,
904
+ )
905
+ })
906
+
907
+ // Still drawn, with its last row, while it leaves…
908
+ const leaving = groupOf("Reading")
909
+
910
+ expect(leaving).toHaveClass("charcuterie-item-exit")
911
+ expect(leaving).toHaveAttribute("inert")
912
+ expect(leaving?.textContent).toContain("Book")
913
+
914
+ // …and gone once it has.
915
+ await waitFor(
916
+ () => {
917
+ expect(groupOf("Reading")).toBeUndefined()
918
+ },
919
+ { timeout: 5_000 },
920
+ )
921
+ } finally {
922
+ root.unmount()
923
+
924
+ host.remove()
925
+
926
+ if (frozenStyle !== null) {
927
+ document.head.append(frozenStyle)
928
+ }
929
+ }
930
+ })
931
+
932
+ const mountUnfrozen = () => {
933
+ const frozenStyle = document.getElementById(
934
+ "charcuterie-freeze-motion",
935
+ )
936
+
937
+ frozenStyle?.remove()
938
+
939
+ const host = document.createElement("div")
940
+
941
+ host.style.setProperty("--duration-fast", "600ms")
942
+ host.style.setProperty("--duration-normal", "600ms")
943
+
944
+ document.body.append(host)
945
+
946
+ const root = createRoot(host)
947
+
948
+ return {
949
+ host,
950
+ render: (groups: GroupedListGroup[]) => {
951
+ flushSync(() => {
952
+ root.render(<GroupedList groups={groups} />)
953
+ })
954
+ },
955
+ unmount: () => {
956
+ root.unmount()
957
+
958
+ host.remove()
959
+
960
+ if (frozenStyle !== null) {
961
+ document.head.append(frozenStyle)
962
+ }
963
+ },
964
+ }
965
+ }
966
+
967
+ const toGroup = (key: string, rowKeys: string[]) => ({
968
+ heading: key,
969
+ items: rowKeys.map((rowKey) => ({
970
+ key: rowKey,
971
+ label: rowKey,
972
+ })),
973
+ key,
974
+ })
975
+
976
+ const topOf = (host: HTMLElement, key: string) =>
977
+ (
978
+ host.querySelector(
979
+ `[data-motion-key="${key}"]`,
980
+ ) as HTMLElement
981
+ ).getBoundingClientRect().top
982
+
983
+ test("a row whose group moves in the same commit starts its slide where it was shown", () => {
984
+ const { host, render, unmount } = mountUnfrozen()
985
+
986
+ try {
987
+ render([
988
+ toGroup("A", ["a1", "a2"]),
989
+ toGroup("B", ["b1", "b2"]),
990
+ ])
991
+
992
+ const before = topOf(host, "b1")
993
+
994
+ // B moves above A, and gains a row above b1, in one commit.
995
+ render([
996
+ toGroup("B", ["b0", "b1", "b2"]),
997
+ toGroup("A", ["a1", "a2"]),
998
+ ])
999
+
1000
+ // The row's slide and its group's slide add up to no jump at all.
1001
+ expect(
1002
+ Math.abs(topOf(host, "b1") - before),
1003
+ ).toBeLessThan(2)
1004
+ } finally {
1005
+ unmount()
1006
+ }
1007
+ })
1008
+
1009
+ test("a group below one that gains a row slides down instead of jumping", () => {
1010
+ const { host, render, unmount } = mountUnfrozen()
1011
+
1012
+ try {
1013
+ render([toGroup("A", ["a1"]), toGroup("B", ["b1"])])
1014
+
1015
+ const before = topOf(host, "B")
1016
+
1017
+ render([
1018
+ toGroup("A", ["a1", "a2"]),
1019
+ toGroup("B", ["b1"]),
1020
+ ])
1021
+
1022
+ expect(
1023
+ Math.abs(topOf(host, "B") - before),
1024
+ ).toBeLessThan(2)
1025
+ } finally {
1026
+ unmount()
1027
+ }
1028
+ })
1029
+
1030
+ test("a group below one whose row has finished leaving slides up instead of jumping", async () => {
1031
+ const { host, render, unmount } = mountUnfrozen()
1032
+
1033
+ try {
1034
+ render([
1035
+ toGroup("A", ["a1", "a2"]),
1036
+ toGroup("B", ["b1"]),
1037
+ ])
1038
+
1039
+ const leaving = host.querySelector(
1040
+ '[data-motion-key="a2"]',
1041
+ ) as HTMLElement
1042
+
1043
+ render([toGroup("A", ["a1"]), toGroup("B", ["b1"])])
1044
+
1045
+ const group = host.querySelector(
1046
+ '[data-motion-key="B"]',
1047
+ ) as HTMLElement
1048
+
1049
+ // The leaving row still holds its space, so nothing has moved yet.
1050
+ expect(group.style.transition).toBe("")
1051
+
1052
+ await waitFor(
1053
+ () => {
1054
+ expect(leaving.isConnected).toBe(false)
1055
+ },
1056
+ { timeout: 5_000 },
1057
+ )
1058
+
1059
+ // Its gap closed, and the group below is sliding up into it.
1060
+ expect(group.style.transition).toContain("translate")
1061
+ } finally {
1062
+ unmount()
1063
+ }
1064
+ })
@@ -1,9 +1,11 @@
1
1
  import { useUniqueId } from "@charcuterie/logic"
2
2
  import type { IntentName } from "@charcuterie/tokens"
3
3
  import type { ReactNode } from "react"
4
+ import { useCallback, useState } from "react"
4
5
 
6
+ import { useListMotion } from "../Motion/useListMotion.ts"
5
7
  import { toClassName } from "../toClassName.ts"
6
- import { GroupedListRow } from "./GroupedListRow.tsx"
8
+ import { GroupedListRows } from "./GroupedListRows.tsx"
7
9
  import { STICKY_HEADING_CLASS } from "./groupedListStickyHeading.ts"
8
10
 
9
11
  export type GroupedListHeadingLevel = 2 | 3 | 4 | 5 | 6
@@ -58,13 +60,20 @@ export type GroupedListItem = {
58
60
  * it lasts, usually by clearing it on a timer.
59
61
  *
60
62
  * **To pulse a row that is already highlighted again, change its
61
- * `key`.** A new key is a new row, and a new row starts the pulse
62
- * from the beginning; `` `${id}-${sequence}` `` is the usual shape.
63
+ * `highlightKey`**, not its `key`. Rows enter, leave, and slide
64
+ * with motion, so a new `key` is a new row: the old one would leave
65
+ * while a copy of it entered. A new `highlightKey` starts only the
66
+ * ring's pulse from the beginning; a scan count is the usual value.
63
67
  *
64
68
  * Under `prefers-reduced-motion` and on ePaper the ring does not
65
69
  * pulse; it is simply there.
66
70
  */
67
71
  isHighlighted?: boolean
72
+ /**
73
+ * Changing it restarts the highlight ring's pulse. See
74
+ * `isHighlighted`.
75
+ */
76
+ highlightKey?: number | string
68
77
  /**
69
78
  * `true` draws the row receded — a sunken surface and a quieter
70
79
  * label — for an entry that exists but is switched off. It stays
@@ -245,6 +254,35 @@ export const GroupedList = ({
245
254
  (group) => group.items.length > 0,
246
255
  )
247
256
 
257
+ // Groups move like their rows do. A group an action creates (the
258
+ // first scan of a day) enters with its first row, and a group an
259
+ // action empties leaves with its last row, instead of either one
260
+ // appearing or vanishing in a frame.
261
+ //
262
+ // The row keys are the layout key: a row added to or removed from
263
+ // one group changes its height, and the groups below it slide to
264
+ // their new places with it.
265
+ //
266
+ // A row that finishes leaving closes its gap one render after its
267
+ // key went away, so the rows report it, and that report is part of
268
+ // the layout key too.
269
+ const [rowExitCount, setRowExitCount] = useState(0)
270
+
271
+ const onRowExitEnd = useCallback(() => {
272
+ setRowExitCount((count) => count + 1)
273
+ }, [])
274
+
275
+ const { entries: groupEntries } = useListMotion({
276
+ getKey: (group: GroupedListGroup) => group.key,
277
+ items: shownGroups,
278
+ layoutKey: JSON.stringify([
279
+ shownGroups.map((group) =>
280
+ group.items.map((item) => item.key),
281
+ ),
282
+ rowExitCount,
283
+ ]),
284
+ })
285
+
248
286
  const Heading = HEADING_TAG[headingLevel]
249
287
 
250
288
  return (
@@ -255,58 +293,64 @@ export const GroupedList = ({
255
293
  className,
256
294
  )}
257
295
  >
258
- {shownGroups.length === 0
296
+ {groupEntries.length === 0
259
297
  ? (emptyState ?? null)
260
- : shownGroups.map((group, index) => {
261
- const headingId = `${baseId}-heading-${index}`
298
+ : groupEntries.map(
299
+ (
300
+ { item: group, key, motionProps },
301
+ position,
302
+ ) => {
303
+ // By place in what is drawn, so a leaving group and the
304
+ // group now at its old index never share an id.
305
+ const headingId = `${baseId}-heading-${position}`
262
306
 
263
- return (
264
- <div
265
- className={toClassName(
266
- "flex flex-col",
267
- isHeadingSticky ? "gap-0" : "gap-2",
268
- )}
269
- key={group.key}
270
- >
307
+ return (
271
308
  <div
309
+ {...motionProps}
272
310
  className={toClassName(
273
- "flex flex-wrap items-baseline gap-x-3 gap-y-0.5",
274
- isHeadingSticky && STICKY_HEADING_CLASS,
311
+ "flex flex-col",
312
+ isHeadingSticky ? "gap-0" : "gap-2",
313
+ motionProps.className,
275
314
  )}
315
+ key={key}
276
316
  >
277
- <Heading
317
+ <div
278
318
  className={toClassName(
279
- "m-0 min-w-0 wrap-anywhere font-semibold text-content-primary",
280
- size === "sm" ? "text-sm" : "text-md",
319
+ "flex flex-wrap items-baseline gap-x-3 gap-y-0.5",
320
+ isHeadingSticky &&
321
+ STICKY_HEADING_CLASS,
281
322
  )}
282
- id={headingId}
283
323
  >
284
- {group.heading}
285
- </Heading>
324
+ <Heading
325
+ className={toClassName(
326
+ "m-0 min-w-0 wrap-anywhere font-semibold text-content-primary",
327
+ size === "sm"
328
+ ? "text-sm"
329
+ : "text-md",
330
+ )}
331
+ id={headingId}
332
+ >
333
+ {group.heading}
334
+ </Heading>
286
335
 
287
- {group.summary ? (
288
- <span className="min-w-0 wrap-anywhere text-content-secondary text-sm">
289
- {group.summary}
290
- </span>
291
- ) : null}
292
- </div>
336
+ {group.summary ? (
337
+ <span className="min-w-0 wrap-anywhere text-content-secondary text-sm">
338
+ {group.summary}
339
+ </span>
340
+ ) : null}
341
+ </div>
293
342
 
294
- <ul
295
- aria-labelledby={headingId}
296
- className="m-0 flex list-none flex-col divide-y divide-border-subtle overflow-hidden rounded-md border border-border-subtle bg-surface-raised p-0"
297
- >
298
- {group.items.map((item) => (
299
- <GroupedListRow
300
- isTextTruncated={isTextTruncated}
301
- item={item}
302
- key={item.key}
303
- size={size}
304
- />
305
- ))}
306
- </ul>
307
- </div>
308
- )
309
- })}
343
+ <GroupedListRows
344
+ headingId={headingId}
345
+ onExitEnd={onRowExitEnd}
346
+ isTextTruncated={isTextTruncated}
347
+ items={group.items}
348
+ size={size}
349
+ />
350
+ </div>
351
+ )
352
+ },
353
+ )}
310
354
  </div>
311
355
  )
312
356
  }
@@ -2,6 +2,7 @@ import type { IntentName } from "@charcuterie/tokens"
2
2
  import type { ReactNode } from "react"
3
3
 
4
4
  import { useIsTextClipped } from "../Badge/useIsTextClipped.ts"
5
+ import type { ListMotionProps } from "../Motion/useListMotion.ts"
5
6
  import { toClassName } from "../toClassName.ts"
6
7
  import type {
7
8
  GroupedListItem,
@@ -11,6 +12,8 @@ import type {
11
12
  export type GroupedListRowProps = {
12
13
  isTextTruncated: boolean
13
14
  item: GroupedListItem
15
+ /** From `useListMotion`, so an added row enters and a removed one leaves. */
16
+ motionProps?: ListMotionProps
14
17
  size: GroupedListSize
15
18
  }
16
19
 
@@ -97,6 +100,7 @@ const SELECTABLE_ROW_CLASS =
97
100
  export const GroupedListRow = ({
98
101
  isTextTruncated,
99
102
  item,
103
+ motionProps,
100
104
  size,
101
105
  }: GroupedListRowProps): ReactNode => {
102
106
  const [labelRef, clippedLabel] = useIsTextClipped()
@@ -125,12 +129,14 @@ export const GroupedListRow = ({
125
129
 
126
130
  return (
127
131
  <li
132
+ {...motionProps}
128
133
  className={toClassName(
129
134
  "flex flex-wrap items-center gap-x-3 gap-y-2",
130
135
  ROW_SIZE_CLASS[size],
131
136
  isSelectable && SELECTABLE_ROW_CLASS,
132
137
  isHighlighted && "relative",
133
138
  isMuted && "bg-surface-sunken",
139
+ motionProps?.className,
134
140
  )}
135
141
  >
136
142
  {isSelectable ? (
@@ -231,6 +237,8 @@ export const GroupedListRow = ({
231
237
  {isHighlighted ? (
232
238
  <span
233
239
  aria-hidden
240
+ // A new key is a new ring, and a new ring pulses again.
241
+ key={item.highlightKey}
234
242
  className={toClassName(
235
243
  "charcuterie-highlight pointer-events-none absolute inset-0 inset-ring-2",
236
244
  HIGHLIGHT_RING_CLASS[highlightIntent],
@@ -0,0 +1,51 @@
1
+ import type { ReactNode } from "react"
2
+
3
+ import { useListMotion } from "../Motion/useListMotion.ts"
4
+ import type {
5
+ GroupedListItem,
6
+ GroupedListSize,
7
+ } from "./GroupedList.tsx"
8
+ import { GroupedListRow } from "./GroupedListRow.tsx"
9
+
10
+ /**
11
+ * One group's rows, in their own component so each group can hold the
12
+ * `useListMotion` hook: an added row enters, a removed one leaves, and
13
+ * the rest slide, which a `map` over groups cannot do inline.
14
+ */
15
+ export const GroupedListRows = ({
16
+ headingId,
17
+ isTextTruncated,
18
+ items,
19
+ onExitEnd,
20
+ size,
21
+ }: {
22
+ headingId: string
23
+ isTextTruncated: boolean
24
+ /** A row finished leaving; the groups below are about to move. */
25
+ onExitEnd: () => void
26
+ items: readonly GroupedListItem[]
27
+ size: GroupedListSize
28
+ }): ReactNode => {
29
+ const { entries } = useListMotion({
30
+ getKey: (item: GroupedListItem) => item.key,
31
+ items,
32
+ onExitEnd,
33
+ })
34
+
35
+ return (
36
+ <ul
37
+ aria-labelledby={headingId}
38
+ className="m-0 flex list-none flex-col divide-y divide-border-subtle overflow-hidden rounded-md border border-border-subtle bg-surface-raised p-0"
39
+ >
40
+ {entries.map(({ item, key, motionProps }) => (
41
+ <GroupedListRow
42
+ isTextTruncated={isTextTruncated}
43
+ item={item}
44
+ key={key}
45
+ motionProps={motionProps}
46
+ size={size}
47
+ />
48
+ ))}
49
+ </ul>
50
+ )
51
+ }
@@ -122,6 +122,9 @@ export const Listbox = ({
122
122
  context,
123
123
  floatingStyles,
124
124
  getFloatingProps,
125
+ isExiting,
126
+ isMounted,
127
+ motionClassName,
125
128
  setFloating,
126
129
  triggerId,
127
130
  } = useAnchoredOverlay({
@@ -204,10 +207,12 @@ export const Listbox = ({
204
207
  <>
205
208
  {clonedTrigger}
206
209
 
207
- {isVisible ? (
210
+ {isMounted ? (
208
211
  <FloatingPortal>
209
212
  <FloatingFocusManager
210
213
  context={context}
214
+ // A leaving panel hands focus back at once.
215
+ disabled={isExiting}
211
216
  initialFocus={-1}
212
217
  modal={false}
213
218
  >
@@ -223,6 +228,7 @@ export const Listbox = ({
223
228
  // middleware (`maxHeightPx`), written as an inline
224
229
  // style; this scrolls within it.
225
230
  "z-[var(--layer-modal)] flex min-w-48 flex-col gap-0.5 overflow-auto p-1",
231
+ motionClassName,
226
232
  className,
227
233
  )}
228
234
  onKeyDown={(keyEvent) => {
@@ -267,6 +273,8 @@ export const Listbox = ({
267
273
  runTypeahead(keyEvent.key)
268
274
  }
269
275
  }}
276
+ aria-hidden={isExiting ? true : undefined}
277
+ inert={isExiting ? true : undefined}
270
278
  ref={setFloating}
271
279
  // Duplicated from `getFloatingProps()` on purpose, and
272
280
  // the two cannot differ — `useRole(context, { role: