Skip to content

Commit

Permalink
fix: Remove circular dep between checkbox and list component (#3519)
Browse files Browse the repository at this point in the history
  • Loading branch information
JKMarkowski committed Oct 1, 2020
1 parent 0bad0b9 commit b913ddb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions libs/core/src/lib/checkbox/checkbox/checkbox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ElementRef,
forwardRef,
HostBinding,
Inject,
Input,
Optional,
ViewChild,
Expand All @@ -14,8 +15,8 @@ import {
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { FdCheckboxValues } from './fd-checkbox-values.interface';
import { compareObjects, KeyUtil } from '../../utils/public_api';
import { ListItemComponent } from '../../list/list-item/list-item.component';
import { Platform } from '@angular/cdk/platform';
import { LIST_ITEM_COMPONENT, ListItemInterface } from '../../list/list-item/list-item-utils';

let checkboxUniqueId = 0;

Expand Down Expand Up @@ -128,7 +129,7 @@ export class CheckboxComponent implements ControlValueAccessor {
@Attribute('tabIndexValue') public tabIndexValue: number = 0,
private _platform: Platform,
private _changeDetectorRef: ChangeDetectorRef,
@Optional() private _listItemComponent: ListItemComponent
@Optional() @Inject(LIST_ITEM_COMPONENT) private _listItemComponent: ListItemInterface
) {
this.tabIndexValue = tabIndexValue;
}
Expand Down
7 changes: 7 additions & 0 deletions libs/core/src/lib/list/list-item/list-item-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { InjectionToken } from '@angular/core';

export const LIST_ITEM_COMPONENT = new InjectionToken<string[]>('ListItemComponent');

export interface ListItemInterface {
selected: boolean;
}
5 changes: 4 additions & 1 deletion libs/core/src/lib/list/list-item/list-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ContentChildren,
ElementRef,
EventEmitter,
forwardRef,
HostBinding,
HostListener,
Input,
Expand All @@ -22,6 +23,7 @@ import { Subject } from 'rxjs';
import { startWith, takeUntil } from 'rxjs/operators';
import { KeyboardSupportItemInterface } from '../../utils/interfaces/keyboard-support-item.interface';
import { KeyUtil } from '../../utils/functions/key-util';
import { LIST_ITEM_COMPONENT, ListItemInterface } from './list-item-utils';

/**
* The component that represents a list item.
Expand All @@ -35,10 +37,11 @@ import { KeyUtil } from '../../utils/functions/key-util';
class: 'fd-list__item',
role: 'listitem'
},
providers: [{ provide: LIST_ITEM_COMPONENT, useExisting: forwardRef(() => ListItemComponent) }],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None
})
export class ListItemComponent implements KeyboardSupportItemInterface, AfterContentInit, OnDestroy {
export class ListItemComponent implements KeyboardSupportItemInterface, AfterContentInit, OnDestroy, ListItemInterface {
/** Whether list item is selected */
@Input()
@HostBinding('attr.aria-selected')
Expand Down
1 change: 1 addition & 0 deletions libs/core/src/lib/list/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './list.module';
export * from './list-item/list-item.component';
export * from './list-item/list-item-utils';
export * from './list-message.directive';
export * from './directives/list-footer.directive';
export * from './directives/list-group-header.directive';
Expand Down

0 comments on commit b913ddb

Please sign in to comment.