-
-
Notifications
You must be signed in to change notification settings - Fork 50.8k
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
fix: Slider step prop not accepting null value #26984
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 616570a:
|
Codecov Report
@@ Coverage Diff @@
## master #26984 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 384 384
Lines 7370 7370
Branches 2051 2009 -42
=========================================
Hits 7370 7370
Continue to review full report at Codecov.
|
@@ -159,6 +160,7 @@ const Slider = React.forwardRef<unknown, SliderSingleProps | SliderRangeProps>( | |||
return ( | |||
<RcSlider | |||
{...(restProps as SliderSingleProps)} | |||
step={restProps.step!} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RcSlider 的定义也需要修正一下,避免用 !
。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately until RcSlider fixes their definition, there is nothing we can do on our end and to avoid typescript lint errors.
Furthermore I have added another test to safeguard againts undefined
:
it('step should not crash with undefined value', () => {
[undefined, null].forEach(value => {
mount(<Slider step={value} tooltipVisible />);
});
});
[中文版模板 / Chinese template]
🤔 This is a ...
🔗 Related issue link
💡 Background and solution
The
step
prop forSlider
will trigger typescript error:Type null is not assignable to type 'number | undefined'
. This is because the type definition does not allownull
value, eventhough in the documents it allowed as mentioned:This can be fixed by changing the definition of
step
to allownull
value.Since underlying component used in
Slider
isreact-component/slider
itsstep
props do not allownull
, although in their documentation it is allowed..A quick fix will force the value
null!
within the library, while client apps will still be able to pass instep={null}
without typescript errors. Until the underlying prop interface is resolved, this should a sufficient enough fix.Updated typescript test to catch this error, and also added tests to ensure slider behaves as expected when null is passed.
📝 Changelog
No breaking changes
step
prop inSlider
to accept null as a valid value in accordance to the documentation.☑️ Self Check before Merge