-
Notifications
You must be signed in to change notification settings - Fork 52
Enhance the Slider Component
#1070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
97188a8
feat: change currentValue through value prop change
guswnsxodlf 2756764
fix: render thumbs through currentValue props
guswnsxodlf ff6fd8c
docs: add value prop on storybook
guswnsxodlf e605245
chore: add changeset
guswnsxodlf 2e7a863
test: add a test case
guswnsxodlf 6a95b22
refactor: name useEffect function
guswnsxodlf 7ec97eb
refactor: set default value on the function props
guswnsxodlf 2dc8cbd
test(Slider): divide a test case to 2 cases
guswnsxodlf ebc9a34
refactor: forwardedRef type
guswnsxodlf bda0af9
fix: always rerender when the current value is changed
guswnsxodlf 9922c64
test: add user interaction test case
guswnsxodlf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| --- | ||
| "@channel.io/bezier-react": patch | ||
| --- | ||
|
|
||
| Enhance the Slider component |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| /* External dependencies */ | ||
| import React, { forwardRef, useState, useCallback } from 'react' | ||
| import React, { | ||
| forwardRef, | ||
| useState, | ||
| useCallback, | ||
| useEffect, | ||
| } from 'react' | ||
| import { isFunction } from 'lodash-es' | ||
| import * as SliderPrimitive from '@radix-ui/react-slider' | ||
|
|
||
|
|
@@ -30,6 +35,19 @@ export const Slider = forwardRef(function Slider( | |
| ) { | ||
| const [currentValue, setCurrentValue] = useState<number[]>(value ?? defaultValue) | ||
|
|
||
| useEffect(() => { | ||
| if (value) { | ||
| setCurrentValue(value) | ||
|
|
||
| if (isFunction(onValueChange)) { | ||
| onValueChange(value) | ||
| } | ||
| } | ||
| }, [ | ||
| value, | ||
| onValueChange, | ||
| ]) | ||
|
|
||
| const handleValueChange: (value: number[]) => void = useCallback((_value) => { | ||
| setCurrentValue(_value) | ||
| if (isFunction(onValueChange)) { | ||
|
|
@@ -89,7 +107,7 @@ export const Slider = forwardRef(function Slider( | |
| guideValue={guideValue} | ||
| /> | ||
| )) } | ||
| { defaultValue.map((v) => ( | ||
| { currentValue.map((v) => ( | ||
|
||
| <SliderPrimitive.Thumb | ||
| asChild | ||
| key={`slider-thumb-${v}`} | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.