amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

amp-list is not aware of content height change due to amp-bind

Open zhangsu opened this issue 9 years ago • 12 comments

What's the issue?

If the height of the content of amp-list changes due to a binding evaluation, the height of the amp-list isn't updated automatically, nor is the overflow element displayed.

How do we reproduce the issue?

amp-list at the bottom of the page

1. html <button on="tap:AMP.setState({comments: [{item: 'Hello'}, {item: 'world'}]})"> Set state </button> <amp-list width="auto" height="50" layout="fixed-height" credentials="include" [state]="comments" src="https://example.com"> <template type="amp-mustache"> <div on="tap:{{item}}-hidden.toggleVisibility">{{item}}</div> <div class="hidden" hidden id="{{item}}-hidden"><br><br>Hidden!!!!<br><br></div> </template> </amp-list> 2. Click on "Set state" to populate the list. 3. Click on "Hello" to make the hidden div inside the amp-list template visible. 4. amp-list content is now overflown, but the height isn't increased automatically.

amp-list not at the bottom of the page

1. html <amp-list width="auto" height="50" layout="fixed-height" credentials="include" [state]="comments" src="https://example.com"> <template type="amp-mustache"> <div on="tap:{{item}}-hidden.toggleVisibility">{{item}}</div> <div class="hidden" hidden id="{{item}}-hidden"><br><br>Hidden!!!!<br><br></div> </template> <div overflow>See more</div> </amp-list> <button on="tap:AMP.setState({comments: [{item: 'Hello'}, {item: 'world'}]})"> Set state </button> 2. Click on "Set state" to populate the list. 3. Click on "Hello" to make the hidden div inside the amp-list template visible. 4. amp-list content is now overflown, but the the overflow element isn't displayed.

What browsers are affected?

Chrome tested.

Which AMP version is affected?

1504119607313

zhangsu avatar Sep 09 '17 20:09 zhangsu

/to @choumx

aghassemi avatar Sep 11 '17 15:09 aghassemi

This issue hasn't been updated in awhile. @choumx Do you have any updates?

ampprojectbot avatar Dec 11 '17 21:12 ampprojectbot

Try this. @zhangsu

  1. change your layout from "fixed-height" to "fill", remove all your width and height. Then add the below code into your css

.i-amphtml-fill-content{ position: static; height: auto; } .i-amphtml-layout-fill,.YOUR-AMP-CLASS [layout=fill]:not(.i-amphtml-layout-fill){ position: static; }

leonahliang90 avatar Dec 31 '17 07:12 leonahliang90

@leonalicious not sure if you can add the above css, I tried your approach and I got AMP validation error:

The text (CDATA) inside tag 'style amp-custom' contains 'CSS i-amphtml- name prefix', which is disallowed

kul3r4 avatar Jan 02 '18 10:01 kul3r4

then you need to play around with css selector, by using CSS ID Selector , such as

#amp-list-id .i-amphtml-fill-content

hope it helps.

leonahliang90 avatar Jan 06 '18 06:01 leonahliang90

In general the usage of internal amp css classes (like -amphtml-fill-content) for custom style is not possible and will result into an error.(doc here)

I played a bit with layout fill and it's not clear to me how this could work. layout fill doesn't need an height and width but uses the one of the parent. If you just use it the amp-list, which automatically comes with position = absolute, will be stuck on top of the page. So then you suggested to add position: static; in the css, but that interferes with amp-list somehow, in fact when I used it the amp-list was not rendering any data.

kul3r4 avatar Jan 08 '18 12:01 kul3r4

@kul3r4 What you said is completely true. Did you find any way to sort it out?

vamshi5889 avatar Feb 01 '18 16:02 vamshi5889

@vamshi5889 I haven't yet found a solution.

kul3r4 avatar Feb 01 '18 18:02 kul3r4

@kul3r4 I got the solution for my requirement.

My requirement was toggling the menu item between "Sign In" and "My Account" (accordion with options) based on user authentication. To achieve this i'm using amp-list and showing "Sign In" and "My Account" dropdown based on authentication.

If user logged in, i'm toggling the list menu with AMP bind variable.

vamshi5889 avatar Feb 02 '18 11:02 vamshi5889

@kul3r4 And for auto height thing, below is my suggestion

Use amp state with id and src attribute and fetch your list (assuming response is JSON with html inside).

Ex JSON: {"data": "

Hello
"}

Now you just put the content in plain html div by calling id.data

vamshi5889 avatar Feb 02 '18 12:02 vamshi5889

This is a dupe of #10230.

dreamofabear avatar Mar 02 '18 20:03 dreamofabear

Closing as dupe.

dreamofabear avatar Mar 27 '18 19:03 dreamofabear