-
Notifications
You must be signed in to change notification settings - Fork 805
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
Jetpack button: fix width and alignment settings #41139
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: fixed | ||
|
||
Fix submit button width and alignment |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: other | ||
|
||
Jetpack button: fix width and alignment |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,7 +166,6 @@ function get_button_styles( $attributes ) { | |
$has_named_gradient = array_key_exists( 'gradient', $attributes ); | ||
$has_custom_gradient = array_key_exists( 'customGradient', $attributes ); | ||
$has_border_radius = array_key_exists( 'borderRadius', $attributes ); | ||
$has_width = array_key_exists( 'width', $attributes ); | ||
$has_font_family = array_key_exists( 'fontFamily', $attributes ); | ||
$has_typography_styles = array_key_exists( 'style', $attributes ) && array_key_exists( 'typography', $attributes['style'] ); | ||
$has_custom_font_size = $has_typography_styles && array_key_exists( 'fontSize', $attributes['style']['typography'] ); | ||
|
@@ -206,11 +205,6 @@ function get_button_styles( $attributes ) { | |
$styles[] = sprintf( 'border-radius: %spx;', $attributes['borderRadius'] ); | ||
} | ||
|
||
if ( $has_width ) { | ||
$styles[] = sprintf( 'width: %s;', $attributes['width'] ); | ||
$styles[] = 'max-width: 100%'; | ||
} | ||
|
||
return implode( ' ', $styles ); | ||
} | ||
|
||
|
@@ -226,7 +220,7 @@ function get_button_wrapper_styles( $attributes ) { | |
$has_width = array_key_exists( 'width', $attributes ); | ||
|
||
if ( $has_width ) { | ||
$styles[] = 'max-width: 100%'; | ||
$styles[] = sprintf( 'width: %s;', $attributes['width'] ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apply the width to the root of the |
||
} | ||
|
||
return implode( ' ', $styles ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,21 +8,16 @@ import { | |
import { compose } from '@wordpress/compose'; | ||
import { __ } from '@wordpress/i18n'; | ||
import clsx from 'clsx'; | ||
import useWidth from '../../shared/use-width'; | ||
import applyFallbackStyles from './apply-fallback-styles'; | ||
import { IS_GRADIENT_AVAILABLE } from './constants'; | ||
import ButtonControls from './controls'; | ||
import usePassthroughAttributes from './use-passthrough-attributes'; | ||
import './editor.scss'; | ||
|
||
export function ButtonEdit( props ) { | ||
const { attributes, backgroundColor, className, clientId, context, setAttributes, textColor } = | ||
props; | ||
const { attributes, backgroundColor, className, clientId, setAttributes, textColor } = props; | ||
const { borderRadius, element, placeholder, text, width, fontSize } = attributes; | ||
const isWidthSetOnParentBlock = 'jetpack/parentBlockWidth' in context; | ||
|
||
usePassthroughAttributes( { attributes, clientId, setAttributes } ); | ||
useWidth( { attributes, disableEffects: isWidthSetOnParentBlock, setAttributes } ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling this hook results in resetting the button width when it is aligned left or right. I don't get the rationale behind that decision. In the current UI, from a user standpoint, this doesn't seem like something we'd want. |
||
|
||
/* eslint-disable react-hooks/rules-of-hooks */ | ||
const { | ||
|
@@ -39,6 +34,7 @@ export function ButtonEdit( props ) { | |
|
||
const blockProps = useBlockProps( { | ||
className: clsx( 'wp-block-button', className ), | ||
style: { width }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Set the |
||
} ); | ||
|
||
const buttonClasses = clsx( 'wp-block-button__link', { | ||
|
@@ -48,7 +44,6 @@ export function ButtonEdit( props ) { | |
[ textColor.class ]: textColor.class, | ||
[ gradientClass ]: gradientClass, | ||
'no-border-radius': 0 === borderRadius, | ||
'has-custom-width': !! width, | ||
[ `has-${ fontSize }-font-size` ]: !! fontSize, | ||
'has-custom-font-size': !! fontSize, | ||
} ); | ||
|
@@ -60,7 +55,6 @@ export function ButtonEdit( props ) { | |
fontSize: attributes.style?.typography?.fontSize, | ||
color: textColor.color, | ||
borderRadius: borderRadius ? borderRadius + 'px' : undefined, | ||
width, | ||
}; | ||
|
||
return ( | ||
|
@@ -90,6 +84,5 @@ export function ButtonEdit( props ) { | |
} | ||
|
||
export default compose( | ||
withColors( { backgroundColor: 'background-color' }, { textColor: 'color' } ), | ||
applyFallbackStyles | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In the following discussion, not using |
||
withColors( { backgroundColor: 'background-color' }, { textColor: 'color' } ) | ||
)( ButtonEdit ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,24 @@ | ||
.wp-block[data-type='jetpack/button'] { | ||
display: inline-block; | ||
margin: 0 auto; | ||
} | ||
.wp-block-jetpack-button { | ||
max-width: 100%; | ||
width: fit-content; | ||
margin: 0; | ||
|
||
.wp-block[data-align="center"] { | ||
.wp-block-jetpack-button { | ||
display: flex; | ||
justify-content: center; | ||
} | ||
} | ||
&.aligncenter { | ||
display: block; | ||
|
||
.wp-block[data-align="right"] { | ||
.wp-block-jetpack-button { | ||
display: flex; | ||
justify-content: flex-end; | ||
margin-left: auto; | ||
margin-right: auto; | ||
} | ||
} | ||
|
||
div[data-type="jetpack/button"]:not([data-align='left']):not([data-align='right']) { | ||
width: 100%; | ||
} | ||
|
||
div[data-type="jetpack/button"][data-align] { | ||
z-index: 1; | ||
width: 100%; | ||
&.alignleft { | ||
display: block; | ||
|
||
.wp-block > div { | ||
max-width: 100%; | ||
margin-right: auto; | ||
} | ||
} | ||
|
||
.wp-block-jetpack-button, | ||
.wp-block-button__link.has-custom-width { | ||
max-width: 100%; | ||
} | ||
&.alignright { | ||
display: block; | ||
|
||
margin-left: auto; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,6 +116,7 @@ | |
} | ||
|
||
.wp-block[data-type='jetpack/button'] { | ||
width: 100%; | ||
margin-top: 0; | ||
margin-bottom: 0; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overwrite the
100%
value. We want to be able to set the width through the button styling options in the editor.