Audit fixes: a11y, gesture correctness, math edge cases

- Keyboard focus-visible ring on all controls (WCAG 2.4.7), suppressed
  for pointer grabs; focusRing prop to customize or disable
- aria-orientation on track modes; data-dragging/-disabled/-readonly/
  -focus-visible state attributes; disabled dims, readOnly drops the
  grab cursor
- Escape cancels a drag and restores the pre-gesture value
- Controlled mode no longer desyncs when the parent rejects onChange
- Second concurrent pointer can no longer hijack a drag session;
  drags cancel when disabled/readOnly flips mid-gesture
- Wheel: onChangeStart symmetry, settle flush on unsubscribe, dominant-
  axis direction (fixes macOS Shift+scroll reversal), ignored mid-drag
- Shift+wheel and fine multipliers now work on stepped/values knobs
- Fader/LEDFader track mapping inset-aligned with handle travel (no
  value jump when grabbing the cap); LEDFader zones sorted
- roundTo no longer returns NaN for exponential-notation values;
  logTaper falls back to linear for invalid ranges; decimalsFromStep
  shaves float noise; findClosest([]) returns the input
- Double-click reset brackets with onChangeStart/End
- MetalKnob honors showValue/unit/format; VintageKnob omits them from
  its type; TickLabels extracted as a public primitive
- SegmentDisplay: letters/hex charset, dash overflow instead of 888
This commit is contained in:
Dreamodus 2026-07-12 14:38:50 -07:00
parent 60a02cb1db
commit da352d3695
13 changed files with 378 additions and 82 deletions

View file

@ -6,6 +6,11 @@ import { useKnob } from '../hooks/useKnob';
export interface KnobProps extends KnobCoreProps {
/** Square canvas size in px. Default: 80. */
size?: number;
/**
* Color of the keyboard focus ring, or `false` to disable it (only do this
* if you render your own focus indicator). Default: a soft blue.
*/
focusRing?: string | false;
className?: string;
style?: React.CSSProperties;
/** SVG children (Arc, Pointer, Ticks, ...) or a render function receiving the live state. */
@ -21,6 +26,7 @@ export interface KnobProps extends KnobCoreProps {
*/
export const Knob: React.FC<KnobProps> = ({
size = 80,
focusRing = 'rgba(130,180,255,0.65)',
className,
style,
children,
@ -52,6 +58,10 @@ export const Knob: React.FC<KnobProps> = ({
position: 'relative',
width: size,
height: size,
borderRadius: '50%',
...(knob.isFocusVisible && focusRing
? { boxShadow: `0 0 0 2px ${focusRing}` }
: undefined),
...knob.bind.style,
...style,
}}