question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[core] Using hardcoded pseudo classes versus values coming from classes object

See original GitHub issue

Opening this issue so that we can align on the way we are writing the styles for the pseudo states.

Current Behavior 😯

We have inconsistencies with how we are defining the style for the pseudo states. On some places we use hardcoded classes:

    '&.Mui-disabled': {
      color: theme.palette.action.disabled,
      ...(styleProps.variant === 'outlined' && {
        border: `1px solid ${theme.palette.action.disabledBackground}`,
      }),
      ...(styleProps.variant === 'outlined' &&
        styleProps.color === 'secondary' && {
          border: `1px solid ${theme.palette.action.disabled}`,
        }),
      ...(styleProps.variant === 'contained' && {
        color: theme.palette.action.disabled,
        boxShadow: theme.shadows[0],
        backgroundColor: theme.palette.action.disabledBackground,
      }),
    },

and on other we are using the classes coming from componentClasses[pseudoState], for example:

    /* Styles applied to the root element if `disabled={true}`. */
    [`&.${iconButtonClasses.disabled}`]: {
      backgroundColor: 'transparent',
      color: theme.palette.action.disabled,
    },

Expected Behavior 🤔

We should use the same way for defining styles for the pseudo states, we just need to decide with which one to use. Here is comparison of both:

  1. Using hardcoded classes +immediately obvious that it defined styles for pseudo state +easy to copy-paste when overriding -the prefix cannot be easily customized (not implemented currently as a functionality, but it could be 🤷)
  2. Using componentClasses[pseudoState] +consistency with how all styles are defined +does not require knowledge of which classes are pseudo states and which are regular classes -~not easily noticeable which styles are for pseudo states, and which are styles for the slots~

I am leaning towards using option 2. everywhere, but I am open for other opinions. Anyway, we should be consistent and use the same everywhere.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mnajdovacommented, Apr 13, 2021

I’ll create PR to normalize all styles to use 2. componentClasses[pseudoState], seems like it brings more benefits than 1. and we will at least have consistency.

1reaction
eps1loncommented, Apr 8, 2021

Gotcha. Coming back to “-not easily noticeable which styles are for pseudo states, and which are styles for the slots”. This is irrelevant to this issue since the higher specificity is caused by the selector.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[core] Using hardcoded pseudo classes versus values coming ...
Opening this issue so that we can align on the way we are writing the styles for the pseudo states. Current Behavior.
Read more >
Pseudo-classes and pseudo-elements - MDN Web Docs
A pseudo-class is a selector that selects elements that are in a specific state, e.g. they are the first element of their type,...
Read more >
Selectors - W3C
Pseudo -classes classify elements on characteristics other than their name, attributes or content; in principle characteristics that cannot be deduced from the ...
Read more >
Angular ngClass and ngStyle: The Complete Guide
In this post, we are going to learn the most commonly used options that we have available for styling our Angular components using...
Read more >
Pseudo-Elements - LearnHowToProgram.com
Unlike pseudo-classes, which capture state information about an existing DOM element, pseudo-elements allow us to create items that don't normally exist in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found