Skip to content
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

Update negative values for margins #40653

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
4 changes: 2 additions & 2 deletions packages/components/src/box-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function useUniqueId( idProp ) {
}
export default function BoxControl( {
id: idProp,
inputProps,
inputProps = defaultInputProps,
onChange = noop,
label = __( 'Box Control' ),
values: valuesProp,
Expand All @@ -57,7 +57,7 @@ export default function BoxControl( {
resetValues = DEFAULT_VALUES,
allowNegativeValues = false,
} ) {
inputProps = allowNegativeValues ? { min: -Infinity } : defaultInputProps;
inputProps.min = allowNegativeValues ? -Infinity : defaultInputProps.min;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for following up, Justin!

I'm actually wondering about this new prop. If a dev does something like this:

<BoxControl
    inputProps={ { min: -10 } }
    allowNegativeValues
/>

At first glance this looks correct, but the minimum of -10 is actually being overwritten still with -Infinity by this code.

There are probably ways to fix that, but then another scenario is something meaningless like:

<BoxControl
    inputProps={ { min: 5 } }
    allowNegativeValues
/>

I think it might be best not to have two props that can do the same thing. Maybe there's no need for the allowNegativeValues prop at all, and the BoxControl used for margin could be simplified to:

<BoxControl
    inputProps={ { min: -Infinity } }
/>

It isn't as clean as allowNegativeValues, but I think it's less likely to cause confusion.


const [ values, setValues ] = useControlledState( valuesProp, {
fallback: DEFAULT_VALUES,
Expand Down