-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
feat(tab-nav-bar): add initial functionality of tab nav bar #1589
Conversation
|
||
import {RoutedContent1, RoutedContent2, RoutedContext3} from '../tabs/tabs-demo'; | ||
|
||
export const TABS_DEMO_ROUTE: Routes = [ |
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.
TABS_DEMO_ROUTES
(plural)
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.
Done.
{ path: '', redirectTo: 'content-1', pathMatch: 'full' }, | ||
{ path: 'content-1', component: RoutedContent1 }, | ||
{ path: 'content-2', component: RoutedContent2 }, | ||
{ path: 'content-3', component: RoutedContext3 }, |
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'd use a different name for the routed content components to be super clear that they're examples and that people don't have to call their components "RoutedContentX". Popular examples are food, weather, pokemon...
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.
Done.
@@ -0,0 +1,40 @@ | |||
import { Component, Input, ViewChild, ElementRef } from '@angular/core'; | |||
import { MdInkBar } from '../ink-bar'; |
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.
No spaces inside imports (this might be a WebStorm settings)
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.
Done.
styleUrls: ['tab-nav-bar.css'], | ||
}) | ||
export class MdTabNavBar { | ||
@ViewChild(MdInkBar) private _inkBar: MdInkBar; |
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.
@ViewChild
can't be applied to a private member (since Angular itself is external to this class and has to touch 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.
Done.
export class MdTabNavBar { | ||
@ViewChild(MdInkBar) private _inkBar: MdInkBar; | ||
|
||
updateActiveLink(element: HTMLElement) { |
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.
Add function description comment
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.
Done.
import { Component, Input, ViewChild, ElementRef } from '@angular/core'; | ||
import { MdInkBar } from '../ink-bar'; | ||
|
||
@Component({ |
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.
Add class description for what this component does (since it's not one of the totally obvious ones like radio-button).
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.
Done.
$md-tab-bar-height: 48px !default; | ||
|
||
|
||
@mixin tab-label { |
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.
Add comment explaining what the mixin is for
@@ -0,0 +1,4 @@ | |||
<div class="md-tab-header"> |
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'm thinking that this should probably be a <nav>
element instead of a div.
@marcysutton Is it appropriate to always use a <nav>
element for a component that contains anchors and navigates the page, or should <nav>
only be used for major site navigation?
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.
Help me level-set: is the set of anchors visually like tabs, but without the associated tabpanels and ARIA tab semantics/keyboard behavior?
The difference between a <div>
and <nav>
is that the latter has a landmark role, making it easy for a screen reader user to discover. I think this component would be a reasonable use case for how I've seen tabs presented in the Material Design spec. Unless you anticipate so many of them on a page they dominate the landmarks list, I don't see much of a downside.
If you do end up using <nav>
, I'd recommend labeling the element with an aria-label
so it can be easily identified as a screen reader landmark.
Edit: I thought I had sent this comment days ago, but I'm still not used to the Review workflow apparently.
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.
Thanks for the input Marcy. Jeremy and I discussed this and agree that we can move this responsibility to the user by making this a component with an attribute selector.
Usage of this component will be written by the user as such:
<nav md-tab-nav-bar aria-label="navigation links"> ... </nav>
private _isActive: boolean = false; | ||
|
||
@Input() | ||
get active(): boolean { |
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 didn't know about this before, but looking through the router docs turned up this:
https://angular.io/docs/ts/latest/guide/router.html#!#router-link-active
Seems like we could rely on that to apply the appropriate class based on the route being active
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.
Adding a comment that addresses the workaround in our demo app because we lack an isActive api on routerLinks
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.
Just a few more things I noticed
{ path: '', redirectTo: 'sunny-tab', pathMatch: 'full' }, | ||
{ path: 'sunny-tab', component: SunnyTabContent }, | ||
{ path: 'rainy-tab', component: RainyTabContent }, | ||
{ path: 'foggy-tab', component: FoggyTabContent }, |
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.
Remove the leading/trailing spaces in object literals
display: block; | ||
} | ||
|
||
a[md-tab-link] { |
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'd remove the a
part of this selector just to reduce the specificity.
@@ -0,0 +1,51 @@ | |||
@import '../core/style/variables'; |
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 file should either consist of exclusively mixins or exclusively concrete styles.
If it's the former, then the file name should start with an underscore (which tells the sass compiler that it's a "partial" file that doesn't have output).
If it's the latter, it should be included in the "styleUrls" for each of the components that use it (rather than doing a sass @import
)
Thanks for the review, I made the tabs common to be purely mixins |
LGTM- nice work! |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Initial development of the tab nav bar
Closes #524