Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand Down Expand Up @@ -163,6 +163,8 @@ export default function SpacingInputControl( {
! showCustomValueControl &&
currentValueHint !== undefined;

const maxCustomValues = { px: 300, '%': 100, vw: 100, vh: 100 };
Copy link
Contributor

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_VALUES to avoid the little bit of overhead of redefining it on every render.


return (
<>
{ side !== 'all' && (
Expand Down Expand Up @@ -227,7 +229,16 @@ export default function SpacingInputControl( {
<RangeControl
value={ customRangeValue }
min={ 0 }
max={ 300 }
max={
maxCustomValues[ selectedUnit ]
? maxCustomValues[ selectedUnit ]
: 10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could possibly change this to maxCustomValues[ selectedUnit ] ?? 10, but I also wonder why em and rem are excluded from maxCustomValues?

}
step={
[ 'px', '%', 'vh', 'vw' ].includes( selectedUnit )
? 1
: 0.1
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to do this the same way maxCustomValues works, extract it out to a variable.

withInputField={ false }
onChange={ handleCustomValueSliderChange }
className="components-spacing-sizes-control__custom-value-range"
Expand Down