diff --git a/projects/packages/forms/changelog/fix-forms-button-style b/projects/packages/forms/changelog/fix-forms-button-style new file mode 100644 index 0000000000000..a9d698b517b8c --- /dev/null +++ b/projects/packages/forms/changelog/fix-forms-button-style @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Forms: Ensure multi and single choice button text and backgrounds won't be the same color. diff --git a/projects/packages/forms/src/blocks/contact-form/util/form-styles.js b/projects/packages/forms/src/blocks/contact-form/util/form-styles.js index 2121e7026af28..0d07dbce37a67 100644 --- a/projects/packages/forms/src/blocks/contact-form/util/form-styles.js +++ b/projects/packages/forms/src/blocks/contact-form/util/form-styles.js @@ -78,6 +78,20 @@ window.jetpackForms.generateStyleVariables = function ( formNode ) { lineHeight: buttonOutlineLineHeight, } = window.getComputedStyle( buttonOutlineNode ); + // This provides a fallback for the button outline text color when the button outline background color is the same as the text color. + let safeButtonOutlineTextColor = buttonOutlineTextColor; + if ( buttonOutlineBackgroundColor === buttonOutlineTextColor ) { + const elements = document.querySelectorAll( + '.contact-form .grunion-field-wrap.grunion-field-checkbox-multiple-wrap.is-style-button-wrap .contact-form-field, .contact-form .grunion-field-wrap.is-style-button-wrap .grunion-radio-label' + ); + if ( elements.length > 0 ) { + const buttonLink = document.querySelector( '.wp-block-button__link' ); + safeButtonOutlineTextColor = buttonLink + ? getComputedStyle( buttonLink ).getPropertyValue( 'color' ) + : backgroundColor; + } + } + const buttonOutlineBackgroundColorFallback = window.jetpackForms.getBackgroundColor( buttonOutlineNode ); @@ -126,7 +140,7 @@ window.jetpackForms.generateStyleVariables = function ( formNode ) { buttonOutlineBackgroundColorFallback, '--jetpack--contact-form--button-outline--border-size': buttonOutlineBorderSize, '--jetpack--contact-form--button-outline--border-radius': buttonOutlineBorderRadius, - '--jetpack--contact-form--button-outline--text-color': buttonOutlineTextColor, + '--jetpack--contact-form--button-outline--text-color': safeButtonOutlineTextColor, '--jetpack--contact-form--button-outline--line-height': buttonOutlineLineHeight, }; }; diff --git a/projects/packages/forms/src/contact-form/css/grunion.css b/projects/packages/forms/src/contact-form/css/grunion.css index 90ecfbdc68369..eb3b70a0d1d77 100644 --- a/projects/packages/forms/src/contact-form/css/grunion.css +++ b/projects/packages/forms/src/contact-form/css/grunion.css @@ -634,6 +634,11 @@ on production builds, the attributes are being reordered, causing side-effects line-height: var(--jetpack--contact-form--button-outline--line-height); } +.contact-form .grunion-field-wrap.grunion-field-checkbox-multiple-wrap.is-style-button-wrap .contact-form-field, +.contact-form .grunion-field-wrap.is-style-button-wrap .grunion-checkbox-multiple-label { + color: var(--jetpack--contact-form--button-outline--text-color); +} + .contact-form .grunion-field-wrap.is-style-button-wrap .grunion-field.radio.is-style-button { /* visually-hidden */ clip: rect(0 0 0 0); diff --git a/projects/plugins/jetpack/changelog/fix-forms-button-style b/projects/plugins/jetpack/changelog/fix-forms-button-style new file mode 100644 index 0000000000000..afe50778ee929 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-forms-button-style @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +Forms: Ensure single and multi choice button text and backgrounds won't be the same color.