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

Do not allow negative values in image dimensions #7656

Merged
merged 2 commits into from
Jul 5, 2018
Merged

Do not allow negative values in image dimensions #7656

merged 2 commits into from
Jul 5, 2018

Conversation

nfmohit
Copy link
Member

@nfmohit nfmohit commented Jul 1, 2018

Description

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.

Screenshots

pull-7637-min

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.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@ajitbohra ajitbohra added [Type] Enhancement A suggestion for improvement. [Feature] Blocks Overall functionality of blocks labels Jul 1, 2018
@@ -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 } ) {
Copy link
Member

Choose a reason for hiding this comment

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

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

Copy link
Member Author

Choose a reason for hiding this comment

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

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 ❤️

Copy link
Member

@ajitbohra ajitbohra left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@gziolo gziolo merged commit 8938581 into WordPress:master Jul 5, 2018
@gziolo gziolo added this to the 3.2 milestone Jul 5, 2018
@ZebulanStanphill
Copy link
Member

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
Labels
[Feature] Blocks Overall functionality of blocks [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants