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

Make required asterisk theme-independant #640

Merged

Conversation

vjawala
Copy link
Contributor

@vjawala vjawala commented Feb 1, 2024

In _formio_component.scss the field-required asterisk is removed because it is handled with the "utrecht-form-label--openforms-required" class. But this class was scoped on the "openforms-theme", meaning it did not work with other themes.

As the showing/hiding of the asterisk is a core functionality I think this css should be scoped on all themes. Styling can be further tweaked in the specific design system.

@include anchor.extend-utrecht-link;
// TODO: remove font-weight rule on 2.0, it's only here for backwards compatibility
font-weight: var(--utrecht-form-label-font-weight, var(--of-label-font-weight));
.utrecht-form-label {
Copy link
Member

Choose a reason for hiding this comment

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

This will also affect utrecht-form-label components outside of our SDK root, so if a CMS solution has other forms on the page (e.g. contact), our CSS overrides leak outside of our own "zone" when embedding forms in pages.

To avoid this, I think we need to gate the CSS overrides like display, line-height etc. behind design tokens and define these design token values in our own openforms-theme.

OR we scope these CSS overrides to .utrecht-form-label.utrecht-form-label--openforms instead - that's probably the neater solution:

.utrecht-form-label {
    @include bem.modifier('openforms') {
        display: block;
        line-height: 1.333;
        overflow-wrap: break-word;
        ...
    }
    
    @include bem.modifier('openforms-required') { ... }
}

Copy link
Contributor Author

@vjawala vjawala Feb 2, 2024

Choose a reason for hiding this comment

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

Ah good one.

When the field is required the label does not get the .utrecht-form-label--openforms class, only .utrecht-form-label--openforms-required. What if we scope it to the generic openforms container?

.openforms-container {
  .utrecht-form-label {
    ...

Copy link
Member

Choose a reason for hiding this comment

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

.openforms-container is not a class/component we have 🤔

When the field is required the label does not get the .utrecht-form-label--openforms class

Yeah I think we should patch that extra utrecht-form-label--openforms classname in (to always have it):

Not sure if there are any extra places where this would apply, but I think our visual regression testing will catch them if I missed anything.

Copy link
Contributor Author

@vjawala vjawala Feb 2, 2024

Choose a reason for hiding this comment

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

ah yes it's the class that formio wraps around the form I think. I like the approach you mentioned (instead of catching all scenario's with just css). Found a few other files where I added the "base" classname. Updated the PR!

@sergei-maertens
Copy link
Member

Thanks for the contribution!

Copy link

codecov bot commented Feb 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (831dd12) 74.85% compared to head (ff47bc4) 74.10%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #640      +/-   ##
==========================================
- Coverage   74.85%   74.10%   -0.75%     
==========================================
  Files         224      224              
  Lines        4542     4542              
  Branches     1211     1211              
==========================================
- Hits         3400     3366      -34     
- Misses       1103     1137      +34     
  Partials       39       39              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@sergei-maertens sergei-maertens left a comment

Choose a reason for hiding this comment

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

Very nice!

@sergei-maertens sergei-maertens merged commit 6d91467 into open-formulieren:main Feb 2, 2024
11 of 12 checks passed
@vjawala vjawala deleted the fix/required-fields-asterisk branch February 3, 2024 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants