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

[amp-sidebar 1.0][Toolbar] Added Body Spacing for Default Toolbar #10100

Merged
merged 18 commits into from Jun 27, 2017

Conversation

torch2424
Copy link
Contributor

@torch2424 torch2424 commented Jun 22, 2017

Closes #9985

  • Creates placeholder elements to push the body down
  • Placeholder elements are recalculated on layout resize
  • Made a better (AMP Start) Test manual file for toolbar, satisfying all manual test requirements.

Please see torch2424#8
for examples

@camelburrito
Copy link
Contributor

Gave @torch2424 in-person feedback on this

@torch2424 torch2424 added this to PRs in AMP Sidebar 1.0 Jun 23, 2017
@torch2424
Copy link
Contributor Author

torch2424 commented Jun 23, 2017

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

@torch2424 torch2424 Jun 23, 2017

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>

Copy link
Contributor

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?)

Copy link
Contributor Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inherit?

Copy link
Contributor Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this deleted?

Copy link
Contributor Author

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.

Copy link
Contributor

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor

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

Copy link
Contributor Author

@torch2424 torch2424 Jun 23, 2017

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

Copy link
Contributor

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?

Copy link
Contributor Author

@torch2424 torch2424 Jun 23, 2017

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

Copy link
Contributor

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

Copy link
Contributor Author

@torch2424 torch2424 Jun 23, 2017

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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!

Copy link
Contributor Author

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.

Copy link
Contributor

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 :)

Copy link
Contributor Author

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_) {
Copy link
Contributor

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.

  1. Check if there is a compensation element , if not create one and assign the height
  2. else just assign the height
  3. When you close the toolbar this has to be hidden

Copy link
Contributor Author

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.

@camelburrito
Copy link
Contributor

Lets not combine features and manual test files in the same PR. Please split it

@torch2424 torch2424 changed the title [amp-sidebar 1.0][Toolbar] Added Body Placeholders, Styling, and an AMP Start Manual Test [amp-sidebar 1.0][Toolbar] Added Body Placeholders, Styling Jun 23, 2017
@torch2424 torch2424 changed the title [amp-sidebar 1.0][Toolbar] Added Body Placeholders, Styling [amp-sidebar 1.0][Toolbar] Added Body Placeholders Jun 23, 2017
@torch2424
Copy link
Contributor Author

torch2424 commented Jun 24, 2017

Split to: torch2424#8

@torch2424 torch2424 changed the title [amp-sidebar 1.0][Toolbar] Added Body Placeholders [amp-sidebar 1.0][Toolbar] Added Body Spacing for Default Toolbar Jun 27, 2017
@torch2424
Copy link
Contributor Author

Decided the placehodlers would disrupt the body:first-child CSS, and we would support only one default toolbar, where it would set the top attribute of the body to the height of the toolbar. Multiple toolbars will conflict with one another, and fight for the space.

@torch2424
Copy link
Contributor Author

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');
Copy link
Contributor

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;
Copy link
Contributor

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_) {
Copy link
Contributor

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.

Copy link
Contributor Author

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} */
Copy link
Contributor

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

Copy link
Contributor Author

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_, {

Copy link
Contributor Author

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

this.initialBodyTop_ = computedStyle(this.win_, this.body_)['top'];
}
state.toolbarHeight = this.toolbarClone_./*REVIEW*/offsetHeight;
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@camelburrito camelburrito merged commit 219742f into ampproject:master Jun 27, 2017
@torch2424 torch2424 deleted the sidebar-v1-placeholder branch October 26, 2018 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants