@charcuterie/ui 3.33.0 → 4.0.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 (105) hide show
  1. package/README.md +30 -0
  2. package/dist/Board/Board.d.ts.map +1 -1
  3. package/dist/Board/Board.js +2 -2
  4. package/dist/Board/Board.js.map +1 -1
  5. package/dist/Main/Main.d.ts +18 -19
  6. package/dist/Main/Main.d.ts.map +1 -1
  7. package/dist/Main/Main.js +21 -10
  8. package/dist/Main/Main.js.map +1 -1
  9. package/dist/Main/ScrollMemoryProvider.d.ts +38 -0
  10. package/dist/Main/ScrollMemoryProvider.d.ts.map +1 -0
  11. package/dist/Main/ScrollMemoryProvider.js +30 -0
  12. package/dist/Main/ScrollMemoryProvider.js.map +1 -0
  13. package/dist/Main/scrollMemory.d.ts +54 -28
  14. package/dist/Main/scrollMemory.d.ts.map +1 -1
  15. package/dist/Main/scrollMemory.js +81 -40
  16. package/dist/Main/scrollMemory.js.map +1 -1
  17. package/dist/Main/scrollMemoryContext.d.ts +18 -0
  18. package/dist/Main/scrollMemoryContext.d.ts.map +1 -0
  19. package/dist/Main/scrollMemoryContext.js +18 -0
  20. package/dist/Main/scrollMemoryContext.js.map +1 -0
  21. package/dist/Main/useScrollMemory.d.ts +20 -18
  22. package/dist/Main/useScrollMemory.d.ts.map +1 -1
  23. package/dist/Main/useScrollMemory.js +69 -42
  24. package/dist/Main/useScrollMemory.js.map +1 -1
  25. package/dist/RangeSlider/RangeSlider.d.ts +117 -0
  26. package/dist/RangeSlider/RangeSlider.d.ts.map +1 -0
  27. package/dist/RangeSlider/RangeSlider.js +242 -0
  28. package/dist/RangeSlider/RangeSlider.js.map +1 -0
  29. package/dist/RangeSlider/rangeSliderValue.d.ts +102 -0
  30. package/dist/RangeSlider/rangeSliderValue.d.ts.map +1 -0
  31. package/dist/RangeSlider/rangeSliderValue.js +116 -0
  32. package/dist/RangeSlider/rangeSliderValue.js.map +1 -0
  33. package/dist/SegmentedControl/SegmentedControl.d.ts +12 -1
  34. package/dist/SegmentedControl/SegmentedControl.d.ts.map +1 -1
  35. package/dist/SegmentedControl/SegmentedControl.js +3 -3
  36. package/dist/SegmentedControl/SegmentedControl.js.map +1 -1
  37. package/dist/SegmentedControl/SegmentedOption.d.ts +2 -1
  38. package/dist/SegmentedControl/SegmentedOption.d.ts.map +1 -1
  39. package/dist/SegmentedControl/SegmentedOption.js +7 -2
  40. package/dist/SegmentedControl/SegmentedOption.js.map +1 -1
  41. package/dist/Slider/Slider.d.ts +6 -1
  42. package/dist/Slider/Slider.d.ts.map +1 -1
  43. package/dist/Slider/Slider.js +8 -22
  44. package/dist/Slider/Slider.js.map +1 -1
  45. package/dist/TimecodeInput/TimecodeInput.d.ts +88 -0
  46. package/dist/TimecodeInput/TimecodeInput.d.ts.map +1 -0
  47. package/dist/TimecodeInput/TimecodeInput.js +258 -0
  48. package/dist/TimecodeInput/TimecodeInput.js.map +1 -0
  49. package/dist/TimecodeInput/timecode.d.ts +132 -0
  50. package/dist/TimecodeInput/timecode.d.ts.map +1 -0
  51. package/dist/TimecodeInput/timecode.js +246 -0
  52. package/dist/TimecodeInput/timecode.js.map +1 -0
  53. package/dist/index.d.ts +10 -0
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.js +4 -0
  56. package/dist/index.js.map +1 -1
  57. package/dist/reactRouter/ReactRouterAdapter.d.ts +43 -0
  58. package/dist/reactRouter/ReactRouterAdapter.d.ts.map +1 -0
  59. package/dist/reactRouter/ReactRouterAdapter.js +50 -0
  60. package/dist/reactRouter/ReactRouterAdapter.js.map +1 -0
  61. package/dist/reactRouter/index.d.ts +14 -8
  62. package/dist/reactRouter/index.d.ts.map +1 -1
  63. package/dist/reactRouter/index.js +13 -8
  64. package/dist/reactRouter/index.js.map +1 -1
  65. package/dist/sliderStyles.d.ts +39 -0
  66. package/dist/sliderStyles.d.ts.map +1 -0
  67. package/dist/sliderStyles.js +50 -0
  68. package/dist/sliderStyles.js.map +1 -0
  69. package/package.json +1 -1
  70. package/src/Board/Board.test.tsx +8 -0
  71. package/src/Board/Board.tsx +7 -1
  72. package/src/Main/Main.mdx +35 -7
  73. package/src/Main/Main.stories.tsx +129 -64
  74. package/src/Main/Main.test.tsx +58 -0
  75. package/src/Main/Main.tsx +20 -20
  76. package/src/Main/ScrollMemoryProvider.tsx +48 -0
  77. package/src/Main/scrollMemory.test.ts +70 -16
  78. package/src/Main/scrollMemory.ts +98 -40
  79. package/src/Main/scrollMemoryContext.ts +21 -0
  80. package/src/Main/useScrollMemory.ts +83 -43
  81. package/src/RangeSlider/RangeSlider.mdx +85 -0
  82. package/src/RangeSlider/RangeSlider.stories.tsx +346 -0
  83. package/src/RangeSlider/RangeSlider.test.tsx +452 -0
  84. package/src/RangeSlider/RangeSlider.tsx +595 -0
  85. package/src/RangeSlider/rangeSliderValue.test.ts +217 -0
  86. package/src/RangeSlider/rangeSliderValue.ts +185 -0
  87. package/src/RouterLink/RouterLink.mdx +53 -16
  88. package/src/SegmentedControl/SegmentedControl.stories.tsx +50 -0
  89. package/src/SegmentedControl/SegmentedControl.test.tsx +36 -1
  90. package/src/SegmentedControl/SegmentedControl.tsx +14 -0
  91. package/src/SegmentedControl/SegmentedOption.tsx +7 -0
  92. package/src/Slider/Slider.tsx +23 -29
  93. package/src/TimecodeInput/TimecodeInput.mdx +155 -0
  94. package/src/TimecodeInput/TimecodeInput.stories.tsx +304 -0
  95. package/src/TimecodeInput/TimecodeInput.test.tsx +279 -0
  96. package/src/TimecodeInput/TimecodeInput.tsx +493 -0
  97. package/src/TimecodeInput/timecode.test.ts +236 -0
  98. package/src/TimecodeInput/timecode.ts +391 -0
  99. package/src/index.ts +21 -0
  100. package/src/reactRouter/ReactRouterAdapter.stories.tsx +120 -0
  101. package/src/reactRouter/ReactRouterAdapter.test.tsx +92 -0
  102. package/src/reactRouter/ReactRouterAdapter.tsx +66 -0
  103. package/src/reactRouter/index.ts +14 -8
  104. package/src/sliderStyles.ts +69 -0
  105. package/src/sourceRules.test.ts +29 -3
@@ -1,73 +1,131 @@
1
1
  /**
2
- * What the browser will not remember for you.
2
+ * What the browser will not remember for you, and the one thing it
3
+ * would never have got wrong.
3
4
  *
4
- * `Shell` gives `<main>` the page's only vertical scrollport, so
5
- * the header and the rails stay put while the content moves —
6
- * that is the whole reason `Shell.test.tsx` asserts "only main
7
- * scrolls vertically, keeping the rail available".
8
- *
9
- * It costs exactly one thing, and this module is it. A browser
10
- * remembers **the document scroller's** offset per history entry
11
- * and puts it back on Back. It does that for a cross-document
12
- * load, and `history.scrollRestoration` is the switch for it. It
13
- * does **not** do it for an arbitrary element with
14
- * `overflow-y: auto`, and it does not do it at all for a
15
- * same-document `pushState` navigation, which is every link press
16
- * in a single-page app. So a page that scrolls its own `<main>`
17
- * loses the reader's place on Back, and no browser setting brings
18
- * it back:
5
+ * `Shell` gives `<main>` the page's only vertical scrollport, so the
6
+ * header and the rails stay put while the content moves — that is
7
+ * what `Shell.test.tsx` asserts. It costs exactly one thing, and
8
+ * this module is it. A browser remembers **the document scroller's**
9
+ * offset per history entry and puts it back on Back. It does not do
10
+ * that for an arbitrary element with `overflow-y: auto`, and it does
11
+ * not do it at all for a same-document `pushState` navigation, which
12
+ * is every link press in a single-page app:
19
13
  *
20
14
  * > *"If I scroll, click on an item, then go back, it resets me to
21
15
  * > the top. […] It should remember where the scroll position was
22
16
  * > previously. Isn't this handled by Chrome already?"*
23
17
  *
24
- * The offsets are held **in memory**, not in `sessionStorage`. A
25
- * history key survives a reload, but the DOM it described does
26
- * not: the app re-fetches, re-measures and often re-orders, so a
27
- * pixel offset from before the reload points at a different row.
28
- * Restoring a stale number is worse than restoring nothing,
29
- * because it looks deliberate.
18
+ * ## An entry remembers its PATH as well as its offset
19
+ *
20
+ * Not decoration — the second field is what keeps this from being a
21
+ * worse bug than the one it fixes. A history entry is not a page. A
22
+ * filter chip, an expanded group, a selected tab: each writes a
23
+ * search param, and **`setSearchParams` navigates**, so each mints a
24
+ * history entry the memory has never seen. Treating an unseen entry
25
+ * as "start at the top" therefore threw the reader to the top of the
26
+ * list every time they opened a group — which is exactly what
27
+ * shipped, and what the path comparison exists to prevent.
28
+ *
29
+ * So the rule is about the PAGE, not the entry:
30
+ *
31
+ * - **An entry we have seen** → its remembered offset. This is the
32
+ * whole feature: Back and Forward land where you left them.
33
+ * - **A new entry on the SAME path** → leave the scrollport alone.
34
+ * A search param changed; the reader did not go anywhere. This is
35
+ * also precisely what the app did before this memory existed, so
36
+ * it can never be a regression.
37
+ * - **A new entry on a DIFFERENT path** → the top. A page you have
38
+ * not seen starts at its beginning, which is what a browser does
39
+ * for a document.
40
+ *
41
+ * ## The offsets are in memory, never `sessionStorage`
42
+ *
43
+ * A history key survives a reload; the DOM it described does not.
44
+ * The app re-fetches, re-measures and often re-orders, so a pixel
45
+ * offset from before the reload points at a different row. Restoring
46
+ * a stale number is worse than restoring nothing, because it looks
47
+ * deliberate.
30
48
  */
31
49
 
32
50
  /**
33
51
  * How many history entries keep an offset. A reader goes back
34
52
  * through a handful of screens, never fifty, so this is a ceiling
35
53
  * against a long session rather than a working set — the map holds
36
- * one small number per entry and evicts the least recently
37
- * written.
54
+ * one small record per entry and evicts the least recently written.
38
55
  */
39
56
  const REMEMBERED_ENTRY_LIMIT = 50
40
57
 
41
- const rememberedOffsets = new Map<string, number>()
58
+ export type ScrollEntry = {
59
+ /** The history entry — react-router's `useLocation().key`. */
60
+ key: string
61
+ /** The page it belongs to — `useLocation().pathname`. */
62
+ path: string
63
+ }
64
+
65
+ type RememberedEntry = {
66
+ offset: number
67
+ path: string
68
+ }
69
+
70
+ const rememberedEntries = new Map<string, RememberedEntry>()
71
+
72
+ /**
73
+ * The entry the scrollport is showing. Module state rather than a
74
+ * ref, because the question it answers — *did the reader change page
75
+ * or only a search param?* — is asked by the incoming entry's effect
76
+ * about the OUTGOING one, and by then the outgoing effect has
77
+ * already been cleaned up.
78
+ */
79
+ let currentEntry: ScrollEntry | null = null
42
80
 
43
81
  export const rememberScrollOffset = (
44
- key: string,
82
+ entry: ScrollEntry,
45
83
  offset: number,
46
84
  ) => {
47
- // Delete before set, so insertion order is least-recent-first
48
- // and the eviction below takes the right one. A plain `set` on
49
- // an existing key keeps its original position.
50
- rememberedOffsets.delete(key)
51
- rememberedOffsets.set(key, offset)
85
+ // Delete before set, so insertion order is least-recent-first and
86
+ // the eviction below takes the right one. A plain `set` on an
87
+ // existing key keeps its original position.
88
+ rememberedEntries.delete(entry.key)
89
+ rememberedEntries.set(entry.key, {
90
+ offset,
91
+ path: entry.path,
92
+ })
52
93
 
53
- for (const oldestKey of rememberedOffsets.keys()) {
54
- if (rememberedOffsets.size <= REMEMBERED_ENTRY_LIMIT) {
94
+ for (const oldestKey of rememberedEntries.keys()) {
95
+ if (rememberedEntries.size <= REMEMBERED_ENTRY_LIMIT) {
55
96
  break
56
97
  }
57
98
 
58
- rememberedOffsets.delete(oldestKey)
99
+ rememberedEntries.delete(oldestKey)
59
100
  }
60
101
  }
61
102
 
62
103
  /**
63
- * `0` for an entry nobody has scrolled, which is also the right
64
- * answer for an entry nobody has *seen* — a link press lands at
65
- * the top of the new page.
104
+ * Where the scrollport should go for this entry, or `null` for
105
+ * **leave it alone** — which is a third answer rather than a missing
106
+ * one, and the difference between a search param and a page.
66
107
  */
67
- export const recallScrollOffset = (key: string) =>
68
- rememberedOffsets.get(key) ?? 0
108
+ export const resolveScrollOffset = (entry: ScrollEntry) => {
109
+ const remembered = rememberedEntries.get(entry.key)
110
+
111
+ if (remembered) {
112
+ return remembered.offset
113
+ }
114
+
115
+ const isSamePage =
116
+ currentEntry !== null &&
117
+ currentEntry.path === entry.path
118
+
119
+ return isSamePage ? null : 0
120
+ }
121
+
122
+ /** Called by the hook once it owns the scrollport for this entry. */
123
+ export const enterScrollEntry = (entry: ScrollEntry) => {
124
+ currentEntry = entry
125
+ }
69
126
 
70
127
  /** Test-only. Module state outlives a mount; a test must not. */
71
128
  export const forgetScrollOffsets = () => {
72
- rememberedOffsets.clear()
129
+ rememberedEntries.clear()
130
+ currentEntry = null
73
131
  }
@@ -0,0 +1,21 @@
1
+ import { createContext } from "react"
2
+
3
+ import type { ScrollEntry } from "./scrollMemory.ts"
4
+
5
+ /**
6
+ * How the history entry reaches `Main` without `Main` knowing a
7
+ * router exists.
8
+ *
9
+ * `@charcuterie/ui`'s main entry is router-free and stays that way —
10
+ * `sourceRules.test.ts` asserts it, and the fleet runs five
11
+ * different routers. So the entry arrives as a plain
12
+ * `{ key, path }`, and the one component that knows how to read it
13
+ * from react-router lives in the `./react-router` subpath.
14
+ *
15
+ * A context rather than a prop, because the alternative is a prop
16
+ * every app has to remember on every `Main` it renders. It was a
17
+ * prop first, exactly once, and three of the four apps that needed
18
+ * it did not have it.
19
+ */
20
+ export const ScrollMemoryContext =
21
+ createContext<ScrollEntry | null>(null)
@@ -1,8 +1,10 @@
1
1
  import { useCallback, useLayoutEffect, useRef } from "react"
2
2
 
3
3
  import {
4
- recallScrollOffset,
4
+ enterScrollEntry,
5
5
  rememberScrollOffset,
6
+ resolveScrollOffset,
7
+ type ScrollEntry,
6
8
  } from "./scrollMemory.ts"
7
9
 
8
10
  /**
@@ -11,11 +13,11 @@ import {
11
13
  *
12
14
  * The offset cannot be applied until the scrollport is tall enough
13
15
  * to hold it, and on a client-rendered page it is not: the commit
14
- * that changes the route draws a skeleton, and the rows land a
15
- * fetch later. So the restore re-applies as the content grows, and
16
- * gives up after this. A page that takes longer than three seconds
17
- * to fill has already been read from the top, and moving it then
18
- * is a worse answer than leaving it where the reader put it.
16
+ * that changes the route draws a skeleton, and the rows land a fetch
17
+ * later. So the restore re-applies as the content grows, and gives
18
+ * up after this. A page that takes longer than three seconds to fill
19
+ * has already been read from the top, and moving it then is a worse
20
+ * answer than leaving it where the reader put it.
19
21
  */
20
22
  const RESTORE_WINDOW_MS = 3000
21
23
 
@@ -28,41 +30,42 @@ const READER_INTENT_EVENTS = [
28
30
  ] as const
29
31
 
30
32
  /**
31
- * Remember where this history entry was scrolled to, and put it
32
- * back when the reader returns to it.
33
+ * Remember where this history entry was scrolled to, and put it back
34
+ * when the reader returns to it.
33
35
  *
34
- * `scrollMemory.ts` says why the browser will not. This is the
35
- * part that has to survive the two things a real page does:
36
+ * `scrollMemory.ts` says why the browser will not, and what an entry
37
+ * that has never been seen should do. This is the part that has to
38
+ * survive the two things a real page does:
36
39
  *
37
40
  * 1. **The content arrives late.** An offset applied against a
38
- * 600px skeleton clamps to `0` and looks like it did nothing.
39
- * A `ResizeObserver` on the scrollport and on its content
40
- * column re-applies the offset every time either grows, until
41
- * the offset lands or the window closes.
42
- * 2. **The reader scrolls during all that.** Any wheel, touch,
43
- * key or pointer press ends the restore immediately. The
44
- * alternative is a page that jumps out from under somebody who
45
- * has already started reading.
41
+ * 600px skeleton clamps to `0` and looks like it did nothing. A
42
+ * `ResizeObserver` on the scrollport and on its content column
43
+ * re-applies the offset every time either grows, until the
44
+ * offset lands or the window closes.
45
+ * 2. **The reader scrolls during all that.** Any wheel, touch, key
46
+ * or pointer press ends the restore immediately. The alternative
47
+ * is a page that jumps out from under somebody who has already
48
+ * started reading.
46
49
  *
47
50
  * The save is a passive `scroll` listener, suppressed while a
48
51
  * restore is in flight. Without that suppression the feature eats
49
52
  * itself: writing `scrollTop` on a still-short page clamps to `0`
50
- * and fires a `scroll` event reading `0`, which would be saved
51
- * over the very offset being restored.
53
+ * and fires a `scroll` event reading `0`, which would be saved over
54
+ * the very offset being restored.
52
55
  *
53
- * @param scrollKey Identifies the history entry — react-router's
54
- * `useLocation().key`. `undefined` turns the memory off, which is
55
- * what an app with no router gets.
56
+ * @param entry The history entry and the page it belongs to.
57
+ * `null` turns the memory off, which is what an app that renders
58
+ * no `ScrollMemoryProvider` gets.
56
59
  */
57
60
  export const useScrollMemory = (
58
- scrollKey: string | undefined,
61
+ entry: ScrollEntry | null | undefined,
59
62
  ) => {
60
63
  const elementRef = useRef<HTMLElement | null>(null)
61
64
  const isRestoringRef = useRef(false)
62
65
 
63
- // A ref rather than a query for the `<main>` id: the effect
64
- // below runs in the same commit that mounts the node, and only a
65
- // ref can say which node that was.
66
+ // A ref rather than a query for the `<main>` id: the effect below
67
+ // runs in the same commit that mounts the node, and only a ref can
68
+ // say which node that was.
66
69
  //
67
70
  // `unknown` in, narrowed here, so the returned function is both a
68
71
  // `RefCallback<HTMLElement>` and something `mergeRefs` accepts —
@@ -73,18 +76,43 @@ export const useScrollMemory = (
73
76
  node instanceof HTMLElement ? node : null
74
77
  }, [])
75
78
 
79
+ const key = entry?.key
80
+ const path = entry?.path
81
+
76
82
  useLayoutEffect(() => {
77
83
  const element = elementRef.current
78
84
 
79
- if (!element || scrollKey === undefined) {
85
+ if (
86
+ !element ||
87
+ key === undefined ||
88
+ path === undefined
89
+ ) {
80
90
  return undefined
81
91
  }
82
92
 
83
- const offset = recallScrollOffset(scrollKey)
84
-
85
- // The arrow defers the read of `applyOffset`, so the three
86
- // pieces can be declared in the order they depend on each
87
- // other rather than in the order they are used.
93
+ const currentEntry = { key, path }
94
+
95
+ // `null` means leave the scrollport alone: a search param
96
+ // changed and the reader did not go anywhere. It is read BEFORE
97
+ // this entry becomes the current one, because the answer depends
98
+ // on the page the reader is arriving from.
99
+ const offset = resolveScrollOffset(currentEntry)
100
+
101
+ enterScrollEntry(currentEntry)
102
+
103
+ // Seed the entry now rather than waiting for a `scroll` event.
104
+ // A reader who opens a group and then follows a link never
105
+ // scrolls in between, so without this the entry they came from
106
+ // is one the memory has never seen — and Back would send them to
107
+ // the top of a list they were half-way down.
108
+ rememberScrollOffset(
109
+ currentEntry,
110
+ offset ?? element.scrollTop,
111
+ )
112
+
113
+ // The arrow defers the read of `applyOffset`, so the pieces can
114
+ // be declared in the order they depend on each other rather than
115
+ // in the order they are used.
88
116
  const observer = new ResizeObserver(() => {
89
117
  applyOffset()
90
118
  })
@@ -93,12 +121,9 @@ export const useScrollMemory = (
93
121
  stopRestoring()
94
122
  }, RESTORE_WINDOW_MS)
95
123
 
96
- const stopRestoring = () => {
97
- if (!isRestoringRef.current) {
98
- return
99
- }
124
+ let isRestoring = offset !== null
100
125
 
101
- isRestoringRef.current = false
126
+ const teardown = () => {
102
127
  observer.disconnect()
103
128
  globalThis.clearTimeout(deadline)
104
129
 
@@ -110,8 +135,18 @@ export const useScrollMemory = (
110
135
  }
111
136
  }
112
137
 
138
+ const stopRestoring = () => {
139
+ if (!isRestoring) {
140
+ return
141
+ }
142
+
143
+ isRestoring = false
144
+ isRestoringRef.current = false
145
+ teardown()
146
+ }
147
+
113
148
  const applyOffset = () => {
114
- if (!isRestoringRef.current) {
149
+ if (!isRestoring || offset === null) {
115
150
  return
116
151
  }
117
152
 
@@ -128,10 +163,10 @@ export const useScrollMemory = (
128
163
  return
129
164
  }
130
165
 
131
- rememberScrollOffset(scrollKey, element.scrollTop)
166
+ rememberScrollOffset(currentEntry, element.scrollTop)
132
167
  }
133
168
 
134
- isRestoringRef.current = true
169
+ isRestoringRef.current = isRestoring
135
170
 
136
171
  for (const eventName of READER_INTENT_EVENTS) {
137
172
  element.addEventListener(eventName, stopRestoring, {
@@ -155,10 +190,15 @@ export const useScrollMemory = (
155
190
  applyOffset()
156
191
 
157
192
  return () => {
158
- stopRestoring()
193
+ // Unconditional, unlike `stopRestoring` — a restore that
194
+ // already landed still has an observer and four listeners on
195
+ // an element the next entry is about to use, and a stale
196
+ // observer that survives its effect applies a stale offset.
197
+ isRestoring = false
198
+ teardown()
159
199
  element.removeEventListener("scroll", onScroll)
160
200
  }
161
- }, [scrollKey])
201
+ }, [key, path])
162
202
 
163
203
  return setElement
164
204
  }
@@ -0,0 +1,85 @@
1
+ import { Canvas, Controls, Meta } from "@storybook/addon-docs/blocks";
2
+
3
+ import * as RangeSliderStories from "./RangeSlider.stories";
4
+
5
+ <Meta of={RangeSliderStories} />
6
+
7
+ # RangeSlider
8
+
9
+ A span picked out along a bar, with an independently focusable handle at each end.
10
+
11
+ It exists because QueuePilot plays **only a section** of a video: a user drags two handles
12
+ over a film's runtime to choose where a clip starts and ends, and has to see the section
13
+ they typed into a `TimecodeInput` beside it. So the shape this is built for is a media
14
+ timeline — a bar spanning the whole runtime, two thumbs, and the chosen span painted
15
+ between them.
16
+
17
+ <Canvas of={RangeSliderStories.Default} />
18
+
19
+ ## Props
20
+
21
+ <Controls />
22
+
23
+ ## Why this is a component and not `Slider isRange`
24
+
25
+ `Combobox`'s `isMultiple` and `DatePicker`'s `isRange` are **modes**, and the test that
26
+ made them modes is written down: the widget's ARIA role does not change, and the two shapes
27
+ share nearly everything. Both halves of that test fail here.
28
+
29
+ [`Slider` puts `role="slider"`, the tab stop and the pointer target on the **track**](?path=/docs/components-controls-slider--docs),
30
+ because one track reports one value. Two values cannot live on one accessible object — so
31
+ here the role moves to the thumbs, the track becomes a `role="group"` carrying the label,
32
+ and the tab stops go from one to two. A mode that rewrote its own role would break
33
+ `getByRole("slider", { name })` in every consumer that had used the single-value one.
34
+
35
+ `Slider`'s own record says it plainly: *"a two-thumb range is a different widget with its
36
+ own focus model"*.
37
+
38
+ What the two genuinely share is the **arithmetic** (`Slider/sliderValue.ts`, called rather
39
+ than copied, so both snap on the same grid) and the **bar** (`sliderStyles.ts`). The test
40
+ compares the two thumbs as computed styles, not as class names.
41
+
42
+ <Canvas of={RangeSliderStories.BesideTheSlider} />
43
+
44
+ ## The thumbs clamp, they do not swap
45
+
46
+ A thumb dragged past its partner stops **on** it. The range collapses to zero width, both
47
+ handles keep their identities, and the next press opens it again from whichever side that
48
+ press lands on.
49
+
50
+ Swapping is the other defensible answer and is the wrong one here. The two handles are a
51
+ clip's start and its end, read alongside a field that names them; a drag that silently
52
+ renamed the handle under the pointer would move a number the user is reading somewhere
53
+ else. On the keyboard it is plainer still — swapping means one ArrowRight moves the *other*
54
+ thumb, and the element with focus is no longer the value that changed.
55
+
56
+ Each thumb reports the other as its own `aria-valuemin` / `aria-valuemax`, which is how a
57
+ screen reader is told where this handle stops.
58
+
59
+ <Canvas of={RangeSliderStories.AllStates} />
60
+
61
+ ## Drag does not commit
62
+
63
+ `onChange` fires on every movement — each arrow key, each pointer sample. `onChangeEnd`
64
+ fires once, on release or key up.
65
+
66
+ The same split `Slider` settled, for the same reason: a clip preview that re-seeks a player
67
+ from `onChange` issues one seek per pointer sample and arrives at the right frame **last**,
68
+ behind a queue of stale ones. While a drag is in flight the component paints from its own
69
+ value rather than from `value`, so a caller that commits on `onChangeEnd` alone still sees
70
+ the thumbs follow the pointer.
71
+
72
+ <Canvas of={RangeSliderStories.Interactive} />
73
+
74
+ ## The app owns the data
75
+
76
+ `valueFormat` turns a number into whatever the value **is** — `21:14`, `$40`, `3.5 km`. The
77
+ component never learns what a timecode is: it knows a number, and the app knows what the
78
+ number means. That one function feeds `aria-valuetext` and the shown span both.
79
+
80
+ `ticks` is the same division. A tick is `{ label?, value }` and nothing else, so a film's
81
+ chapters are the offsets the app already has. There is no chapter model in here, and the
82
+ marks are `aria-hidden` — each thumb already announces its own position, so a screen reader
83
+ reading the marks between them would be reading the picture.
84
+
85
+ <Canvas of={RangeSliderStories.AllVariants} />