Code Monkey home page Code Monkey logo

Comments (7)

 avatar commented on July 24, 2024

Using :global fixes this issue. For example:

&:global(:container(width >= 18em)) {}

However, it still seems to be failing when there is some class change on the element (adding a class .active, for example). The CSS breaks in this case, as the container query disappears from the HTML element. Later, though, if the viewport is resized, everything goes back to normal.

from cq-prolyfill.

ausi avatar ausi commented on July 24, 2024

The PostCSS plugin converts the container query to an escaped class name, e.g. from :container(width < 10em) to .\:container\(width\<10em\) so it looks like a regular class name. Maybe it helps if you let the cq-prolyfill-plugin run after the css modules plugin.

If that doesn’t help, could you give me a quick example how I can reproduce this issue?

from cq-prolyfill.

paul-sachs avatar paul-sachs commented on July 24, 2024

@rulych is correct, using global works off the bat until something changes the class.

I tried moving the the css modules plugin to only process after but it doesn't work. I'll put the partial configs below:

webpack:

module: {
    loaders: [
      {
        test:   /\.css$/,
        loader: 'style-loader!css-loader?modules!postcss-loader'
      }
}
...
postcss: [
  require('postcss-nested'),
  require('cq-prolyfill/postcss-plugin')
]

component:

import React from 'react';

import styles from './styles.css';

export default ({ }) => (
  <div className={styles['card-list']}>
    <div className='res'>
      <button>HELLO</button>
    </div>
  </div>
);

styles.css (with global workaround)

.card-list {
  &:global(:container(width >= 18em)) {
    background-color: red;
  }
}

from cq-prolyfill.

paul-sachs avatar paul-sachs commented on July 24, 2024

I think the issue with using the :global is more a problem with using react. React sets the classes according to what css modules returns as class names, which does not seem to include the :container(...) but even if it did, the cq-prolyfill contains code that adds/removes classes to/from elements, which is generally very bad form for react.

from cq-prolyfill.

ausi avatar ausi commented on July 24, 2024

You could take a look at react-container-query-container from @VinSpee how it works there. Im not very familiar with React so I don’t know if it’s bad practice to change class names outside React code.

from cq-prolyfill.

paul-sachs avatar paul-sachs commented on July 24, 2024

Yeah alright. Which sucks because I really like cq-prolyfill. Here's to hoping it becomes a standard.

from cq-prolyfill.

bradennapier avatar bradennapier commented on July 24, 2024

Why was this issue closed when it was not resolved?

from cq-prolyfill.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.