Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -819,11 +819,11 @@ public function render_radio_field( $id, $label, $value, $class, $required, $req
}
$used_html_ids[ $radio_id ] = true;

$default_classes = 'wp-block-jetpack-option grunion-radio-label radio';
$default_classes = 'contact-form-field wp-block-jetpack-option';
$option_styles = empty( $option['style'] ) ? '' : "style='" . $option['style'] . "'";
$option_classes = empty( $option['class'] ) ? $default_classes : $default_classes . ' ' . $option['class'];

$field .= "<p class='contact-form-field'>";
$field .= "<p {$option_styles} class='{$option_classes}'>";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As well as the option classes, I've also moved the option inline styles to the option block wrapper element for consistency. It all seems to work as expected from what I can tell.

One weird issue I've noticed is if you apply text decoration to an option that has the button style variation active, the checkmark also looks like it also has text decoration, and setting text-decoration: none on the pseudoelement doesn't solve it:
Screenshot 2025-05-01 at 4 42 47 pm

This stack overflow answer explains it - https://stackoverflow.com/questions/1238881/text-decoration-and-the-after-pseudo-element-revisited#comment1071169_1239140 - it's not actually the text decoration applying to the pseudo element, the pseudo element is being rendered over the top of the text decoration, so that's why it can't be turned off.

It was also an issue before, this change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be working well to me, too!

$field .= "<input
id='" . esc_attr( $radio_id ) . "'
type='radio'
Expand All @@ -833,7 +833,7 @@ public function render_radio_field( $id, $label, $value, $class, $required, $req
. checked( $option_label, $value, false ) . ' '
. ( $required ? "required aria-required='true'" : '' )
. '/> ';
$field .= "<label for='" . esc_attr( $radio_id ) . "' {$option_styles} class='" . $option_classes . ( $this->is_error() ? ' form-error' : '' ) . "'>";
$field .= "<label for='" . esc_attr( $radio_id ) . "' class='grunion-radio-label radio" . ( $this->is_error() ? ' form-error' : '' ) . "'>";
$field .= "<span class='grunion-field-text'>" . esc_html( $option_label ) . '</span>';
$field .= '</label>';
$field .= '</p>';
Expand Down Expand Up @@ -1175,11 +1175,11 @@ public function render_checkbox_multiple_field( $id, $label, $value, $class, $re
}
$used_html_ids[ $checkbox_id ] = true;

$default_classes = 'wp-block-jetpack-option grunion-checkbox-multiple-label checkbox-multiple';
$default_classes = 'contact-form-field wp-block-jetpack-option';
$option_styles = empty( $option['style'] ) ? '' : "style='" . $option['style'] . "'";
$option_classes = empty( $option['class'] ) ? $default_classes : $default_classes . ' ' . $option['class'];

$field .= "<p class='contact-form-field'>";
$field .= "<p {$option_styles} class='{$option_classes}'>";
$field .= "<input
id='" . esc_attr( $checkbox_id ) . "'
type='checkbox'
Expand All @@ -1188,7 +1188,7 @@ public function render_checkbox_multiple_field( $id, $label, $value, $class, $re
. $class
. checked( in_array( $option_label, (array) $value, true ), true, false )
. ' /> ';
$field .= "<label for='" . esc_attr( $checkbox_id ) . "' {$option_styles} class='" . $option_classes . ( $this->is_error() ? ' form-error' : '' ) . "'>";
$field .= "<label for='" . esc_attr( $checkbox_id ) . "' class='grunion-checkbox-multiple-label checkbox-multiple" . ( $this->is_error() ? ' form-error' : '' ) . "'>";
$field .= "<span class='grunion-field-text'>" . esc_html( $option_label ) . '</span>';
$field .= '</label>';
$field .= '</p>';
Expand Down
97 changes: 64 additions & 33 deletions projects/packages/forms/src/contact-form/css/grunion.css
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,13 @@
font-weight: 700;
}

.contact-form label.consent {
.contact-form :where(label.consent) {
font-size: 13px;
font-weight: 400;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While re-testing, I just noticed that I think the default font-weight: 400 overwrites a theme's overall fontWeight set in theme.json. For example, TT5 theme sets font-weight: 300 and this gets overwritten to 400, whereas in the editor it doesn't get overwritten:

image

So, there could be an opportunity to further reduce the specificity of font-weight rules so that they play nicely with global font-weight set across a theme. However, I think this is likely out of scope for the current exercise as I imagine these 400 rules pre-exist the inner blocks refactor?

For now, since this PR reduces the font-weight so that it's compatible with setting block-level font weight in global styles, I think we've achieved the desired specificity reduction, and I'm aware it's very easy to accidentally increase scope of tasks right now.

So IMO not a blocker for proceeding with this change 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made an issue (FORMS-41) to track that.

text-transform: uppercase;
}

.contact-form label.consent {
display: flex;
align-items: center;
}
Expand All @@ -101,14 +104,17 @@
display: none;
}

.contact-form label.checkbox {
font-weight: 400;
.contact-form :where(label.checkbox-multiple),
.contact-form :where(label.radio),
.contact-form :where(label.checkbox) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiniest of nits: unintended single line whitespace? (not a blocker)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately Jetpack's linter auto adds this above any comments (there's one on the following line).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good to know! Ignore me then 🙂

/* Inherit the font weight from the parent 'option' block wrapper */
font-weight: inherit;
}

.contact-form label.checkbox-multiple,
.contact-form label.radio {
margin-bottom: 0;
font-weight: 400;
flex: 1;
}

Expand Down Expand Up @@ -144,8 +150,6 @@
}
}

.contact-form .is-style-outlined .grunion-checkbox-multiple-options legend,

.contact-form .is-style-outlined .grunion-checkbox-multiple-options legend,
.contact-form .is-style-outlined .grunion-radio-options legend {
margin: 0 0 -0.75em;
Expand All @@ -163,8 +167,8 @@
margin: 0;
}

.contact-form label span.required,
.grunion-label-required {
.contact-form :where(label span.required),
.contact-form :where(.grunion-label-required) {
font-size: 85%;
margin-left: 0.25em;
font-weight: 400;
Expand Down Expand Up @@ -377,13 +381,13 @@
inset-inline-end: 20px;
top: 50%;

content: "";
display: block;
content: "";
display: block;
width: 8px;
height: 8px;

border-bottom: 2px solid;
border-right: 2px solid;
border-right: 2px solid;

transform: translateY(-50%) rotate(45deg);
transform-origin: center center;
Expand Down Expand Up @@ -644,13 +648,30 @@ on production builds, the attributes are being reordered, causing side-effects
padding-top: 8px;
}

.contact-form :where(.grunion-checkbox-multiple-options .contact-form-field),
.contact-form :where(.grunion-radio-options .contact-form-field),
.contact-form :where(.grunion-checkbox .contact-form-field) {
font-weight: 400;
}

.contact-form :where(.grunion-checkbox-multiple-options .contact-form-field),
.contact-form :where(.grunion-radio-options .contact-form-field) {

/* Back compat for the old css vars used in the old radio and checkbox styles */
font-size: var(--jetpack--contact-form--font-size);
}

.contact-form .grunion-field-wrap input.checkbox-multiple,
.contact-form .grunion-field-wrap input.radio {
position: relative;

box-sizing: border-box;
width: var(--jetpack--contact-form--font-size);
height: var(--jetpack--contact-form--font-size);

/* Inherit the font size from the parent element. This allows the input to scale with the font size
set from global styles or from block styles */
font-size: inherit;
width: 1em;
height: 1em;
margin-inline-end: calc(var(--jetpack--contact-form--font-size) / 2);
padding: 0;

Expand All @@ -668,14 +689,16 @@ on production builds, the attributes are being reordered, causing side-effects

.contact-form .grunion-field-wrap input.checkbox-multiple:checked::before {
content: "\2713";

position: absolute;
top: calc(var(--jetpack--contact-form--font-size) / 2);
left: calc(var(--jetpack--contact-form--font-size) / 2);

/* Inherit the font size from the parent element. This allows the input to scale with the font size
set from global styles or from block styles */
font-size: inherit;
top: calc(1em / 2);
left: calc(1em / 2);

display: block;

font-size: var(--jetpack--contact-form--font-size);
line-height: 1;

transform: translate(-50%, -50%);
Expand All @@ -685,19 +708,27 @@ on production builds, the attributes are being reordered, causing side-effects
background: currentColor;
border-radius: 50%;
content: '';
height: calc(var(--jetpack--contact-form--font-size) / 2);

/* Inherit the font size from the parent element. This allows the input to scale with the font size
set from global styles or from block styles */
font-size: inherit;
height: calc(1em / 2);
width: calc(1em / 2);
margin-left: 50%;
margin-top: 50%;
position: absolute;
transform: translate(-50%, -50%);
width: calc(var(--jetpack--contact-form--font-size) / 2);
}

.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 {
.contact-form .grunion-field-wrap.grunion-field-radio-wrap.is-style-button-wrap .contact-form-field {
display: inline-flex;
align-items: center;
padding: var(--jetpack--contact-form--button-outline--padding);
}

.contact-form :where(.grunion-field-wrap.grunion-field-checkbox-multiple-wrap.is-style-button-wrap .contact-form-field),
.contact-form :where(.grunion-field-wrap.grunion-field-radio-wrap.is-style-button-wrap .contact-form-field) {
background: var(--jetpack--contact-form--button-outline--background-color);
border: var(--jetpack--contact-form--button-outline--border);
border-radius: var(--jetpack--contact-form--button-outline--border-radius);
Expand All @@ -709,12 +740,12 @@ on production builds, the attributes are being reordered, causing side-effects

/* visually-hidden */
clip: rect(0 0 0 0);
clip-path: inset(50%);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
clip-path: inset(50%);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}

.contact-form .grunion-field-wrap.is-style-button-wrap .grunion-field.radio:checked + .grunion-radio-label {
Expand All @@ -732,18 +763,18 @@ on production builds, the attributes are being reordered, causing side-effects
outline-offset: 2px;
}

.contact-form .grunion-field-wrap.is-style-button-wrap .grunion-field.checkbox-multiple {
.contact-form :where(.grunion-field-wrap.is-style-button-wrap .grunion-field.checkbox-multiple) {
border-radius: var(--jetpack--contact-form--button-outline--border-radius);
color: var(--jetpack--contact-form--button-outline--text-color);

font-family: var(--wp--preset--font-family--body);
}

.contact-form .grunion-field-wrap.is-style-button-wrap .grunion-field.checkbox-multiple:focus {
outline-width: 0; /* focus style defined on parent */
}

.contact-form .is-style-button-wrap input.grunion-field + .grunion-field-text::before {
/* TODO - is this style used anywhere? if not, remove it */
.contact-form :where(.is-style-button-wrap input.grunion-field + .grunion-field-text::before) {
background: var(--jetpack--contact-form--button-outline--background-color);
border: var(--jetpack--contact-form--button-outline--border);
border-color: currentColor;
Expand All @@ -759,16 +790,16 @@ on production builds, the attributes are being reordered, causing side-effects
z-index: -1;
}

.contact-form .is-style-button-wrap input.grunion-field {
.contact-form :where(.is-style-button-wrap input.grunion-field) {
color: var(--jetpack--contact-form--button-outline--color);
}

.contact-form .is-style-button-wrap input.grunion-field:checked,
.contact-form .is-style-button-wrap input.grunion-field:checked + .grunion-field-text {
.contact-form :where(.is-style-button-wrap input.grunion-field:checked),
.contact-form :where(.is-style-button-wrap input.grunion-field:checked + .grunion-field-text) {
color: var(--jetpack--contact-form--button-outline--background-color-fallback);
}

.contact-form .is-style-button-wrap input.grunion-field:checked + .grunion-field-text::before {
.contact-form :where(.is-style-button-wrap input.grunion-field:checked + .grunion-field-text::before) {
background: var(--jetpack--contact-form--button-outline--text-color);
border-color: var(--jetpack--contact-form--button-outline--text-color);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1379,22 +1379,25 @@ public function assertValidFieldMultiField( $html, $attributes ) {
}

if ( ! empty( $attributes['optionsdata'] ) ) {
$filtered = array_filter(
$filtered = array_filter(
json_decode( $attributes['optionsdata'] ),
function ( $option ) use ( $input ) {
return $option->label === $input->getAttribute( 'value' );
}
);
$label_style = array_values( $filtered )[0] ?? null;
// Block styles and classes are applied to the option wrapper.
$option = $item_label->parentNode; //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase

$option_data = array_values( $filtered )[0] ?? null;
// @phan-suppress-next-line PhanUndeclaredMethod - Phan doesn't know that getAttribute is available. But it is.
if ( ! empty( $item_label->getAttribute( 'style' ) ) ) {
// @phan-suppress-next-line PhanUndeclaredMethod
$this->assertEquals( $item_label->getAttribute( 'style' ), $label_style->style, 'Style doesn\'t match' );
$this->assertEquals( $option->getAttribute( 'style' ), $option_data->style, 'Style doesn\'t match' );
}
// @phan-suppress-next-line PhanUndeclaredMethod
if ( ! empty( $item_label->getAttribute( 'class' ) ) ) {
// @phan-suppress-next-line PhanUndeclaredMethod
$this->assertContains( $label_style->class, explode( ' ', $item_label->getAttribute( 'class' ) ), 'Class doesn\'t match' );
$this->assertContains( $option_data->class, explode( ' ', $option->getAttribute( 'class' ) ), 'Class doesn\'t match' );
}
}
}
Expand Down