Repository navigation
Forms: Fix CSS specificity for compatibility with global styles on the frontend #43299
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
Changes from all commits
686519c
aad356f
3b813fb
9509487
4c51793
cfaa952
9deed62
fa8d36b
a522931
8be1607
e1dd2d4
5acc81a
82c9c65
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 |
|---|---|---|
|
|
@@ -89,10 +89,13 @@ | |
| font-weight: 700; | ||
| } | ||
|
|
||
| .contact-form label.consent { | ||
| .contact-form :where(label.consent) { | ||
| font-size: 13px; | ||
| font-weight: 400; | ||
|
Member
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. While re-testing, I just noticed that I think the default
So, there could be an opportunity to further reduce the specificity of For now, since this PR reduces the So IMO not a blocker for proceeding with this change 👍
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. I've made an issue (FORMS-41) to track that. |
||
| text-transform: uppercase; | ||
| } | ||
|
|
||
| .contact-form label.consent { | ||
| display: flex; | ||
| align-items: center; | ||
| } | ||
|
|
@@ -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) { | ||
|
|
||
|
Member
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. Tiniest of nits: unintended single line whitespace? (not a blocker)
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. Unfortunately Jetpack's linter auto adds this above any comments (there's one on the following line).
Member
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. 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; | ||
| } | ||
|
|
||
|
|
@@ -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; | ||
|
|
@@ -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; | ||
|
|
@@ -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; | ||
|
|
@@ -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; | ||
|
|
||
|
|
@@ -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%); | ||
|
|
@@ -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); | ||
|
|
@@ -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 { | ||
|
|
@@ -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; | ||
|
|
@@ -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); | ||
| } | ||
|
|
||

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.
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: noneon the pseudoelement doesn't solve it: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.
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.
Seems to be working well to me, too!