Repository navigation
FE-2385: Build new Salt slider UI + api - #10691
alex-e-leon wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryHigh Risk Overview Implementation is largely new: Call sites in this PR are updated: brunch voice audio controls; petrinaut drops its native Reviewed by Cursor Bugbot for commit d2aceff. Bugbot is set up for automated code reviews on this repo. Configure here. |
b2cc00c to
4bff5d5
Compare
4bff5d5 to
896ea1d
Compare
896ea1d to
eae5b42
Compare
70413a5 to
fe107da
Compare
f63b8b9 to
4b8224d
Compare
4b8224d to
be10e67
Compare
| "@hashintel/ds-components": minor | ||
| --- | ||
|
|
||
| **Breaking:** `Slider` has a new look and is now a controlled input — `value` is required, and `onChange` fires once per interaction with the settled value (use `onDrag` for every value on the way). `onChangeEnd`, `label`, `showValueText`, `variant`, `defaultValue` and `style` are removed; name the slider with a `Form.Field` label or `aria-label` instead. A new `type` prop adds `dot`, which leaves the track unfilled, and `range`, which selects a span with two thumbs. |
There was a problem hiding this comment.
Two changeset gaps:
- Missing
@hashintel/petrinautchangeset: This PR changes user-facing UI and keyboard behavior in three Petrinaut controls (event-time-controls,sweep-navigator,simulation-scenario-controls), including PageUp/PageDown now jumping 10% of the range. Perlibs/@hashintel/petrinaut/AGENTS.md, consumer-facing Petrinaut changes need a separatepatchchangeset. - Omitted removed type exports:
libs/@hashintel/ds-components/src/main.tsstops exportingSliderPropsandSliderVariant(and addsSliderMarkandSliderScale). Note the removed type exports here (pointing callers toComponentProps<typeof Slider>) so external consumers aren't hit by an undocumented compile break.
There was a problem hiding this comment.
-
I'm not sure that these small UI changes warrant a petrinaut changeset? If I was a consumer of petrinaut, these changes would read as noise to me. @kube ?
-
👍
There was a problem hiding this comment.
No need. We already spam changeset enough.
| * focuses it, as they would a native input. | ||
| * | ||
| * Ark only positions the parts, and is kept read-only. Pointer and keyboard | ||
| * handling live here because `onChange` reports settled values (so the values |
There was a problem hiding this comment.
Two points on the custom interaction layer:
- Missing component tests:
slider.tsxowns pointer drag, track press,onDragoverrides, settledonChange,Form.Fieldnaming/legend, and range push/swap hand-over, yet there is noslider.test.tsx(onlyslider-util.test.tsand 4 Petrinaut keyboard tests). Please add component tests covering the changeset's core contract (onChangefiring once per interaction with the settled value,onDragfiring on each step and overriding the thumb, no-op release, cancel, and range collision). - Architectural question:
@zag-js/slider(already installed via@ark-ui/react) natively supportsonValueChange/onValueChangeEnd, grab offset (thumbDragOffset),minStepsBetweenThumbs,thumbCollisionBehavior(none/push/swap),largeStep, andgetAriaValueText. Putting Ark inreadOnlyand hand-rolling ~350 lines here (plus ~250 lines inslider-util.ts) is driven mainly byscaleandstep="marks", neither of which any consumer in this PR uses. Arescaleandstep="marks"needed right now, or could we drop them and delegate interaction to Ark/Zag?
There was a problem hiding this comment.
- 👍
- scale is probably unnecessary, and I was on the fence on whether to include it, but it also only adds ~30 lines of code. The bigger impact is from step="marks" - but it's a useful and common enough pattern that I'd like to keep it, as it unlocks some ui patterns.
| // ring is held back while the thumb's focus came from a pointer. | ||
| const [pointerFocus, setPointerFocus] = useState(false); | ||
|
|
||
| if (disabled && drag !== null) { |
There was a problem hiding this comment.
Turning disabled on mid-drag clears drag (removing the document listeners) but leaves gestureRef.current set and never calls endDrag(). As a result, onDrag has already emitted intermediate values while onChange is silently dropped (same on unmount mid-drag). Clear gestureRef.current and decide whether disabling mid-drag should commit or revert.
Related question at lines 398-399: pointercancel and contextmenu currently call endDrag() and commit the mid-drag value — should a cancelled gesture revert to gesture.start instead?
|
|
||
| const dragging = drag !== null; | ||
| // Re-subscribed on every render so the listeners see current props | ||
| useLayoutEffect(() => { |
There was a problem hiding this comment.
Because this useLayoutEffect has no dependency array and dragTo calls setDrag on every step, all four document event listeners are removed and re-attached on every frame during a drag. Keeping the latest handlers in a ref (or useEffectEvent) and depending only on [dragging] subscribes once per drag gesture.
| return { min, max }; | ||
| } | ||
| return thumbIndex === 0 | ||
| ? { min, max: upperShown - minDistance } |
There was a problem hiding this comment.
upperShown - minDistance and lowerShown + minDistance aren't snapped to step, so with e.g. step={1} and minDistance={1.5} the lower thumb reports aria-valuemax="4.5" even though it can only reach 4 (contradicting slider.docs.mdx:935, which says these report how far the thumb can currently travel). Snap through values.atMost / values.atLeast here.
| }) => { | ||
| const continuous = step === "any"; | ||
| // A scale that cannot place both ends, such as a log scale from 0, is ignored | ||
| const usableScale = |
There was a problem hiding this comment.
Several invalid inputs are silently coerced rather than failing informatively:
- An unusable
scale(e.g. a log scale starting at0) silently drops the scale and renders linearly. step <= 0(line 157) silently becomes1.- A
NaNcontrolledvaluereturnsNaNfromstepFrom; becauseNaN !== NaN,sameThumbs([NaN], [NaN])isfalse, so every keypress emitsonChange(NaN).
Confirm whether silent fallback is intentional for scale and step (if not, warn or throw in dev), and guard NaN values so keypresses don't loop onChange(NaN).
There was a problem hiding this comment.
Good call, I'll add some warnings.
I don't think that a consumer should expect all components to work with invalid values, and type-safety is rarely enough to completely make components bullet-proof, so a consumer will always be on the hook to use components appropriately - but adding these checks seems reasonable and low cost.
| /** The smallest gap allowed between the two thumbs, in the same unit as `value`. Only applies when `type` is `range`. */ | ||
| minDistance?: number; | ||
| /** What a dragged thumb does on reaching the other: `none` stops it there, `push` moves the other along, and `swap` lets it pass and carry on as the other thumb. Only applies when `type` is `range`. */ | ||
| thumbCollisionBehavior?: "none" | "push" | "swap"; |
There was a problem hiding this comment.
Optional cleanup: Import ThumbCollisionBehavior from ./slider-util instead of repeating "none" | "push" | "swap" here, so the prop type stays in sync with moveThumb.
| */ | ||
| const unwrapLinkTags = (text: string): string => | ||
| // eslint-disable-next-line react-refresh/only-export-components -- exported for tests | ||
| export const unwrapLinkTags = (text: string): string => |
There was a problem hiding this comment.
Optional cleanup: PropsTable already renders descriptions through react-markdown (line 167), and the only prop description using {@link url|label} is slider.tsx:104. Writing a standard markdown link there removes unwrapLinkTags, this eslint-disable, and props-table.test.ts.
If you want TSDoc {@link} syntax for IDE hover as well, move unwrapLinkTags into docs/blocks/props-table/unwrap-link-tags.ts so props-table.tsx stays component-only without the lint disable.
There was a problem hiding this comment.
Yes, like you noted, the reason is to support @link syntax for IDE hover.
Personally I don't think this function is big enough to warrant its own file, and since its only used internally by props-table, makes more sense to stay in the same file, so I think I'll leave this as is.
| @@ -350,15 +331,17 @@ export const AudioSettings = ({ | |||
| <span className={labelStyle}>Speed</span> | |||
| <div className={sliderRowStyle}> | |||
| <Slider | |||
There was a problem hiding this comment.
The visible 1.05× readout below is aria-hidden and this <Slider> sets no formatValue, so screen readers announce bare "1.05" without a unit. Pass formatValue={(speed) => ${speed.toFixed(2)}×} to match the new Slider accessibility guidance.
be10e67 to
892ba67
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d2aceff. Configure here.
| }; | ||
| setDrag({ thumbs: committed, index: pressed, handedOver: false }); | ||
| focusThumb(pressed); | ||
| }; |
There was a problem hiding this comment.
Second pointer resets active drag
Medium Severity
A new pointerdown always overwrites the active gesture and seeds it from committed, without checking for an existing drag. A second finger (or another pointer) on the track therefore jumps the thumbs back to the pre-drag value and the original pointer's pointerId no longer matches, so the in-progress movement is discarded instead of committed.
Reviewed by Cursor Bugbot for commit d2aceff. Configure here.
Benchmark results
|
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| resolve_policies_for_actor | user: empty, selectivity: high, policies: 2002 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: medium, policies: 1002 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: high, policies: 3314 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: medium, policies: 1527 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: high, policies: 2078 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: medium, policies: 1033 | Flame Graph |
policy_resolution_medium
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| resolve_policies_for_actor | user: empty, selectivity: high, policies: 102 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: medium, policies: 52 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: high, policies: 269 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: medium, policies: 108 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: high, policies: 133 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: medium, policies: 63 | Flame Graph |
policy_resolution_none
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| resolve_policies_for_actor | user: empty, selectivity: high, policies: 2 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: medium, policies: 2 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: high, policies: 8 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: medium, policies: 3 | Flame Graph |
policy_resolution_small
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| resolve_policies_for_actor | user: empty, selectivity: high, policies: 52 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: medium, policies: 26 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: high, policies: 94 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: medium, policies: 27 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: high, policies: 66 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: medium, policies: 29 | Flame Graph |
read_scaling_complete
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_id;one_depth | 1 entities | Flame Graph | |
| entity_by_id;one_depth | 10 entities | Flame Graph | |
| entity_by_id;one_depth | 25 entities | Flame Graph | |
| entity_by_id;one_depth | 5 entities | Flame Graph | |
| entity_by_id;one_depth | 50 entities | Flame Graph | |
| entity_by_id;two_depth | 1 entities | Flame Graph | |
| entity_by_id;two_depth | 10 entities | Flame Graph | |
| entity_by_id;two_depth | 25 entities | Flame Graph | |
| entity_by_id;two_depth | 5 entities | Flame Graph | |
| entity_by_id;two_depth | 50 entities | Flame Graph | |
| entity_by_id;zero_depth | 1 entities | Flame Graph | |
| entity_by_id;zero_depth | 10 entities | Flame Graph | |
| entity_by_id;zero_depth | 25 entities | Flame Graph | |
| entity_by_id;zero_depth | 5 entities | Flame Graph | |
| entity_by_id;zero_depth | 50 entities | Flame Graph |
read_scaling_linkless
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_id | 1 entities | Flame Graph | |
| entity_by_id | 10 entities | Flame Graph | |
| entity_by_id | 100 entities | Flame Graph | |
| entity_by_id | 1000 entities | Flame Graph | |
| entity_by_id | 10000 entities | Flame Graph |
representative_read_entity
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/block/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/book/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/building/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/organization/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/page/v/2
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/person/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/playlist/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/song/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/uk-address/v/1
|
Flame Graph |
representative_read_entity_type
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| get_entity_type_by_id | Account ID: bf5a9ef5-dc3b-43cf-a291-6210c0321eba
|
Flame Graph |
representative_read_multiple_entities
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_property | traversal_paths=0 | 0 | |
| entity_by_property | traversal_paths=255 | 1,resolve_depths=inherit:1;values:255;properties:255;links:127;link_dests:126;type:true | |
| entity_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:0;properties:0;links:0;link_dests:0;type:false | |
| entity_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:0;properties:0;links:1;link_dests:0;type:true | |
| entity_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:0;properties:2;links:1;link_dests:0;type:true | |
| entity_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:2;properties:2;links:1;link_dests:0;type:true | |
| link_by_source_by_property | traversal_paths=0 | 0 | |
| link_by_source_by_property | traversal_paths=255 | 1,resolve_depths=inherit:1;values:255;properties:255;links:127;link_dests:126;type:true | |
| link_by_source_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:0;properties:0;links:0;link_dests:0;type:false | |
| link_by_source_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:0;properties:0;links:1;link_dests:0;type:true | |
| link_by_source_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:0;properties:2;links:1;link_dests:0;type:true | |
| link_by_source_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:2;properties:2;links:1;link_dests:0;type:true |
scenarios
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| full_test | query-limited | Flame Graph | |
| full_test | query-unlimited | Flame Graph | |
| linked_queries | query-limited | Flame Graph | |
| linked_queries | query-unlimited | Flame Graph |


🌟 Purpose
Updates the UI for Slider to match the design guidelines and introduces a new more flexible api, new options and new variants.
Also updates petrinaut and brunch to use the new Slider api, and swaps two custom slider implementations from petrinaut over to Slider.