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

feat(breadcrumbs) *experimental* #1183

Merged
merged 23 commits into from
Jul 13, 2018
Merged

feat(breadcrumbs) *experimental* #1183

merged 23 commits into from
Jul 13, 2018

Conversation

jeremysmartt
Copy link
Collaborator

@jeremysmartt jeremysmartt commented Jun 20, 2018

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:

<td-breadcrumbs #breadcrumbs class="pad-left" separatorIcon="motorcycle">
    <a td-breadcrumb [routerLink]="'/'">Home</a>
    <a td-breadcrumb [routerLink]="'/layouts'">Layouts</a>
    <a td-breadcrumb [routerLink]="'/layouts2'">Layouts2</a>
    <a td-breadcrumb [routerLink]="'/layouts3'">Layouts3</a>
    <td-breadcrumb class="tc-grey-500">Manage List</td-breadcrumb>
</td-breadcrumbs>

What's included?

  • README.md
  • CovalentBreadcrumbsModule with TdBreadcrumbsComponent and TdBreadcrumbComponent
  • Usage on test bed
  • Added in experimental

Test Steps

  • npm run serve:test-bed
  • go to http://localhost:4200/
  • click on breadcrumbs link
  • See it working
  • Resize width of window to be smaller than width of breadcrumbs
  • See first breadcrumbs disappear for responsive
  • See hidden breadcrumbs count increase
  • See individual hidden breadcrumb width info

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

breadcrumbs-demo

closes #1053

@jeremysmartt jeremysmartt changed the title feat(breadcrumbs): Initial scaffolding for breadcrumbs feat(breadcrumbs) Jun 20, 2018
@jeremysmartt jeremysmartt changed the title feat(breadcrumbs) feat(breadcrumbs) *experimental* Jul 10, 2018
constructor(private _elementRef: ElementRef, private _changeDetectorRef: ChangeDetectorRef) { }

ngAfterViewInit(): void {
this._resizeSubscription = merge(
Copy link
Contributor

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?

Copy link
Collaborator Author

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

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

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

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?

Copy link
Collaborator Author

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

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

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']">
Copy link
Contributor

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

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

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

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;

Copy link
Contributor

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

@emoralesb05
Copy link
Contributor

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
@emoralesb05
Copy link
Contributor

  • pushed changed to make sure clicking on the icon doesnt trigger navigation

@emoralesb05 emoralesb05 merged commit 256491e into develop Jul 13, 2018
@emoralesb05 emoralesb05 deleted the feature/breadcrumbs branch July 13, 2018 20:27
kriswinbush pushed a commit to kriswinbush/covalent that referenced this pull request Feb 20, 2020
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Breadcrumbs
3 participants