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

Do not allow negative values in image dimensions #7656

merged 2 commits into from Jul 5, 2018


None yet
4 participants

nfmohit-wpmudev commented Jul 1, 2018


This PR addresses #7637 which reports the allowance of negative values in width and height input fields belonging to the block inspector settings of the image block.

How has this been tested?

This has been tested by making sure a minimum value of 1 is enforced in the mentioned input fields so that no negative values are allowed.

This was tested in WP 4.9.6, Gutenberg 3.1.1, Apache server with PHP 7.2.0 and MySQL 5.6.34. According to initial tests, the code doesn’t seem to affect any other areas.



Types of changes

This PR introduces a new attribute named min in the TextControl element, which is used in the image block's width and height TextControl fields. A minimum value of 1 set in the fields so that negative values are not allowed. This uses HTML input field's min attribute, more details on that here.


  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
@@ -5,7 +5,7 @@ import BaseControl from '../base-control';
import withInstanceId from '../higher-order/with-instance-id';
import './style.scss';
function TextControl( { label, value, help, className, instanceId, onChange, type = 'text', ...props } ) {
function TextControl( { label, value, help, className, instanceId, min, onChange, type = 'text', ...props } ) {

This comment has been minimized.


ajitbohra Jul 1, 2018


No need for the additional min attribute as ...props will pass the additional props added to the component

This comment has been minimized.


nfmohit-wpmudev Jul 1, 2018


Whoops, sorry, didn't realize that 😳 Just pushed a new commit which removes any changes from the component file.

Thank you so much for the review @ajitbohra ❤️



@gziolo gziolo merged commit 8938581 into WordPress:master Jul 5, 2018

2 checks passed

codecov/project 46.98% remains the same compared to 345e1ea
continuous-integration/travis-ci/pr The Travis CI build passed

@gziolo gziolo added this to the 3.2 milestone Jul 5, 2018


This comment has been minimized.


ZebulanStanphill commented Jul 7, 2018

Are there any use cases for having an image use decimal dimensions <1 like 0.5×0.5?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment