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
[amp-sidebar 1.0][Toolbar] Added Body Spacing for Default Toolbar #10100
[amp-sidebar 1.0][Toolbar] Added Body Spacing for Default Toolbar #10100
Conversation
Gave @torch2424 in-person feedback on this |
Please note in my latest changes, I created a new attribute called toolbar-container for when we are creating the container/target for the toolbar. This will allow our users to target the toolbar independently with CSS. I was unable to create the new preety view for toolbar without this. And it would be required for #10126 , in order to apply styles (such as position:fixed) to only our generated containers. |
} | ||
|
||
.i-amphtml-toolbar > ul { | ||
.i-amphtml-toolbar > ul:first-child { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldnt toolbar only have one nav element inside of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i-amphtml-toolbar
is the class applied to the <nav toolbar>
element. I noticed when implementing the sidebarOnly amp start, that these styles we being applied to the ul within the amp-accordian. So I ensured that this was the first child, as <nav toolbar> may only contain one direct child of <ul>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way you should ensure it is .i-amphtml-toolbar > :not(ul:first-child)
right (or somecss that works?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would target the elements that are not the first child of our <nav toolbar> .
Oh wait I was incorrect: https://developer.mozilla.org/en-US/docs/Web/CSS/Child_selectors
It may have been a mistmatch in classes from the AMP start heme, I'll play with it and see what happens
@@ -53,10 +53,10 @@ | |||
z-index: 2147483646; | |||
width: 100%; | |||
position: fixed; | |||
top: 0; | |||
background-color: white; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inherit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we can do that!
@@ -53,10 +53,10 @@ | |||
z-index: 2147483646; | |||
width: 100%; | |||
position: fixed; | |||
top: 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
top: 0 breaks the place holder, and doesn't keep it within it's container. Therefore the multiple toolbars will over lap if they all have the same top value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is fine , it is up to the developer to adjust this , but by default it should be 0.
@@ -110,6 +110,7 @@ export class AmpSidebar extends AMP.BaseElement { | |||
const toolbarElements = | |||
Array.prototype.slice | |||
.call(this.element.querySelectorAll('nav[toolbar]'), 0); | |||
toolbarElements.reverse(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should not do any DOM re-ordering
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not re-ording the dom. I am reversing the elements within the array itself. I am doing this because then the toolbars would be added to the DOM in reverse order.
I can either do this, or traverse backward with a for(var i = toolbarElements.length) ... loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would it be added in the reverse order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we are adding each element as the first child of the body.
So if we have toolbars in our html as:
<body>
first
second
third
...
<body>
The loop goes as follows when sidebar is applied:
Iteration 1
<body>
first
...
<body>
Iteration 2
<body>
second
first
...
<body>
Iteration 3
<body>
third
second
first
...
<body>
Reversing the array does this in the correct order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should not add it as the first child , you will need to add it as the last child so that you dont break existing css. The order of insertion of toolbars should not matter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do not add the element as the first child than the placeholder solution will not work.
The alternative in that case would to be to add border-top to the body. In that case we would have to maintain the top:
styling of all our toolbars, as well as getting all of our toolbars to play nicely with one another, or having sidebar manage each toolbar's height to calculate top accordingly. Also, in this case, performing #9983 would be much more difficult.
Could you share on what type of existing css would be broken by this method? The only case I could think of is body:first-child
@@ -47,6 +50,9 @@ export class Toolbar { | |||
/** @private {Element|undefined} */ | |||
this.targetElement_ = undefined; | |||
|
|||
/** @private {Element|undefined} */ | |||
this.placeholder_ = undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is a placeholder here ? there is already a set definition for a placeholder in amp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's talk offline about this as I cannot find it.
and this placehodler is used for the elements that will reserve height for our toolbar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that is super cool. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the placeholder, but it does not remove the need for keeping a reference to the placeholder. Since we are resizing it's height as needed.
However, with accordance to your other comment about adding and removing the placeholder dynamically on attemptShow(), this would make sense to move since we would be creating it there, and not in the toolbar build callback. I'll remove this if we decide to go that route instead of hiding the parent container we create.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok lets discuss on Monday, also don't call it placeholder :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good 👍
I'll rename as I totally forgot to add the placeholder attribute anyways
|
||
// Use the placeholder to fill the height of the toolbar | ||
this.vsync_.mutate(() => { | ||
if (this.placeholder_) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be done in attempt show , you dont want to display the compensatingElement when toolbar is hidden.
- Check if there is a compensation element , if not create one and assign the height
- else just assign the height
- When you close the toolbar this has to be hidden
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compensating element is within our container that receives display: none; So it would not be shown.
But I can throw this into attempt show before the return.
Lets not combine features and manual test files in the same PR. Please split it |
Split to: torch2424#8 |
Decided the placehodlers would disrupt the |
The build currently isn't passing, but it appears to be an issue with autosuggest, and not the sidebar component. This is ready for review/merge if able. |
|
||
// Calculate our body top before returning the fragment | ||
this.bodyTop_ = | ||
this.win_.getComputedStyle(this.body_, null).getPropertyValue('top'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the dom.js function
// Make room for the toolbar | ||
this.vsync_.mutate(() => { | ||
if (this.body_) { | ||
const toolbarHeight = this.toolbarClone_./*REVIEW*/offsetHeight; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in measure?
@@ -157,6 +183,15 @@ export class Toolbar { | |||
toggle(element, true); | |||
}); | |||
} | |||
|
|||
// Remove room for our toolbar | |||
if (this.body_) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should not have to check if body exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check-types linter wont pass without this
@@ -32,6 +35,12 @@ export class Toolbar { | |||
/** @private {!Object} **/ | |||
this.win_ = win; | |||
|
|||
/** @private {Element|null} */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop the null here and the linter would pass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you drop the null here you get:
found : (Element|null)
required: Element
setStyles(this.body_, {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error in the linter: ERROR - actual parameter 1 of module$src$style.setStyles does not match formal parameter
e161be4
to
a1454f6
Compare
this.initialBodyTop_ = computedStyle(this.win_, this.body_)['top']; | ||
} | ||
state.toolbarHeight = this.toolbarClone_./*REVIEW*/offsetHeight; | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
Closes #9985
Please see torch2424#8
for examples