@kobalte/core
Advanced tools
Comparing version 0.11.1 to 0.11.2
@@ -19,3 +19,3 @@ /* eslint-disable solid/reactivity */ | ||
import { SliderContext } from "./slider-context"; | ||
import { getClosestValueIndex, getNextSortedValues, hasMinStepsBetweenValues } from "./utils"; | ||
import { getNextSortedValues, hasMinStepsBetweenValues } from "./utils"; | ||
export function SliderRoot(props) { | ||
@@ -85,10 +85,7 @@ let ref; | ||
let currentPosition = null; | ||
const onSlideStart = (value) => { | ||
const closestIndex = getClosestValueIndex(state.values(), value); | ||
if (closestIndex >= 0) { | ||
state.setFocusedThumb(closestIndex); | ||
state.setThumbDragging(closestIndex, true); | ||
state.setThumbValue(closestIndex, value); | ||
currentPosition = null; | ||
} | ||
const onSlideStart = (index, value) => { | ||
state.setFocusedThumb(index); | ||
state.setThumbDragging(index, true); | ||
state.setThumbValue(index, value); | ||
currentPosition = null; | ||
}; | ||
@@ -95,0 +92,0 @@ const onSlideMove = ({ deltaX, deltaY }) => { |
@@ -15,3 +15,3 @@ /*! | ||
import { callHandler, mergeDefaultProps, mergeRefs } from "@kobalte/utils"; | ||
import { createContext, onMount, splitProps, useContext } from "solid-js"; | ||
import { createContext, createUniqueId, onMount, splitProps, useContext, } from "solid-js"; | ||
import { createFormControlField, FORM_CONTROL_FIELD_PROP_NAMES } from "../form-control"; | ||
@@ -25,3 +25,3 @@ import { Polymorphic } from "../polymorphic"; | ||
props = mergeDefaultProps({ | ||
id: context.generateId("thumb"), | ||
id: context.generateId(`thumb-${createUniqueId()}`), | ||
}, props); | ||
@@ -76,11 +76,13 @@ const [local, formControlFieldProps, others] = splitProps(props, [ | ||
const target = e.currentTarget; | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
target.setPointerCapture(e.pointerId); | ||
e.preventDefault(); | ||
target.focus(); | ||
startPosition = context.state.orientation() === "horizontal" ? e.clientX : e.clientY; | ||
if (value()) { | ||
context.onSlideStart?.(value()); | ||
if (value() !== undefined) { | ||
context.onSlideStart?.(index(), value()); | ||
} | ||
}; | ||
const onPointerMove = e => { | ||
e.stopPropagation(); | ||
callHandler(e, local.onPointerMove); | ||
@@ -98,2 +100,3 @@ const target = e.currentTarget; | ||
const onPointerUp = e => { | ||
e.stopPropagation(); | ||
callHandler(e, local.onPointerUp); | ||
@@ -100,0 +103,0 @@ const target = e.currentTarget; |
@@ -5,3 +5,3 @@ import { callHandler, mergeRefs } from "@kobalte/utils"; | ||
import { useSliderContext } from "./slider-context"; | ||
import { linearScale } from "./utils"; | ||
import { getClosestValueIndex, linearScale } from "./utils"; | ||
/** | ||
@@ -41,3 +41,4 @@ * The component that visually represents the slider track. | ||
startPosition = context.state.orientation() === "horizontal" ? e.clientX : e.clientY; | ||
context.onSlideStart?.(value); | ||
const closestIndex = getClosestValueIndex(context.state.values(), value); | ||
context.onSlideStart?.(closestIndex, value); | ||
}; | ||
@@ -44,0 +45,0 @@ const onPointerMove = e => { |
@@ -15,3 +15,3 @@ import { Accessor, Setter } from "solid-js"; | ||
setThumbs: Setter<CollectionItemWithRef[]>; | ||
onSlideStart: ((value: number) => void) | undefined; | ||
onSlideStart: ((index: number, value: number) => void) | undefined; | ||
onSlideMove: ((deltas: { | ||
@@ -18,0 +18,0 @@ deltaX: number; |
{ | ||
"name": "@kobalte/core", | ||
"version": "0.11.1", | ||
"version": "0.11.2", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "Unstyled components and primitives for building accessible web apps and design systems with SolidJS.", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5799153
66413