Skip to content

Commit 27960db

Browse files
authored
Fix form-related Jetpack style bugs (#2154)
1 parent 33025a9 commit 27960db

File tree

7 files changed

+50
-19
lines changed

7 files changed

+50
-19
lines changed

.changeset/cold-pillows-do.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cloudfour/patterns': patch
3+
---
4+
5+
Fix display of empty field values in Jetpack form success messaging

.changeset/nasty-frogs-smile.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cloudfour/patterns': patch
3+
---
4+
5+
Fix stretched `select` caret icon bug in Firefox by removing old Chrome hack that no longer seems necessary

.changeset/neat-parrots-shop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cloudfour/patterns': patch
3+
---
4+
5+
Fix right padding in `select.c-input` elements (was missing a math operator)

src/mixins/_input.scss

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,12 @@
8686

8787
/// Types that disclose additional options should have an icon
8888
///
89-
/// 1. Setting the background size to `100%` avoids a strange background shift
90-
/// bug on hover in Chrome but has no visible effect in other browsers as
91-
/// long as the image is an SVG that does not preserve its aspect ratio.
92-
/// 2. Firefox misaligns inner options when padding is applied, but all modern
89+
/// 1. Firefox misaligns inner options when padding is applied, but all modern
9390
/// browsers seem to align selects predictably even when there is no
9491
/// vertical padding. We still keep a small amount of padding because
9592
/// Firefox's inner dotted outline looks gross when it runs into the outer
9693
/// border, and existing hacks around this visibly degrade text rendering.
97-
/// 3. Prevents option text from overlapping icon.
94+
/// 2. Prevents option text from overlapping icon.
9895
@mixin icon-affordance(
9996
$icon-url: svg-load('icons/caret-down.svg', fill=color.$text-dark)
10097
) {
@@ -104,9 +101,10 @@
104101

105102
background-position: right size.$spacing-control-icon-inset center;
106103
background-repeat: no-repeat;
107-
background-size: size.$square-control-icon 100%; // 1
108-
padding-block: math.div(size.$padding-control-vertical, 2); // 2
109-
padding-inline-end: size.$spacing-control-icon-inset size.$square-control-icon; // 3
104+
background-size: size.$square-control-icon;
105+
padding-block: math.div(size.$padding-control-vertical, 2); // 1
106+
padding-inline-end: size.$spacing-control-icon-inset +
107+
size.$square-control-icon; // 2
110108
}
111109

112110
/// Various input and interaction states

src/vendor/wordpress/demo/contact-form/success.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434
<p></p>
3535
<p></p>
3636
<div class="field-name">Date:</div>
37-
<div class="field-value">Today</div>
37+
<div class="field-value"></div>
3838
<p></p>
3939
<p></p>
4040
<div class="field-name">Phone:</div>
41-
<div class="field-value">5555555555</div>
41+
<div class="field-value"></div>
4242
<p></p>
4343
<p></p>
4444
<div class="field-name">Website:</div>

src/vendor/wordpress/jetpack-blocks.stories.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Our styles include customizations for some of these form elements, with some exc
4646
</Story>
4747
</Canvas>
4848

49-
The success messaging markup generated by these blocks is pretty quirky, but we do our best to style it.
49+
The success messaging markup generated by these blocks is pretty quirky, but we do our best to style it. Browsers that support `:has` will hide any field summaries with empty values.
5050

5151
<Canvas>
5252
<Story name="Contact Form Success" parameters={{ layout: 'fullscreen' }}>

src/vendor/wordpress/styles/_jetpack-blocks.scss

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,37 @@
154154
clear: left; // 1
155155
font-weight: font-weight.$medium; // 2
156156
margin-inline-end: 1ch; // 3
157+
158+
/// If there is no field value, don't bother displaying the field name.
159+
&:has(+ .field-value:empty) {
160+
display: none;
161+
}
157162
}
158163

159-
/// 1. Field values appear slightly muted.
160-
/// 2. Because values may break onto new lines, we need to use bottom margin
161-
/// to continue vertical rhythm. We only apply this when the field value is
162-
/// the last of its type: We can't use `:last-child` because it is often
163-
/// followed by an empty paragraph. (This can be simplified once
164-
/// `margin-trim` is widely supported!)
164+
/// Field values appear slightly muted.
165+
165166
.field-value {
166-
color: var(--theme-color-text-muted); // 1
167+
color: var(--theme-color-text-muted);
168+
169+
/// Empty field values need to clear floats to maintain margin.
170+
&:empty {
171+
clear: left;
172+
float: none;
173+
174+
/// If the browser supports `:has()`, we can hide the field value entirely
175+
/// since the field name will be hidden as well.
176+
@supports selector(:has(+ :empty)) {
177+
display: none;
178+
}
179+
}
167180

181+
/// Because values may break onto new lines, we need to use bottom margin
182+
/// to continue vertical rhythm. We only apply this when the field value is
183+
/// the last of its type: We can't use `:last-child` because it is often
184+
/// followed by an empty paragraph. (This can be simplified once
185+
/// `margin-trim` is widely supported!)
168186
&:not(:last-of-type) {
169-
margin-block-end: var(--rhythm, #{size.$rhythm-default}); // 2
187+
margin-block-end: var(--rhythm, #{size.$rhythm-default});
170188
}
171189
}
172190
}

0 commit comments

Comments
 (0)