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

Allow negative values for margin inputs #40464

Merged
merged 4 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions packages/block-editor/src/hooks/margin.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export function MarginEdit( props ) {
units={ units }
allowReset={ false }
splitOnAxis={ splitOnAxis }
allowNegativeValues={ true }
/>
</>
),
Expand Down
5 changes: 4 additions & 1 deletion 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 = defaultInputProps,
inputProps,
onChange = noop,
label = __( 'Box Control' ),
values: valuesProp,
Expand All @@ -55,7 +55,10 @@ export default function BoxControl( {
splitOnAxis = false,
allowReset = true,
resetValues = DEFAULT_VALUES,
allowNegativeValues = false,
} ) {
inputProps = allowNegativeValues ? { min: -Infinity } : defaultInputProps;
Copy link
Contributor

Choose a reason for hiding this comment

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

@JustinyAhin Won't this overwrite inputProps, making the prop unusable?

Copy link
Member Author

Choose a reason for hiding this comment

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

@talldan in which scenario would that happen? Not sure I really understand your question

Copy link
Member

Choose a reason for hiding this comment

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

Hmmm you have a point @talldan! Apologies, I initially missed this in my initial review.

Should probably be something like this instead:

inputProps.min = allowNegativeValues ? -Infinity : defaultInputProps.min;

What do you think?


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