Skip to content

Commit

Permalink
feat(navigator): add EventEmitter to selected item
Browse files Browse the repository at this point in the history
  • Loading branch information
hai-ji committed Aug 10, 2022
1 parent 4c652a8 commit 537697c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions libs/markdown-navigator/README.md
Expand Up @@ -26,6 +26,8 @@ A component for rendering and navigating through markdown, such as documentation

- buttonClicked: ITdFlavoredMarkdownButtonClickEvent
- Emitted when a button is clicked
- itemSelected: IMarkdownNavigatorItem
- Emitted the selected item when a item is selected

For reference:

Expand Down Expand Up @@ -117,6 +119,8 @@ A component that contains a MarkdownNavigator component and a toolbar
- Event emitted when the close button is clicked.
- buttonClicked: ITdFlavoredMarkdownButtonClickEvent
- Emitted when a button is clicked
- itemSelected: IMarkdownNavigatorItem
- Emitted the selected item when a item is selected

## Setup

Expand Down
Expand Up @@ -17,5 +17,6 @@
[copyCodeToClipboard]="copyCodeToClipboard"
[copyCodeTooltips]="copyCodeTooltips"
(buttonClicked)="buttonClicked.emit($event)"
(itemSelected)="itemSelected.emit($event)"
></td-markdown-navigator>
</td-window-dialog>
Expand Up @@ -51,6 +51,8 @@ export class TdMarkdownNavigatorWindowComponent {
@Output() dockToggled: EventEmitter<boolean> = new EventEmitter();
@Output() buttonClicked: EventEmitter<ITdFlavoredMarkdownButtonClickEvent> =
new EventEmitter();
@Output() itemSelected: EventEmitter<IMarkdownNavigatorItem> =
new EventEmitter();

get markdownNavigatorLabels(): IMarkdownNavigatorLabels | undefined {
if (!this.labels) {
Expand Down
17 changes: 13 additions & 4 deletions libs/markdown-navigator/src/markdown-navigator.component.ts
Expand Up @@ -116,6 +116,8 @@ export class TdMarkdownNavigatorComponent implements OnChanges {

@Output() buttonClicked: EventEmitter<ITdFlavoredMarkdownButtonClickEvent> =
new EventEmitter();
@Output() itemSelected: EventEmitter<IMarkdownNavigatorItem> =
new EventEmitter();

@ViewChild('markdownWrapper') markdownWrapper!: ElementRef;

Expand Down Expand Up @@ -273,6 +275,7 @@ export class TdMarkdownNavigatorComponent implements OnChanges {
this.currentMarkdownItem = undefined;
}
this.historyStack = [];
this.itemSelected.emit(undefined);
this._changeDetectorRef.markForCheck();
}

Expand All @@ -299,6 +302,7 @@ export class TdMarkdownNavigatorComponent implements OnChanges {
} else {
this.reset();
}
this.itemSelected.emit(parent);
this._changeDetectorRef.markForCheck();
}

Expand All @@ -307,6 +311,7 @@ export class TdMarkdownNavigatorComponent implements OnChanges {
this.currentMarkdownItem = item;
this.historyStack = [...this.historyStack, item];
this.setChildrenAsCurrentMenuItems(item);
this.itemSelected.emit(item);
this._changeDetectorRef.markForCheck();
}

Expand Down Expand Up @@ -403,8 +408,10 @@ export class TdMarkdownNavigatorComponent implements OnChanges {
path = this.findPath(this.items, itemOrPath);
}
path.forEach((pathItem: IMarkdownNavigatorItem, index) => {
if (index === 0) { this.reset() }

if (index === 0) {
this.reset();
}

this.handleItemSelected(pathItem);
});
}
Expand Down Expand Up @@ -471,12 +478,14 @@ export class TdMarkdownNavigatorComponent implements OnChanges {
const link: HTMLAnchorElement = <HTMLAnchorElement>event.target;
const url: URL = new URL(link.href);
const urlParts = url.href.split('/');
const id = urlParts[urlParts.length-1].split('.md')[0];
const id = urlParts[urlParts.length - 1].split('.md')[0];
this.loading = true;
this._changeDetectorRef.markForCheck();
const pathFound = await this._jumpTo({ id });

if (pathFound) { return; }
if (pathFound) {
return;
}

try {
const markdownString: string = await this._markdownUrlLoaderService.load(
Expand Down

0 comments on commit 537697c

Please sign in to comment.