-
-
Notifications
You must be signed in to change notification settings - Fork 32
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(design): add textarea component #1562
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
apps/design-land/src/app/text-area/text-area-routing.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { | ||
Routes, | ||
RouterModule, | ||
} from '@angular/router'; | ||
import { NgModule } from '@angular/core'; | ||
import { DesignLandTextAreaComponent } from './text-area.component'; | ||
|
||
export const formRoutes: Routes = [ | ||
{ path: '', component: DesignLandTextAreaComponent }, | ||
]; | ||
|
||
@NgModule({ | ||
imports: [ | ||
RouterModule.forChild(formRoutes), | ||
], | ||
exports: [ | ||
RouterModule, | ||
], | ||
}) | ||
export class DesignLandTextAreaRoutingModule {} |
12 changes: 12 additions & 0 deletions
12
apps/design-land/src/app/text-area/text-area.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<form [formGroup]="form" #ngForm="ngForm"> | ||
<daff-form-field> | ||
<label golfFormLabel>Comments/Questions?</label> | ||
<textarea daff-textarea type="text" | ||
[formControl]="form.controls['textareaExample']" | ||
[formSubmitted]="ngForm.submitted"></textarea> | ||
<daff-error-message *ngIf="form.controls['textareaExample'].errors && (form.controls['textareaExample'].touched || ngForm.submitted)">This is a required field >:(</daff-error-message> | ||
<div class="form__error-placeholder" *ngIf="!(form.controls['textareaExample'].errors && (form.controls['textareaExample'].touched || ngForm.submitted))"></div> | ||
</daff-form-field> | ||
<button daff-button type="submit" daff-button>Submit</button> | ||
</form> | ||
|
10 changes: 10 additions & 0 deletions
10
apps/design-land/src/app/text-area/text-area.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.form { | ||
|
||
& input { | ||
height: 50px; | ||
font-size: 40px; | ||
} | ||
&__error-placeholder { | ||
height: 18px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { | ||
Component, | ||
OnInit, | ||
} from '@angular/core'; | ||
import { | ||
FormBuilder, | ||
Validators, | ||
FormGroup, | ||
} from '@angular/forms'; | ||
|
||
@Component({ | ||
selector: 'design-land-text-area', | ||
templateUrl: './text-area.component.html', | ||
styleUrls: ['./text-area.component.scss'], | ||
}) | ||
export class DesignLandTextAreaComponent implements OnInit { | ||
|
||
form: FormGroup; | ||
|
||
constructor( | ||
private fb: FormBuilder, | ||
) {} | ||
|
||
ngOnInit() { | ||
this.form = this.fb.group({ | ||
textareaExample: ['', Validators.required], | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
|
||
import { DesignLandTextAreaRoutingModule } from './text-area-routing.module'; | ||
|
||
import { DesignLandTextAreaComponent } from './text-area.component'; | ||
import { | ||
DaffTextareaModule, | ||
DaffFormFieldModule, | ||
DaffButtonModule, | ||
DaffInputModule, | ||
} from '@daffodil/design'; | ||
import { ReactiveFormsModule } from '@angular/forms'; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
DesignLandTextAreaComponent, | ||
], | ||
imports: [ | ||
CommonModule, | ||
DaffTextareaModule, | ||
DaffInputModule, | ||
DaffFormFieldModule, | ||
DesignLandTextAreaRoutingModule, | ||
ReactiveFormsModule, | ||
DaffButtonModule, | ||
], | ||
}) | ||
export class DesignLandTextAreaModule { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { DaffTextareaComponent } from './textarea.component'; | ||
export { DaffTextareaModule } from './textarea.module'; |
23 changes: 23 additions & 0 deletions
23
libs/design/src/atoms/form/textarea/textarea.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@import 'daff-util'; | ||
|
||
:host { | ||
background: transparent; | ||
border: none; | ||
border-radius: 3px; | ||
box-shadow: none; | ||
font-size: 1rem; | ||
line-height: 1.25rem; | ||
margin: 0; | ||
width: 100% !important; /* stylelint-disable-line declaration-no-important */ | ||
box-sizing: border-box; | ||
|
||
&:focus { | ||
border: none; | ||
box-shadow: none; | ||
outline: none; | ||
} | ||
|
||
&::placeholder { | ||
color: transparent; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
libs/design/src/atoms/form/textarea/textarea.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { | ||
Component, | ||
DebugElement, | ||
} from '@angular/core'; | ||
import { | ||
waitForAsync, | ||
ComponentFixture, | ||
TestBed, | ||
} from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
import { DaffTextareaComponent } from './textarea.component'; | ||
|
||
|
||
@Component ({ | ||
template: `<textarea daff-textarea></textarea>`, | ||
}) | ||
|
||
class WrapperComponent {} | ||
|
||
describe('DaffTextareaComponent', () => { | ||
let fixture: ComponentFixture<WrapperComponent>; | ||
let de: DebugElement; | ||
let wrapper: WrapperComponent; | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ | ||
DaffTextareaComponent, | ||
WrapperComponent, | ||
], | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(WrapperComponent); | ||
wrapper = fixture.componentInstance; | ||
de = fixture.debugElement.query(By.css('textarea[daff-textarea]')); | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(wrapper).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { | ||
Component, | ||
Input, | ||
Optional, | ||
Self, | ||
ChangeDetectionStrategy, | ||
HostListener, | ||
ElementRef, | ||
} from '@angular/core'; | ||
import { NgControl } from '@angular/forms'; | ||
|
||
import { DaffFormFieldControl } from '../form-field/form-field-control'; | ||
|
||
/** | ||
* A component for standardizing textarea form fields. | ||
*/ | ||
@Component({ | ||
// eslint-disable-next-line @angular-eslint/component-selector | ||
selector: 'textarea[daff-textarea]', | ||
template: '<ng-content></ng-content>', | ||
styleUrls: ['./textarea.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
providers: [ | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
{ provide: DaffFormFieldControl, useExisting: DaffTextareaComponent }, | ||
], | ||
}) | ||
export class DaffTextareaComponent implements DaffFormFieldControl { | ||
|
||
focused = false; | ||
|
||
get disabled() { | ||
return this.ngControl.disabled; | ||
} | ||
|
||
/** | ||
* Has the form been submitted. | ||
*/ | ||
@Input() formSubmitted: boolean; | ||
|
||
@HostListener('focus') onFocus() { | ||
this.focused = true; | ||
} | ||
|
||
@HostListener('blur') onBlur() { | ||
this.focused = false; | ||
} | ||
|
||
constructor(@Optional() @Self() public ngControl: NgControl, private _elementRef: ElementRef<HTMLInputElement>) {} | ||
|
||
focus() { | ||
this._elementRef.nativeElement.focus(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Textarea | ||
`[daff-textarea]` is a component selector that allows the native `<textarea>` element to work with `<daff-form-field>`. It has the same functionality as a native `<textarea>` and contains custom styling and functionality. It is used for multi-line text input. It can not be used by itself and must be contained inside of a `<daff-form-field>`. | ||
|
||
## Form Field Features | ||
There are many features in `<daff-form-field>` that can be used with the `[daff-textarea]` component. These include `[daffFormLabel]` and `<daff-error-message>`. | ||
|
||
For additional information about these features, see the <a href="/form-field">form field</a> documentation. | ||
|
||
## Accessibility | ||
The `[daff-textarea]` component works with the native `<textarea>` element to provide an accessible experience. `[daffFormLabel` should always be used in conjuction with `[daff-textarea]` even if `placeholder="placeholder text"` is used. An error will occur if `[daffFormLabel]` is not defined. | ||
|
||
## Usage | ||
``` | ||
<h3>Basic Textarea</h3> | ||
<daff-form-field> | ||
<label daffFormLabel>Comments/Questions?</label> | ||
<textarea daff-textarea [formControl]="comments"></textarea> | ||
<daff-error-message *ngIf="comments.invalid">This field is required.</daff-error-message> | ||
</daff-form-field> | ||
|
||
<h3>Disabled Textarea</h3> | ||
<daff-form-field> | ||
<label daffFormLabel>Comments/Questions?</label> | ||
<textarea daff-textarea [formControl]="comments2"></textarea> | ||
</daff-form-field> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
|
||
import { DaffTextareaComponent } from './textarea.component'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
], | ||
exports: [ | ||
DaffTextareaComponent, | ||
], | ||
declarations: [ | ||
DaffTextareaComponent, | ||
], | ||
}) | ||
export class DaffTextareaModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is never used; it should be removed.