Can't style element in shadow dom in media query

后端 未结 1 1307
终归单人心
终归单人心 2021-01-21 17:03

In my styles/app-theme.html I am trying to change the menu icon size of paper-drawer-panel in the media query. This element is in index.html. Since it

相关标签:
1条回答
  • 2021-01-21 17:51

    Polymer currently uses a shim (a partial polyfill) to evaluate custom properties. As such, they aren't automatically recalculated. What you can do, however, is use iron-media-query (or directly use matchMedia) to know when to call updateStyles on the element(s) that need updating.

    Here's an example of using updateStyles:

    Polymer({
    
        is: 'seed-element',
    
        properties: {
          largeScreen: {
            type: Boolean,
            observer: '_largeScreenChanged'
          }
        },
        
        _largeScreenChanged: function(newValue) {
          this.updateStyles({
            '--h1-color': (newValue ? 'red' : 'blue')
          });
        }
      });
    <dom-module id="seed-element">
      <template>
        <style>
          h1 {
            color: var(--h1-color, red);
          }
        </style>
        
        <h1>header</h1>
        
        <iron-media-query query="(max-width: 600px)" query-matches="{{largeScreen}}"></iron-media-query>
      </template>
    
    </dom-module>
    
    <seed-element id="topmenu"></seed-element>

    0 讨论(0)
提交回复
热议问题