Skip to content

Commit

Permalink
feat: introduce disabled token and fix disabled multi input (#1205)
Browse files Browse the repository at this point in the history
* #1204 fix disabled multi input and introduce disabled token

* #1204 remove unused import
  • Loading branch information
droshev authored Sep 2, 2019
1 parent 9b9ccf5 commit fc35e9c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@
[(ngModel)]="selected"></fd-multi-input>

Selected: [{{selected.toLocaleString()}}]
<br />
<label fd-label for="disabledMultiInput1">Disabled Multi Input</label>
<fd-multi-input [dropdownValues]="['Apple', 'Banana', 'Pineapple', 'Tomato']"
[placeholder]="'Search here...'"
[disabled]="true"
id="disabledMultiInput1"
[(ngModel)]="secondSelected"></fd-multi-input>

Selected: [{{secondSelected.toLocaleString()}}]
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ import { Component } from '@angular/core';
export class MultiInputExampleComponent {

selected = [];
secondSelected = ['Pineapple'];

}
8 changes: 5 additions & 3 deletions library/src/lib/multi-input/multi-input.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@
</fd-popover>
</div>
<div class="fd-multi-input-tags">
<fd-token *ngFor="let token of selected"
(onCloseClick)="handleSelect(false, token)"
class="fd-multi-input-token-spacing">
<fd-token
*ngFor="let token of selected"
[disabled]=this.disabled
(onCloseClick)="handleSelect(false, token)"
class="fd-multi-input-token-spacing">
{{token | displayFnPipe:displayFn}}
</fd-token>
</div>
Expand Down
4 changes: 4 additions & 0 deletions library/src/lib/token/token.component.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.fd-token-content {
display: inline-block;
}
//temporary fix until fundamental styles introduces a disabled token
.fd-token__disabled::after{
cursor: not-allowed;
}
9 changes: 7 additions & 2 deletions library/src/lib/token/token.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ElementRef, EventEmitter, HostListener, Output, ViewChild, ViewEncapsulation } from '@angular/core';
import { Component, ElementRef, EventEmitter, HostListener, Output, ViewChild, ViewEncapsulation, Input } from '@angular/core';

/**
* A token is used to represent contextualizing information.
Expand All @@ -10,6 +10,7 @@ import { Component, ElementRef, EventEmitter, HostListener, Output, ViewChild, V
styleUrls: ['./token.component.scss'],
host: {
class: 'fd-token',
'[class.fd-token__disabled]': 'disabled',
'role': 'button'
},
encapsulation: ViewEncapsulation.None
Expand All @@ -20,6 +21,10 @@ export class TokenComponent {
@ViewChild('contentContainer')
contentContainer: ElementRef;

/** Whether the token is disabled. */
@Input()
disabled: boolean = false;

/** Emitted when the *x* icon is clicked. Specifically, any pseudo-element. */
@Output()
readonly onCloseClick: EventEmitter<void> = new EventEmitter<void>();
Expand All @@ -31,7 +36,7 @@ export class TokenComponent {
/** @hidden */
@HostListener('click', ['$event'])
clickHandler(event): void {
if (this.contentContainer) {
if (this.contentContainer && !this.disabled) {
if (this.elRef.nativeElement.contains(event.target) && !this.contentContainer.nativeElement.contains(event.target)) {
this.onCloseClick.emit();
}
Expand Down

0 comments on commit fc35e9c

Please sign in to comment.