-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1569 from ecency/feature/slider-keyboard
Added keyboard controls for entry vote slider
- Loading branch information
Showing
5 changed files
with
72 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./react-input-slider-wrapper"; |
32 changes: 32 additions & 0 deletions
32
src/common/features/packages-helpers/react-input-slider-wrapper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Slider from "react-input-slider"; | ||
import React, { useRef } from "react"; | ||
|
||
interface Props { | ||
value: number; | ||
onChange: (v: number) => void; | ||
} | ||
|
||
export function ReactInputSliderWrapper({ value, onChange }: Props) { | ||
const rootRef = useRef<HTMLSpanElement | null>(null); | ||
|
||
const handleKeyboard = (e: React.KeyboardEvent) => { | ||
if (e.key === "ArrowLeft" && value > 0) { | ||
onChange(value - 1); | ||
} | ||
if (e.key === "ArrowRight" && value < 100) { | ||
onChange(value + 1); | ||
} | ||
}; | ||
|
||
return ( | ||
<span | ||
ref={rootRef} | ||
tabIndex={0} | ||
className="w-full flex [&>div]:w-full" | ||
onKeyUp={handleKeyboard} | ||
onClick={() => rootRef.current?.focus()} | ||
> | ||
<Slider axis="x" xstep={0.1} x={value} onChange={({ x }) => onChange(x)} /> | ||
</span> | ||
); | ||
} |