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

Forms: Ensure form choice buttons have a fallback text color if text and background are the same #39789

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions projects/packages/forms/changelog/fix-forms-button-style
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Forms: Ensure multi and single choice button text and backgrounds won't be the same color.
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -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,
};
};
5 changes: 5 additions & 0 deletions projects/packages/forms/src/contact-form/css/grunion.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/fix-forms-button-style
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

Forms: Ensure single and multi choice button text and backgrounds won't be the same color.
Loading