Search code examples
htmlamp-html

Issue with AMP default height values being toggled


I have an amp carousel with some hide/show content at the bottom. I am using amp-bind to dynamically hide and show some extra content as well as adjust the height value of the carousel itself so that the content can be seen.

The markup is something like this, but with a couple more slides with similar content:

<amp-carousel
   [height]="visible ? 720 : 550"
   height="550"
   width="400"
   layout="responsive"
   type="slides">
    <div class="carousel__slide">
       <p>Text content here</p>
       <button [text]="visible ? 'See Less' : 'See More'" 
           on="tap:AMP.setState({visible: !visible})">See More</button>
       <ul [class]="visible ? 'show' : 'hide'" class="hide">
          <li>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</li>
          <li>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</li>
          <li>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</li>
       </ul>
    </div>
</amp-carousel>

With that mark I get the following error:

amp-bind: Default value for [height] does not match first expression result (550). This can result in unexpected behavior after the next state change.​​​ 

I tried adding a default value for height before the carousel but that didn't seem to help

<amp-state id="props">
    <script type="application/json">
      {
        "height": "550"
      }
    </script>
  </amp-state>

I tried passing it both a number and string, with brackets and without but none of it seems to work


Solution

  • After discussing with the AMP team, they informed me that's it's actually a bug with the validation in developer mode

    Bug has been filed here: https://github.com/ampproject/amphtml/issues/12028