components icon indicating copy to clipboard operation
components copied to clipboard

bottom-nav component

Open jelbourn opened this issue 10 years ago • 55 comments

See https://material.io/design/components/bottom-navigation.html

jelbourn avatar May 09 '16 16:05 jelbourn

Thanks for opening this up @jelbourn. I plan on implementing and have already begun some of the coding. I'm also working on writing up a design doc as you pointed out. There's several more things I need to think about that will hopefully come out in the design document but here's my initial thoughts.

I've been looking at an android/java implementation to learn from that: https://github.com/roughike/BottomBar

So far I've thought about providing a declarative approach such as

<md-bottomnav>
    <md-bottomnav-item>
    </md-bottomnav-item>
</md-bottomnav>

and a programatic approach that consumes an array

<md-bottomnav [items]="items">

The spec mentions that the component can be used for bottom navigation but it doesn't mention anything about its behavior automatically positioning itself to the bottom. I'm not sure if it's more in the spirit that using this component should automatically fix it to the bottom of its containing element, if it shouldn't be concerned with overall layout whatsoever (leaving that up to the consumer of the component), or if it should be a container component that takes up the full height of the view and has a projection area.

mikekhaas avatar May 09 '16 18:05 mikekhaas

@mikehaas763

For the API, the first approach is preferable. When you want to include items programmatically, you would use ngFor on the item.

The bottom-nav should behave like the toolbar in WRT to the user being able to decide where to place it.

jelbourn avatar May 09 '16 18:05 jelbourn

Agree with @jelbourn. Also, can we make it md-bottom-nav rather than md-bottomnav? Will be easier to read.

kara avatar May 09 '16 18:05 kara

@jelbourn makes sense, was thinking the same thing about ngFor but wasn't sure what would be more preferable.

@kara I agree. My thinking was that I wasn't sure if it should be consistent with sidenav. However, I think of sidenav as one word but with bottom not so much.

mikekhaas avatar May 09 '16 18:05 mikekhaas

WIP design document (not very far yet): https://docs.google.com/document/d/1h3fQaEaWYKv9GISAYitKSjbPvgNBB4_veIo2hOAquOE/edit?usp=sharing

mikekhaas avatar May 10 '16 01:05 mikekhaas

Thinking about the API a bit more while working on the design doc, the main piece of the component from a UI perspective is the set of icons. So I have to think about how to use MD icons and could use some feedback.

A few ideas:

  • Mimic some of the functionality that's in MdIcon in the MdBottomNavItem component (perhaps extracting pieces into services). This would mean create the same @Input()s, inject MdIconRegistry, etc.
  • Compose MdIcon within MdBottomNavItem and delegate to it
  • Subtype MdIcon with MdBottomNavItem. I haven't test this yet with A2 components and am not sure how well it works or if there are any edge cases related to decorators or other constructs.

Although I'm generally in the composition over inheritance camp as most people are, I think this may be a good use case for it. The nav items are essentially just icons. The only differences I know of being added on in the subtype right now are:

  1. optionally displaying a text label underneath
  2. communicating with the host element to have the ink effect that's specified in the spec starting at the location of the clicked icon

Thoughts?

mikekhaas avatar May 12 '16 02:05 mikekhaas

@mikehaas763 The content of the bottom-nav items should be completely up to the user. People will most likely put an <md-icon> in there, but the component itself should have no dependency on it.

It should be something like

<md-bottom-nav>
  <a md-nav-item ...> <md-icon>home</md-icon> </a>
  ...
</md-bottom-nav>

jelbourn avatar May 12 '16 02:05 jelbourn

@jelbourn I took this statement from the spec too literally: "Because bottom navigation actions are presented as icons, they should be used for content that can be suitably communicated with icons".

Meaning I thought it was a restriction material2 would want to match. That makes it a lot easier though so I'll just make that a projection area.

mikekhaas avatar May 12 '16 03:05 mikekhaas

@jelbourn Do you agree that the component should provide default styling so that if something like the following is used then it will look as it would in the spec?

<a md-nav-item>
  <md-icon>home</md-icon>
  <span>Home</span>
</a>

mikekhaas avatar May 12 '16 20:05 mikekhaas

@mikehaas763 yes, but it should be via an explicit attribute rather than looking for something like span. See md-card for examples of what I mean.

jelbourn avatar May 12 '16 21:05 jelbourn

update: I'm doing some prototyping to help flush out some design considerations I'm not sure of yet at mikehaas763/material2 in my bottomnav branch. https://github.com/angular/material2/compare/master...mikehaas763:bottomnav

mikekhaas avatar May 18 '16 01:05 mikekhaas

Forgive my ignorance, but I use a tabs for this exact same functionality... I use CSS to flip the views and you could do the same to hide the indicator. Looking at the design spec's it seems you could use the same code for both components instead of creating something totally different and having to maintain two implementations .

Here is an example of a simply flipped tabs component: http://plnkr.co/edit/hyacHu?p=preview

Tabs & Bottom Nav: Text or icons, full width, truncation, ripples, Tabs: Indicator, scrollable Bottom Nav: On the bottom If you don't want the wrapped views you don't have to use the md-tabs-content directive

I'm just thinking adding a few attributes or css classes would be better than a whole new component..

DennisSmolek avatar May 28 '16 22:05 DennisSmolek

I see the bottom nav as being different from tabs in a few ways:

  • It same a slightly different visual presentation
  • It is only for navigation (essentially a <nav> containing <a> elements)
  • It is not paginated (which tabs will be eventually)

jelbourn avatar May 31 '16 18:05 jelbourn

Right, but with so much being the same I was curious why have two codebases. Tabs can be paginated, they don't have to be, especially because bottom navs are recommended to be no more than 4.

The biggest thing I get is semantically you wouldn't have it be "Tabs" as even though the code is identical the use case is different which I get..

DennisSmolek avatar May 31 '16 18:05 DennisSmolek

Hi! Looking in the design doc, you forgot to include that in tablets and desktops this should be displayed aside, to the left.

btw. I agree this may share some code with tabs, but it would easier to understand if you separate concerns.

michaeljota avatar Sep 24 '16 03:09 michaeljota

@michaeljota just for clarity purposes, my understanding of the spec is different.

Larger displays, like desktop, may achieve a similar effect by using side navigation.

This says to me that a consuming application can optionally choose to use a side nav on bigger displays, but not that the component itself should concern itself with resizing and snapping itself to a side nav.

If it were a valid use case in the future to have a component that did have knowledge to dynamically use a side nav or bottom nav based on screen size, then I'd think that should be a new component that wraps each respectively. Eg. AutoNavigationMenu etc :)

In any case, I'm starting small anyway and can add more features as time goes on.

mikekhaas avatar Sep 28 '16 01:09 mikekhaas

Yeah, I see your point. I'm spanish speaker, in spanish may and can are the same, and we almost take them as should, so that's on me.

But you are right, that may it's saying it is optional. This component should not care about being in a large screen or whatever. :)

michaeljota avatar Sep 28 '16 01:09 michaeljota

Does the library already have any utility styling for reseting hyperlinks to essentially no styling? I have to do something similar with this component's default styling.

image

mikekhaas avatar Oct 22 '16 18:10 mikekhaas

Hey all. Have created a bottom-nav for a project I'm working on. The current implementation I have is as follows and programatic. Ideally looking to contribute to the design doc and implenetation since I'm already using material2 for the project. Let me know what you think.

<bottom-nav [tabs]="navBarTabs"></bottom-nav>

With an interface for the tabs:

export interface NavTab {
  title: string;
  icon: string;
  link: string;
}

@Component({
  selector: 'bottom-nav',
  templateUrl: './bottom-nav.ng.html',
  styleUrls: ['./bottom-nav.scss']
})
export class BottomNavComponent {
  @Input() tabs: NavTab[];
}

Picture for reference: screenshot 2017-06-13 at 11 40 49 am

pyle avatar Jun 13 '17 15:06 pyle

@pyle revisiting this, my current thinking is that the bottom-nav should have the same API as the tab-nav-bar:

<nav md-bottom-nav>
  <a md-bottom-nav-item routerLink="troubleshoot"> ... </a>
  <a md-bottom-nav-item routerLink="status"> ... </a>
  <a md-bottom-nav-item routerLink="faq"> ... </a>
</nav>

jelbourn avatar Jun 13 '17 15:06 jelbourn