(clientX: number)
| 240 | // the pill moves in the bar's own, unscaled pixels: map through the |
| 241 | // layout width so the pill stops at the right edge as it does at the left. |
| 242 | const tabAt = (clientX: number) => { |
| 243 | const track = trackRef.current; |
| 244 | const rect = track?.getBoundingClientRect(); |
| 245 | if (!track || !rect || !rect.width) { |
| 246 | return null; |
| 247 | } |
| 248 | const trackWidth = track.offsetWidth || rect.width; |
| 249 | const width = trackWidth / tabs.length; |
| 250 | const x = ((clientX - rect.left) / rect.width) * trackWidth; |
| 251 | return { |
| 252 | left: Math.min(Math.max(x - width / 2, 0), trackWidth - width), |
| 253 | index: Math.min( |
| 254 | tabs.length - 1, |
| 255 | Math.floor(clamp(x / trackWidth) * tabs.length), |
| 256 | ), |
| 257 | }; |
| 258 | }; |
| 259 | |
| 260 | const onPointerDown = (event: React.PointerEvent<HTMLDivElement>) => { |
| 261 | if (event.pointerType === 'mouse' && event.button !== 0) { |
no test coverage detected