diff --git a/package.json b/package.json index 2463c5d..cf16640 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@weng-lab/psychscreen-ui-components", "description": "Typescript and Material UI based components used for psychSCREEN", "author": "SCREEN Team @ UMass Chan Medical School", - "version": "0.8.0-a.3", + "version": "0.8.1", "license": "MIT", "main": "dist/index.js", "typings": "dist/index.d.ts", diff --git a/src/components/Slider/Slider.tsx b/src/components/Slider/Slider.tsx index 6d8e9e6..e3d07ac 100644 --- a/src/components/Slider/Slider.tsx +++ b/src/components/Slider/Slider.tsx @@ -22,7 +22,8 @@ export type SliderProps = MuiSliderProps & { defaultEnd: number; //Could do more strict input checking here by checking the min/max of the slider minDistance?: number; - onChange?: (value: number[]) => void; + onSliderChange?: (value: number[]) => void; + onSliderChangeCommitted?: (value: number[]) => void; }; function valuetext(value: number) { @@ -35,9 +36,9 @@ const RangeSlider: React.FC = (props: SliderProps) => { [props.defaultStart, props.defaultEnd] ); - //Triggers when component updates, allows the value to be extraced in an onChange() function + // Triggers when component updates, allows the value to be extraced in an onChange() function useEffect(() => { - props.onChange && props.onChange(value); + props.onSliderChange && props.onSliderChange(value); }) //Check if declared, if not set to MUI slider defaults @@ -81,6 +82,8 @@ const RangeSlider: React.FC = (props: SliderProps) => { } }; + const handleSliderChangeCommited = () => {props.onSliderChangeCommitted && props.onSliderChangeCommitted(value)} + //On a user pressing enter, decides if the temp value is valid and posts it, or corrects the temp value const handleInputEnter0 = (event: React.KeyboardEvent) => { @@ -172,12 +175,14 @@ const RangeSlider: React.FC = (props: SliderProps) => { getAriaLabel={() => 'Minimum distance'} value={value} onChange={handleSliderChange} + onChangeCommitted={handleSliderChangeCommited} valueLabelDisplay="auto" getAriaValueText={valuetext} disableSwap min={sliderMin} max={sliderMax} step={sliderStep} + {...props} /> diff --git a/stories/Slider.stories.tsx b/stories/Slider.stories.tsx index b4784a8..75abd93 100644 --- a/stories/Slider.stories.tsx +++ b/stories/Slider.stories.tsx @@ -70,7 +70,36 @@ export const onSliderChange = () => { defaultEnd={7} minDistance={1} step={0.5} - onChange={(value) => { + onSliderChange={(value) => { + setValue0(value[0]) + setValue1(value[1]) + }} + /> + + Value 0 = {value0} + + + Value 1 = {value1} + + + ); +} + +export const onSliderCommit = () => { + const [ value0, setValue0 ] = React.useState(0); + const [ value1, setValue1 ] = React.useState(0); + return ( + <> + { setValue0(value[0]) setValue1(value[1]) }}