Skip to content

refactor: CSS "condition" to SCSS condition #4690

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

mfranzke
Copy link
Collaborator

@mfranzke mfranzke commented Aug 6, 2025

Proposed changes

Currently we've checked for the elements to be either input or textarea at the CSS level with :is(). Instead as we're using those in a SCSS mixin, we should that for check for those element types in a SCSS condition.

The main purpose of this is to prevent resulting selectors like .db-input input:is(input,textarea):not(:disabled):read-only

Types of changes

  • Bugfix (non-breaking change that fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (improvements to existing components or architectural decisions)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Further comments

@mfranzke mfranzke self-assigned this Aug 6, 2025
@mfranzke mfranzke requested a review from nmerget as a code owner August 6, 2025 13:46
@mfranzke mfranzke added the 🍄🆙improvement New feature or request label Aug 6, 2025
@mfranzke mfranzke moved this to 👀 In review in UX Engineering Team Backlog Aug 6, 2025
@mfranzke mfranzke removed their assignment Aug 6, 2025
Copy link
Contributor

github-actions bot commented Aug 6, 2025

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@mfranzke mfranzke changed the title refactor: css condition to scss condition refactor: CSS "condition" to SCSS condition Aug 6, 2025
@mfranzke mfranzke enabled auto-merge (squash) August 6, 2025 14:38
mfranzke and others added 2 commits August 6, 2025 16:39
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This refactoring moves CSS element type checking from runtime CSS :is() selectors to build-time SCSS conditions, improving maintainability and performance by reducing CSS complexity. The change replaces CSS pseudo-selectors with SCSS conditional compilation.

  • Replaced CSS :is(input, textarea) selectors with SCSS @if conditions using list.index()
  • Added SCSS variables to define valid form field types for read-only and field-sizing properties
  • Updated CSS variable naming to be dynamic based on the element type

Comment on lines +13 to +17
// https://developer.mozilla.org/en-US/docs/Web/CSS/:read-only
$valid-read-only-form-fields: input, textarea;
// https://developer.mozilla.org/en-US/docs/Web/CSS/field-sizing
$valid-field-sizing-form-fields: input, textarea;

Copy link
Contributor

Choose a reason for hiding this comment

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

Currently, both $valid-field-sizing-form-fields and $valid-read-only-form-fields contain the same elements (input, textarea). Do we need to keep them separate for semantic clarity, or could we merge them into a single list to reduce redundancy?

Copy link
Collaborator Author

@mfranzke mfranzke Aug 12, 2025

Choose a reason for hiding this comment

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

I was struggling with this as well. Perhaps there is no clear right or wrong, but when it comes to choosing between DRY and distinguishing between two completely different CSS features, the latter may be slightly more relevant.

@if list.index($valid-read-only-form-fields, $selector) {
&:not(:disabled):read-only {
background-color: var(
--db-#{$selector}-read-only,
Copy link
Contributor

Choose a reason for hiding this comment

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

This was --db-textarea-read-only before and is now element-specific. I think that is fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was --db-textarea-read-only before and is now element-specific. I think that is fine.

In general this isn't a variable we're providing, but only something we provide as a "Styling API". So scoping this to the "correct" component (input instead of textarea) might even be benefical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍄🆙improvement New feature or request
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

2 participants