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

<dom-if> interferes with justify-content: space-between #4773

Closed
2 tasks done
andrey-git opened this issue Aug 5, 2017 · 4 comments
Closed
2 tasks done

<dom-if> interferes with justify-content: space-between #4773

andrey-git opened this issue Aug 5, 2017 · 4 comments

Comments

@andrey-git
Copy link

Description

Using <template is='dom-if'> in source code causes <dom-if> element to be put in resulting HTML (regardless of whether the condition is true or false).
If the parent element has justify-content: space-between; display: flex; then <dom-if> participates in element count for justification sake and the result looks broken.

This can be fixed by styling <dom-if> with display: none. Since this is a regression from Polymer 1.9, maybe the library can apply this automatically? I can't think of a use case where one wouldn't want display: none on the <dom-if>

Live Demo

http://jsbin.com/megukipana/1/edit?html,output

Steps to Reproduce

Example:

    <template>
      <style>
        .parent {
          border: 1px solid red;
          justify-content: space-between;
          width: 300px;
          display: flex;
        }
        .child {
          border: 1px solid green;
          width: 100px;
        }
      </style>
      <div class='parent'>
        <div class='child'>Child1</div>        
        <template is='dom-if' if='1'>
          <div class='child'>Child2</div>
        </template>
      </div>
    </template>

Expected Results

Child1 is to the left, Child2 is to the right.

Actual Results

Space to the right if Child2 caused by empty <dom-if>

Browsers Affected

  • Chrome
  • Firefox

Versions

  • Polymer: v2.0
  • webcomponents: vX.X.X
@TimvdLippe
Copy link
Contributor

The reason it regressed in Polymer 1 vs 2 is that in Polymer 2 the <template is="dom-if"> is transformed into a <dom-if>. This means that it is an actual custom element and not inert, thus it participates in the CSS styling counts. Since is= was not implemented (see the long discussion in WICG/webcomponents#509 for more information), dom-if can't take advantage of the properties of template in 2.0.

To resolve this, we could maybe force styling on dom-if to resolve this:

:host {
  display: none;
}

I am not 100% sure this will work because of CSS priorities and specificity.

@andrey-git
Copy link
Author

Setting

:host {
  display: none;
}

would be a good first step.
Probably the cases where user's CSS makes <dom-if> specifically displayed are rare.

@sorvell
Copy link
Contributor

sorvell commented Sep 2, 2017

There's also a colspan issue in tables: http://jsbin.com/tuqadit/edit?html,output.

@equinusocio
Copy link

:host dom-if {
  display: none;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants