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

[RNMobile] Fix: Button button border-radius to be stored as a value + unit #33405

Closed
wants to merge 2 commits into from
Closed
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
19 changes: 15 additions & 4 deletions packages/block-library/src/button/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class ButtonEdit extends Component {
...style,
border: {
...style?.border,
radius: newRadius,
radius: `${ newRadius }px`, // Store the value with the px value so that it works as expected.
},
};

Expand Down Expand Up @@ -368,6 +368,16 @@ class ButtonEdit extends Component {
}
}

getBorderRadiusValue( borderRadius, defaultBorderRadius ) {
// Return an integer value for the border Radius.
// Since that is what the we expect that value to be.
if ( Number.isInteger( parseInt( borderRadius ) ) ) {
return parseInt( borderRadius );
}

return defaultBorderRadius;
}

render() {
const {
attributes,
Expand Down Expand Up @@ -395,10 +405,11 @@ class ButtonEdit extends Component {
}

const borderRadius = buttonStyle?.border?.radius;
const borderRadiusValue = this.getBorderRadiusValue(
borderRadius,
styles.defaultButton.borderRadius
);

const borderRadiusValue = Number.isInteger( borderRadius )
? borderRadius
: styles.defaultButton.borderRadius;
const outlineBorderRadius =
borderRadiusValue > 0
? borderRadiusValue + spacing + borderWidth
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/buttons/test/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ describe( 'when a button is shown', () => {
fireEvent( radiusSlider, 'valueChange', '25' );

const expectedHtml = `<!-- wp:buttons -->
<div class="wp-block-buttons"><!-- wp:button {"style":{"border":{"radius":25}}} -->
<div class="wp-block-button"><a class="wp-block-button__link" href="">Hello</a></div>
<div class="wp-block-buttons"><!-- wp:button {"style":{"border":{"radius":"25px"}}} -->
<div class="wp-block-button"><a class="wp-block-button__link" href="" style="border-radius:25px">Hello</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons -->`;
expect( getEditorHtml() ).toBe( expectedHtml );
Expand Down