Skip to content

Commit

Permalink
type erroes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeac123 committed May 24, 2024
1 parent 0c5c0d6 commit d81ffe8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions packages/lab/src/slider/internal/SliderThumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export function SliderThumb(props: SliderThumbProps): JSX.Element {

const onKeyDown = useKeyDownThumb(min, max, step, value, onChange, index);

console.log(index);

const { thumbProps, tooltipVisible } = useMouseDownThumb(
trackRef,
min,
Expand Down
6 changes: 2 additions & 4 deletions packages/lab/src/slider/internal/useMouseDownThumb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export function useMouseDownThumb(
index: number,
) {



const [tooltipVisible, setTooltipVisible] = useState(false);
const [ mouseDown, setMouseDown ] = useState(false)
const activeThumbIndex = useRef<{ index: number | undefined}>({
Expand All @@ -33,7 +31,7 @@ export function useMouseDownThumb(
document.removeEventListener("pointerup", onMouseUp);
setTooltipVisible(false);
setMouseDown(false)
activeThumbIndex.current.index = undefined
activeThumbIndex.current.index = 0
};

const onMouseMove = (event: MouseEvent): void => {
Expand All @@ -55,7 +53,7 @@ export function useMouseDownThumb(
onDownThumb();
},
onMouseOver() {
activeThumbIndex.current.index === index && setTooltipVisible(true);
setTooltipVisible(true)
},
onFocus() {
setTooltipVisible(true);
Expand Down
8 changes: 5 additions & 3 deletions packages/lab/src/slider/internal/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SliderChangeHandler } from "../types";
import { RefObject, useRef } from "react";
import { RefObject } from "react";

export const getValue = (
trackRef: RefObject<Element>,
Expand Down Expand Up @@ -30,8 +30,10 @@ export function setRangeValue(
Math.abs(value[1] - newValue) < step
)
return;
if (index === 0 && newValue > value[1]) return;
if (index === 1 && newValue < value[0]) return;
if (index === 0 && newValue > value[1])
return onChange([value[1] - step, value[1]]);
if (index === 1 && newValue < value[0])
return onChange([value[0], value[0] + step]);
index ? onChange?.([value[0], newValue]) : onChange?.([newValue, value[1]]);
}

Expand Down
1 change: 1 addition & 0 deletions packages/lab/stories/slider/slider.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export const RangeWithInput = () => {
min={0}
max={50}
value={value}
// @ts-ignore
onChange={handleSliderChange}
aria-label="withInput"
/>
Expand Down

0 comments on commit d81ffe8

Please sign in to comment.