Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

feat(subheader): add subheader component #269

Closed
wants to merge 2 commits into from
Closed

Conversation

rschmukler
Copy link
Contributor

This implements #216.

As per suggestion from @matsko, uses native position: sticky when possible, otherwise uses a javascript implementation using the new $materialSticky service.

A new directive material-sticky is also exposed, which uses the $materialSticky service.

This pull request also makes the material-subheader create a h2 for accessibility purposes as per @marcysutton's suggestion. Subsequently, it ups the h2 and h3 in material-list-item to h3 and h4 respectively.

Commit messages have been squashed

Would love suggestions from @ajoslin on ideas for testing $materialSticky service, or anyone else who has ideas.

Also does anyone have opinion on whether we want to document material-sticky directive / $materialSticky service for usage on the docs?

var next; // pointer to next target

// Convenience getter for the target element
var targetElementIndex = $container.data('$stickyTarget'),
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems we're getting to the point where it would be better to just have one element.data('$sticky') object that contains .target, .orderedEls, etc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool with me

Copy link
Contributor

Choose a reason for hiding this comment

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

Also if you do that, you could just have one stickyData var at the top, so you don't have to keep calling $container.data('$sticky'). Cleaner & easier.

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 depends on checkElements existing for each sticky container. I'd rather keep the memory footprint smaller by using the $container.data -- if you're opinionated on it, I'm happy to change it, just my initial thoughts.

@ajoslin
Copy link
Contributor

ajoslin commented Sep 15, 2014

This looks good overall!

The main problem I see is that you're using css top to push elements. This is a problem because changing CSS top isn't GPU accelerated and will look really slow when doing it every frame on iOS & older android devices.

Just use transform: 'translate3d(0, ' + yValue + 'px, 0)' for setting the top, and cache an element's current translate3d value separately (reading translate from .css isn't possible, and reading it from getComputedStyle() is troublesome).

incrementElement();
}
//If we are going up, and our normal position would be rendered not sticky, un-sticky ourselves
else if(!scrollingDown && stickyActive && targetRect.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.

Coding convention: we always put the brace on the same line as the else if.

Just add a blank line if you want to space things out.

@ajoslin
Copy link
Contributor

ajoslin commented Sep 15, 2014

Regarding documentation: I would say don't bother doing that yet. We can just document material-subheader for now.



$el.attr({
'role' : $attr.role || Constant.ARIA.ROLE.HEADING
Copy link
Contributor

Choose a reason for hiding this comment

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

This is actually unnecessary because there is a heading element nested inside of it. Good intention, though!

@marcysutton
Copy link
Contributor

👍 for making the heading sticky without having to modify the DOM.

$el = Util.wrap($el, 'div', 'sticky-container'),
$container = $el.controller('materialContent').$element;

if(!$container) { throw new Error('$materialSticky used outside of material-contant'); }
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to check for presence of $el.controller('materialContent'), too.

@@ -29,6 +29,28 @@ var Util = {
},

/**
* Returns a function, that, as long as it continues to be invoked, will not
Copy link
Contributor

Choose a reason for hiding this comment

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

Util.debounce already exists in master, once you rebase.

// If we are scrollingDown, sticky, and are being pushed off screen by a different element, increment
if(scrollingDown && stickyActive && contentRect.bottom <= 0 && targetElementIndex < orderedElements.length - 1) {
targetElement().children(0).removeAttr('material-sticky-active');
targetElement().css({height: null});
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you use the object notation when you're only setting one property?

The object notation requires allocating a new object here, then looping through it internally.

It may seem inconsequential, but I'd rather save where we can if it's easy to save.

@ajoslin
Copy link
Contributor

ajoslin commented Sep 23, 2014

We've talked, and I know you can handle me being picky about little details. So I'm being really picky about little details...a little too much probably.

The things that matter the most are translateY and $sticky initialization.

@rschmukler
Copy link
Contributor Author

Just a note, we should review this with the UX team -- Android has issues with scroll / rAF events firing after hardware accelerated scrolling redraws the screen. This makes some jank. @ajoslin

@rschmukler rschmukler closed this in 7787c9c Oct 4, 2014
@ajoslin ajoslin deleted the wip-sub-header branch October 17, 2014 23:28
@Splaktar Splaktar added the pr: merge ready This PR is ready for a caretaker to review label Aug 9, 2018
@angular angular locked as resolved and limited conversation to collaborators Aug 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr: merge ready This PR is ready for a caretaker to review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants