Repository navigation
Forms: Fix typography input styles applying to labels when outline style is active (on frontend) #43534
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
Forms: Fix typography input styles applying to labels when outline style is active (on frontend) #43534
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 |
|---|---|---|
|
|
@@ -103,52 +103,53 @@ class Contact_Form_Field extends Contact_Form_Shortcode { | |
| public function __construct( $attributes, $content = null, $form = null ) { | ||
| $attributes = shortcode_atts( | ||
| array( | ||
| 'label' => null, | ||
| 'togglelabel' => null, | ||
| 'type' => 'text', | ||
| 'required' => false, | ||
| 'requiredtext' => null, | ||
| 'options' => array(), | ||
| 'optionsdata' => array(), | ||
| 'id' => null, | ||
| 'style' => null, | ||
| 'fieldbackgroundcolor' => null, | ||
| 'buttonbackgroundcolor' => null, | ||
| 'buttonborderradius' => null, | ||
| 'buttonborderwidth' => null, | ||
| 'textcolor' => null, | ||
| 'default' => null, | ||
| 'values' => null, | ||
| 'placeholder' => null, | ||
| 'class' => null, | ||
| 'width' => null, | ||
| 'consenttype' => null, | ||
| 'dateformat' => null, | ||
| 'implicitconsentmessage' => null, | ||
| 'explicitconsentmessage' => null, | ||
| 'borderradius' => null, | ||
| 'borderwidth' => null, | ||
| 'lineheight' => null, | ||
| 'labellineheight' => null, | ||
| 'bordercolor' => null, | ||
| 'inputcolor' => null, | ||
| 'labelcolor' => null, | ||
| 'labelfontsize' => null, | ||
| 'fieldfontsize' => null, | ||
| 'labelclasses' => null, | ||
| 'labelstyles' => null, | ||
| 'inputclasses' => null, | ||
| 'inputstyles' => null, | ||
| 'optionclasses' => null, | ||
| 'optionstyles' => null, | ||
| 'min' => null, | ||
| 'max' => null, | ||
| 'maxfiles' => null, | ||
| 'fieldwrapperclasses' => null, | ||
| 'outlinestyledata' => array(), | ||
| 'outlinestyleclasses' => null, | ||
| 'optionsclasses' => null, | ||
| 'optionsstyles' => null, | ||
| 'label' => null, | ||
| 'togglelabel' => null, | ||
| 'type' => 'text', | ||
| 'required' => false, | ||
| 'requiredtext' => null, | ||
| 'options' => array(), | ||
| 'optionsdata' => array(), | ||
| 'id' => null, | ||
| 'style' => null, | ||
| 'fieldbackgroundcolor' => null, | ||
| 'buttonbackgroundcolor' => null, | ||
| 'buttonborderradius' => null, | ||
| 'buttonborderwidth' => null, | ||
| 'textcolor' => null, | ||
| 'default' => null, | ||
| 'values' => null, | ||
| 'placeholder' => null, | ||
| 'class' => null, | ||
| 'width' => null, | ||
| 'consenttype' => null, | ||
| 'dateformat' => null, | ||
| 'implicitconsentmessage' => null, | ||
| 'explicitconsentmessage' => null, | ||
| 'borderradius' => null, | ||
| 'borderwidth' => null, | ||
| 'lineheight' => null, | ||
| 'labellineheight' => null, | ||
| 'bordercolor' => null, | ||
| 'inputcolor' => null, | ||
| 'labelcolor' => null, | ||
| 'labelfontsize' => null, | ||
| 'fieldfontsize' => null, | ||
| 'labelclasses' => null, | ||
| 'labelstyles' => null, | ||
| 'inputclasses' => null, | ||
| 'inputstyles' => null, | ||
| 'optionclasses' => null, | ||
| 'optionstyles' => null, | ||
| 'min' => null, | ||
| 'max' => null, | ||
| 'maxfiles' => null, | ||
| 'fieldwrapperclasses' => null, | ||
| 'stylevariationattributes' => array(), | ||
| 'stylevariationclasses' => null, | ||
| 'stylevariationstyles' => null, | ||
| 'optionsclasses' => null, | ||
| 'optionsstyles' => null, | ||
| ), | ||
| $attributes, | ||
| 'contact-field' | ||
|
|
@@ -830,19 +831,19 @@ public function render_radio_field( $id, $label, $value, $class, $required, $req | |
| $fieldset_id = "id='" . esc_attr( "$id-label" ) . "'"; | ||
|
|
||
| if ( $is_outlined_style ) { | ||
| $outline_styles = $this->get_attribute( 'outlinestyledata' ); | ||
| $style_variation_attributes = $this->get_attribute( 'stylevariationattributes' ); | ||
|
|
||
| if ( ! empty( $outline_styles ) ) { | ||
| $outline_styles = json_decode( html_entity_decode( $outline_styles, ENT_COMPAT ), true ); | ||
| if ( ! empty( $style_variation_attributes ) ) { | ||
| $style_variation_attributes = json_decode( html_entity_decode( $style_variation_attributes, ENT_COMPAT ), true ); | ||
| } | ||
|
|
||
| // When there's an outlined style, and border radius is set, the existing inline border radius is overridden to apply | ||
| // a limit of `100px` to the radius on the x axis. This achieves the same look and feel as other fields | ||
| // that use the notch html (`notched-label__leading` has a max-width of `100px` to prevent it from getting too wide). | ||
| // It prevents large border radius values from disrupting the look and feel of the fields. | ||
| if ( isset( $outline_styles['border']['radius'] ) ) { | ||
| if ( isset( $style_variation_attributes['border']['radius'] ) ) { | ||
| $options_styles = $options_styles ?? ''; | ||
| $radius = $outline_styles['border']['radius']; | ||
| $radius = $style_variation_attributes['border']['radius']; | ||
| $has_split_radius_values = is_array( $radius ); | ||
| $top_left_radius = $has_split_radius_values ? $radius['topLeft'] : $radius; | ||
| $top_right_radius = $has_split_radius_values ? $radius['topRight'] : $radius; | ||
|
|
@@ -1233,19 +1234,19 @@ public function render_checkbox_multiple_field( $id, $label, $value, $class, $re | |
| $fieldset_id = "id='" . esc_attr( "$id-label" ) . "'"; | ||
|
|
||
| if ( $is_outlined_style ) { | ||
| $outline_styles = $this->get_attribute( 'outlinestyledata' ); | ||
| $style_variation_attributes = $this->get_attribute( 'stylevariationattributes' ); | ||
|
|
||
| if ( ! empty( $outline_styles ) ) { | ||
| $outline_styles = json_decode( html_entity_decode( $outline_styles, ENT_COMPAT ), true ); | ||
| if ( ! empty( $style_variation_attributes ) ) { | ||
| $style_variation_attributes = json_decode( html_entity_decode( $style_variation_attributes, ENT_COMPAT ), true ); | ||
| } | ||
|
|
||
| // When there's an outlined style, and border radius is set, the existing inline border radius is overridden to apply | ||
| // a limit of `100px` to the radius on the x axis. This achieves the same look and feel as other fields | ||
| // that use the notch html (`notched-label__leading` has a max-width of `100px` to prevent it from getting too wide). | ||
| // It prevents large border radius values from disrupting the look and feel of the fields. | ||
| if ( isset( $outline_styles['border']['radius'] ) ) { | ||
| if ( isset( $style_variation_attributes['border']['radius'] ) ) { | ||
| $options_styles = $options_styles ?? ''; | ||
| $radius = $outline_styles['border']['radius']; | ||
| $radius = $style_variation_attributes['border']['radius']; | ||
| $has_split_radius_values = is_array( $radius ); | ||
| $top_left_radius = $has_split_radius_values ? $radius['topLeft'] : $radius; | ||
| $top_right_radius = $has_split_radius_values ? $radius['topRight'] : $radius; | ||
|
|
@@ -1543,23 +1544,17 @@ class=" ' . $classes . '" | |
| * } | ||
| */ | ||
| private function get_form_variation_style_properties( $form_style = 'outlined' ) { | ||
| $style_attrs = ''; | ||
| $css_vars = ''; | ||
| $outline_styles = $this->get_attribute( 'outlinestyledata' ); | ||
| $outline_classes = $this->get_attribute( 'outlinestyleclasses' ); | ||
| $block_name = 'jetpack/input'; | ||
| $css_vars = ''; | ||
| $variation_attributes = $this->get_attribute( 'stylevariationattributes' ); | ||
| $variation_attributes = ! empty( $variation_attributes ) ? json_decode( html_entity_decode( $variation_attributes, ENT_COMPAT ), true ) : array(); | ||
| $variation_classes = $this->get_attribute( 'stylevariationclasses' ); | ||
| $variation_style = $this->get_attribute( 'stylevariationstyles' ); | ||
| $block_name = 'jetpack/input'; | ||
|
|
||
| if ( $this->maybe_override_type() === 'radio' || $this->maybe_override_type() === 'checkbox-multiple' ) { | ||
| $block_name = 'jetpack/options'; | ||
| } | ||
|
|
||
| $outline_styles = ! empty( $outline_styles ) ? json_decode( html_entity_decode( $outline_styles, ENT_COMPAT ), true ) : array(); | ||
| $input_styles = $this->get_attribute( 'inputstyles' ); | ||
|
|
||
| if ( ! empty( $input_styles ) ) { | ||
| $style_attrs = $input_styles; | ||
| } | ||
|
Comment on lines
1559
to
1561
Contributor
Author
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. This is where the bug was. I've removed it in favor of |
||
|
|
||
| $global_styles = wp_get_global_styles( | ||
| array( 'border' ), | ||
| array( | ||
|
|
@@ -1575,28 +1570,28 @@ private function get_form_variation_style_properties( $form_style = 'outlined' ) | |
| * For newer forms that use global styles or the block supports styles, this value will be empty and is ignored. | ||
| */ | ||
| $border_width_attribute = $this->get_attribute( 'borderwidth' ); | ||
| $legacy_border_size = ! empty( $border_width_attribute ) || $border_width_attribute === '0' ? $border_width_attribute . 'px' : $outline_styles['border']['width'] ?? null; | ||
| $legacy_border_size = ! empty( $border_width_attribute ) || $border_width_attribute === '0' ? $border_width_attribute . 'px' : $variation_attributes['border']['width'] ?? null; | ||
| $legacy_border_size = is_numeric( $legacy_border_size ) ? $legacy_border_size . 'px' : $legacy_border_size; | ||
| $legacy_border_radius = $outline_styles['border']['radius'] ?? null; | ||
| $legacy_border_radius = $variation_attributes['border']['radius'] ?? null; | ||
| $legacy_border_radius = is_numeric( $legacy_border_radius ) ? $legacy_border_radius . 'px' : $legacy_border_radius; | ||
|
|
||
| $border_top_size = $legacy_border_size ?? | ||
| $outline_styles['border']['top']['width'] ?? | ||
| $variation_attributes['border']['top']['width'] ?? | ||
| $global_styles['width'] ?? | ||
| $global_styles['top']['width'] ?? null; | ||
|
|
||
| $border_right_size = $legacy_border_size ?? | ||
| $outline_styles['border']['right']['width'] ?? | ||
| $variation_attributes['border']['right']['width'] ?? | ||
| $global_styles['width'] ?? | ||
| $global_styles['right']['width'] ?? null; | ||
|
|
||
| $border_bottom_size = $legacy_border_size ?? | ||
| $outline_styles['border']['bottom']['width'] ?? | ||
| $variation_attributes['border']['bottom']['width'] ?? | ||
| $global_styles['width'] ?? | ||
| $global_styles['bottom']['width'] ?? null; | ||
|
|
||
| $border_left_size = $legacy_border_size ?? | ||
| $outline_styles['border']['left']['width'] ?? | ||
| $variation_attributes['border']['left']['width'] ?? | ||
| $global_styles['width'] ?? | ||
| $global_styles['left']['width'] ?? null; | ||
|
|
||
|
|
@@ -1628,9 +1623,9 @@ private function get_form_variation_style_properties( $form_style = 'outlined' ) | |
| } | ||
|
|
||
| return array( | ||
| 'style' => $style_attrs, | ||
| 'style' => $variation_style, | ||
| 'css_vars' => $css_vars, | ||
| 'class_name' => $outline_classes, | ||
| 'class_name' => $variation_classes, | ||
| ); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -470,9 +470,8 @@ public static function block_attributes_to_shortcode_attributes( $atts, $type, $ | |
| /* | ||
| Borders for the outlined notched HTML. | ||
| */ | ||
| $outlined_style_data = self::get_outlined_style_attributes( $block_name, $inner_block['attrs'] ); | ||
| $atts['outlinestyledata'] = $outlined_style_data['outlinestyledata'] ?? null; | ||
| $atts['outlinestyleclasses'] = $outlined_style_data['outlinestyleclasses'] ?? null; | ||
| $style_variation_data = self::get_style_variation_shortcode_attributes( $block_name, $inner_block['attrs'] ); | ||
| $atts = array_merge( $atts, $style_variation_data ); | ||
| $add_block_style_classes_to_field_wrapper = true; | ||
| } | ||
|
|
||
|
|
@@ -523,9 +522,8 @@ public static function block_attributes_to_shortcode_attributes( $atts, $type, $ | |
| /* | ||
| Borders for the outlined notched HTML. | ||
| */ | ||
| $outlined_style_data = self::get_outlined_style_attributes( $block_name, $inner_block['attrs'] ); | ||
| $atts['outlinestyledata'] = $outlined_style_data['outlinestyledata']; | ||
| $atts['outlinestyleclasses'] = $outlined_style_data['outlinestyleclasses']; | ||
| $style_variation_atts = self::get_style_variation_shortcode_attributes( $block_name, $inner_block['attrs'] ); | ||
| $atts = array_merge( $atts, $style_variation_atts ); | ||
| $add_block_style_classes_to_field_wrapper = true; | ||
| } | ||
| } | ||
|
|
@@ -552,38 +550,41 @@ public static function block_attributes_to_shortcode_attributes( $atts, $type, $ | |
|
|
||
| /** | ||
| * Returns the form "Outlined" style classes and styles. | ||
| * Important: The "Outlined" style is somewhat different as it uses custom HTML to create a border around the field. | ||
| * Important: The "Outlined" style is somewhat different as it uses custom HTML to create a border around the field's label. | ||
| * When applying styles to the control, background and border styles are applied to the custom HTML, not the input itself. | ||
| * | ||
| * @param string $block_name - the block name. | ||
| * @param array $attrs - the block attributes. | ||
| * | ||
| * @return array | ||
| */ | ||
| protected static function get_outlined_style_attributes( $block_name, $attrs ) { | ||
| $outlined_style_data = array(); | ||
| $attributes_for_outlined_style = array(); | ||
| protected static function get_style_variation_shortcode_attributes( $block_name, $attrs ) { | ||
| $picked_attributes = array(); | ||
|
|
||
| // For style variations like the outlined style, we only care about porting specific attributes like background color and border | ||
| // to the custom label HTML, so we pick those attributes and ignore the rest. | ||
| if ( isset( $attrs['backgroundColor'] ) ) { | ||
| $attributes_for_outlined_style['backgroundColor'] = $attrs['backgroundColor']; | ||
| $picked_attributes['backgroundColor'] = $attrs['backgroundColor']; | ||
| } | ||
|
|
||
| if ( isset( $attrs['style']['border'] ) ) { | ||
| $attributes_for_outlined_style['style']['border'] = $attrs['style']['border']; | ||
| $picked_attributes['style']['border'] = $attrs['style']['border']; | ||
| } | ||
|
|
||
| if ( isset( $attrs['borderColor'] ) ) { | ||
| $attributes_for_outlined_style['borderColor'] = $attrs['borderColor']; | ||
| $picked_attributes['borderColor'] = $attrs['borderColor']; | ||
| } | ||
|
|
||
| if ( isset( $attrs['style']['color']['background'] ) ) { | ||
| $attributes_for_outlined_style['style']['color']['background'] = $attrs['style']['color']['background']; | ||
| $picked_attributes['style']['color']['background'] = $attrs['style']['color']['background']; | ||
| } | ||
|
|
||
| $outlined_attrs = self::get_block_support_classes_and_styles( $block_name, $attributes_for_outlined_style ); | ||
| $outlined_style_data['outlinestyledata'] = isset( $attributes_for_outlined_style['style'] ) ? \wp_json_encode( $attributes_for_outlined_style['style'] ) : ''; | ||
| $outlined_style_data['outlinestyleclasses'] = isset( $outlined_attrs['class'] ) ? ' ' . $outlined_attrs['class'] : ''; | ||
| return $outlined_style_data; | ||
| $block_support_styles = self::get_block_support_classes_and_styles( $block_name, $picked_attributes ); | ||
| return array( | ||
| 'stylevariationattributes' => isset( $picked_attributes['style'] ) ? \wp_json_encode( $picked_attributes['style'] ) : '', | ||
| 'stylevariationclasses' => isset( $block_support_styles['class'] ) ? ' ' . $block_support_styles['class'] : '', | ||
| 'stylevariationstyles' => isset( $block_support_styles['style'] ) ? $block_support_styles['style'] : '', | ||
| ); | ||
|
Comment on lines
582
to
587
Contributor
Author
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. This is where |
||
| } | ||
|
|
||
| /** | ||
|
|
||
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.
👍🏻