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

FocalPointPicker: stop using UnitControl's deprecated unit prop #39504

Merged
merged 2 commits into from
Mar 17, 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/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- `Divider`: Make the divider visible by default (`display: inline`) in flow layout containers when the divider orientation is vertical ([#39316](https://github.com/WordPress/gutenberg/pull/39316)).
- Stop using deprecated `event.keyCode` in favor of `event.key` for keyboard events in `UnitControl` and `InputControl`. ([#39360](https://github.com/WordPress/gutenberg/pull/39360))
- `ColorPalette`: refine custom color button's label. ([#39386](https://github.com/WordPress/gutenberg/pull/39386))
- `FocalPointPicker`: stop using `UnitControl`'s deprecated `unit` prop ([#39504](https://github.com/WordPress/gutenberg/pull/39504)).

### Internal

Expand Down
5 changes: 2 additions & 3 deletions packages/components/src/focal-point-picker/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ export default function FocalPointPickerControls( {
<ControlWrapper className="focal-point-picker__controls">
<UnitControl
label={ __( 'Left' ) }
value={ valueX }
value={ [ valueX, '%' ].join( '' ) }
onChange={ ( next ) => handleChange( next, 'x' ) }
dragDirection="e"
/>
<UnitControl
label={ __( 'Top' ) }
value={ valueY }
value={ [ valueY, '%' ].join( '' ) }
Comment on lines -45 to +51
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there something I don't know about join that makes it better than template literals?

Copy link
Contributor Author

@ciampo ciampo Mar 16, 2022

Choose a reason for hiding this comment

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

I prefer the join approach because it ignores undefined values:

[ 41, undefined ].join(''); // '41'
`${ 41 }${ undefined }`; // '41undefined'

And so I've taken the habit of using this syntax, especially when in need of concatenating quantity and unit in the context of UnitControl

Copy link
Contributor

Choose a reason for hiding this comment

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

Now I get it. Thanks! I'm pretty sure in this case the values cannot be undefined but I'm not sweating these joins staying put.

Copy link
Contributor

@andrewserong andrewserong Mar 17, 2022

Choose a reason for hiding this comment

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

I prefer the join approach because it ignores undefined values

Oh, nice! I'm sure I'll borrow that approach 😀

onChange={ ( next ) => handleChange( next, 'y' ) }
dragDirection="s"
/>
Expand All @@ -63,7 +63,6 @@ function UnitControl( props ) {
labelPosition="top"
max={ TEXTCONTROL_MAX }
min={ TEXTCONTROL_MIN }
unit="%"
units={ [ { value: '%', label: '%' } ] }
{ ...props }
/>
Expand Down