-
Notifications
You must be signed in to change notification settings - Fork 357
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(breadcrumbs) *experimental* #1183
Conversation
…style breadcrumbs
…b as the window shrinks
constructor(private _elementRef: ElementRef, private _changeDetectorRef: ChangeDetectorRef) { } | ||
|
||
ngAfterViewInit(): void { | ||
this._resizeSubscription = merge( |
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 this subscription be cleaned up on component destroy?
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.
@jotatoledo You are correct, nice catch.
|
||
ngDoCheck(): void { | ||
if (this._elementRef && this._elementRef.nativeElement) { | ||
this._widthSubject.next((<HTMLElement>this._elementRef.nativeElement).getBoundingClientRect().width); |
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 about hiding the argument of next
behind a private getter?
Something like private get nativeElementWidth(): number {}
// don't show the right chevron on the first breadcrumb | ||
breadcrumbArray[0].displayIcon = false; | ||
} | ||
breadcrumbArray.map((breadcrumb: TdBreadcrumbComponent) => { |
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.
Wouldnt a forEach
be better suited for iterating and mutating the elements in the array? considering that you arent really mapping the array elements into something new.
], | ||
imports: [ | ||
NoopAnimationsModule, | ||
RouterTestingModule.withRoutes([ |
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.
Is there any reason to use mock 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.
just so the test doesn't fail with the routherlink in there
for (let i: number = this.hiddenBreadcrumbs.length; i < crumbsArray.length; i++) { | ||
curTotCrumbWidth += crumbsArray[i].width; | ||
} | ||
let winWidth: number = this._elementRef.nativeElement.parentElement.offsetWidth - this._windowWidthPadding; |
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.
Should check the host here instead of the parent in case the component width
changes.
private _widthSubject: Subject<number> = new Subject<number>(); | ||
private _resizing: boolean = false; | ||
// Padding on the window when calculating the full size | ||
private _windowWidthPadding: number = 20; |
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.
Is this needed if we check the host width rather than the parent width?
Example with all inputs/outputs: | ||
|
||
```html | ||
<div layout-gt-sm="row" tdMediaToggle="gt-xs" [mediaClasses]="['push-sm']"> |
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.
Lets remove this div and just keep the example with the component usage.
|
||
#### Methods | ||
|
||
+ displayIcon: function(): 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.
Not sure if we state that these properties are public. Since we use them internally to change the state of it.. which we should probably add a _
as a prefix, since that is the standard for internal
properties.
*/ | ||
private setStyles(): void { | ||
let breadcrumbArray: TdBreadcrumbComponent[] = this._breadcrumbs.toArray(); | ||
if (breadcrumbArray && breadcrumbArray.length > 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.
Im almost sure that there is no need to check the existence of breadcrumbArray
.
The not empty conditional could be shortened to if(breadcrumbArray.length)
} | ||
|
||
ngOnDestroy(): void { | ||
if (this._resizeSubscription) { |
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.
Avoid the truthy check by declaring the sub variable with the initial value of Subscription.EMPTY
;
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.
Huh, i didnt know about that.
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.
👍
Showcase get/set methods as properties since thats how they are used
Just noticed that the icon is also clickable.. wonder if that will cause issues 🤔 |
this is done because the navigation or event shouldnt be triggered in that scenario
|
* feat(breadcrumbs): Initial scaffolding for breadcrumbs * feat(breadcrumbs): Checkpoint checkin with breadcrumbs showing up * feat(breadcrumbs): code cleanup and adding graying out to last element * feat(breadcrumbs): Adding themes to experimental area. Using scss to style breadcrumbs * add to demo * feat(breadcrumbs): Responsive Breadcrumbs, removes the left-most crumb as the window shrinks * Adding sandbox area with routes to test-beds * Using ngAfterContentChecked lifecycle method * Adding title to demo * Update documentation Readme with usage * Moving tab-select into separate demo directory * Unit Tests for Breadcrumbs * Unit Tests for Breadcrumbs * chore(breadcrumbs): Update code from code review * fix(breadcrumb): Fix unit test * chore(breadcrumbs): Use Subscription.EMPTY to avoid needing null checks * chore(breadcrumbs): remove console.log * chore(): updates on README Showcase get/set methods as properties since thats how they are used * chore(breadcrumbs): remove media usage from breadcrumbs to reduce noise * fix(breadcrumbs): stop click event on the breadcrumb separator this is done because the navigation or event shouldnt be triggered in that scenario
Description
First pass on breadcrumbs component and will be treated as experimental while we use it in multiple products to ensure quality.
closes #1053
Usage:
What's included?
Test Steps
npm run serve:test-bed
General Tests for Every PR
npm run serve:prod
still works.npm run tslint
passes.npm run stylelint
passes.npm test
passes and code coverage is not lower.npm run build:lib
still works.Screenshots or link to StackBlitz/Plunker
closes #1053