-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Adjust the custom range steps to match the units chosen #44959
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,7 +107,7 @@ export default function SpacingInputControl( { | |
| const customTooltipContent = ( newValue ) => | ||
| value === undefined ? undefined : spacingSizes[ newValue ]?.name; | ||
|
|
||
| const customRangeValue = parseInt( currentValue, 10 ); | ||
| const customRangeValue = parseFloat( currentValue, 10 ); | ||
|
|
||
| const getNewCustomValue = ( newSize ) => { | ||
| const isNumeric = ! isNaN( parseFloat( newSize ) ); | ||
|
|
@@ -163,6 +163,8 @@ export default function SpacingInputControl( { | |
| ! showCustomValueControl && | ||
| currentValueHint !== undefined; | ||
|
|
||
| const maxCustomValues = { px: 300, '%': 100, vw: 100, vh: 100 }; | ||
|
|
||
| return ( | ||
| <> | ||
| { side !== 'all' && ( | ||
|
|
@@ -227,7 +229,16 @@ export default function SpacingInputControl( { | |
| <RangeControl | ||
| value={ customRangeValue } | ||
| min={ 0 } | ||
| max={ 300 } | ||
| max={ | ||
| maxCustomValues[ selectedUnit ] | ||
| ? maxCustomValues[ selectedUnit ] | ||
| : 10 | ||
|
||
| } | ||
| step={ | ||
| [ 'px', '%', 'vh', 'vw' ].includes( selectedUnit ) | ||
| ? 1 | ||
| : 0.1 | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be good to do this the same way |
||
| withInputField={ false } | ||
| onChange={ handleCustomValueSliderChange } | ||
| className="components-spacing-sizes-control__custom-value-range" | ||
|
|
||
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.
This could be moved to file scope and named
MAX_CUSTOM_VALUESto avoid the little bit of overhead of redefining it on every render.