Skip to content

Commit a2a25be

Browse files
amcdnljelbourn
authored andcommitted
docs(input): add overview examples for input (#5228)
1 parent dbdc6ab commit a2a25be

11 files changed

+101
-2
lines changed

src/lib/input/input.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ messages should be displayed. This can be done with CSS, `ngIf` or `ngSwitch`.
4646
Note that, while multiple error messages can be displayed at the same time, it is recommended to
4747
only show one at a time.
4848

49+
<!-- example(input-errors) -->
50+
4951
### Placeholder
5052

5153
A placeholder is an indicative text displayed in the input zone when the input does not contain
@@ -84,6 +86,8 @@ per the Material specification, and clicking it will focus the input.
8486
Adding the `mdPrefix` attribute to an element inside the `md-input-container` will designate it as
8587
the prefix. Similarly, adding `mdSuffix` will designate it as the suffix.
8688

89+
<!-- example(input-prefix-suffix) -->
90+
8791
### Hint Labels
8892

8993
Hint labels are the labels that show below the underline. An `md-input-container` can have up to two
@@ -95,6 +99,8 @@ Hint labels are specified in one of two ways: either using the `hintLabel` attri
9599
`align` attribute containing the side. The attribute version is assumed to be at the `start`.
96100
Specifying a side twice will result in an exception during initialization.
97101

102+
<!-- example(input-hint) -->
103+
98104
### Underline Color
99105

100106
The underline (line under the `input` content) color can be changed by using the `color`

src/material-examples/example-module.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {IconOverviewExample} from './icon-overview/icon-overview-example';
2828
import {ProgressBarOverviewExample} from './progress-bar-overview/progress-bar-overview-example';
2929
import {SlideToggleOverviewExample} from './slide-toggle-overview/slide-toggle-overview-example';
3030
import {SlideToggleFormsExample} from './slide-toggle-forms/slide-toggle-forms-example';
31-
import {InputOverviewExample} from './input-overview/input-overview-example';
3231
import {MenuOverviewExample} from './menu-overview/menu-overview-example';
3332
import {CheckboxConfigurableExample} from './checkbox-configurable/checkbox-configurable-example';
3433
import {
@@ -51,7 +50,6 @@ import {TooltipPositionExample} from './tooltip-position/tooltip-position-exampl
5150
import {
5251
ProgressSpinnerConfigurableExample
5352
} from './progress-spinner-configurable/progress-spinner-configurable-example';
54-
import {InputFormExample} from './input-form/input-form-example';
5553
import {ListOverviewExample} from './list-overview/list-overview-example';
5654
import {SliderOverviewExample} from './slider-overview/slider-overview-example';
5755
import {
@@ -71,6 +69,12 @@ import {ChipsOverviewExample} from './chips-overview/chips-overview-example';
7169
import {ChipsStackedExample} from './chips-stacked/chips-stacked-example';
7270
import {SelectFormExample} from './select-form/select-form-example';
7371
import {DatepickerOverviewExample} from './datepicker-overview/datepicker-overview-example';
72+
import {InputOverviewExample} from './input-overview/input-overview-example';
73+
import {InputErrorsExample} from './input-errors/input-errors-example';
74+
import {InputFormExample} from './input-form/input-form-example';
75+
import {InputPrefixSuffixExample} from './input-prefix-suffix/input-prefix-suffix-example';
76+
import {InputHintExample} from './input-hint/input-hint-example';
77+
7478
import {
7579
MdAutocompleteModule, MdButtonModule, MdButtonToggleModule, MdCardModule, MdCheckboxModule,
7680
MdChipsModule, MdDatepickerModule, MdDialogModule, MdGridListModule, MdIconModule, MdInputModule,
@@ -132,6 +136,9 @@ export const EXAMPLE_COMPONENTS = {
132136
'icon-svg': {title: 'SVG icons', component: IconSvgExample},
133137
'input-form': {title: 'Inputs in a form', component: InputFormExample},
134138
'input-overview': {title: 'Basic inputs', component: InputOverviewExample},
139+
'input-errors': {title: 'Input Errors', component: InputErrorsExample},
140+
'input-prefix-suffix': {title: 'Input Prefixes/Suffixes', component: InputPrefixSuffixExample},
141+
'input-hint': {title: 'Input Hint', component: InputHintExample},
135142
'list-overview': {title: 'Basic list', component: ListOverviewExample},
136143
'list-sections': {title: 'List with sections', component: ListSectionsExample},
137144
'menu-icons': {title: 'Menu with icons', component: MenuIconsExample},
@@ -238,6 +245,9 @@ export const EXAMPLE_LIST = [
238245
IconSvgExample,
239246
InputFormExample,
240247
InputOverviewExample,
248+
InputPrefixSuffixExample,
249+
InputHintExample,
250+
InputErrorsExample,
241251
ListOverviewExample,
242252
ListSectionsExample,
243253
MenuIconsExample,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.example-form {
2+
width: 500px;
3+
}
4+
5+
.example-full-width {
6+
width: 100%;
7+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<form class="example-form">
2+
<md-input-container class="example-full-width">
3+
<input mdInput placeholder="Email" [formControl]="emailFormControl">
4+
<md-error *ngIf="emailFormControl.hasError('pattern')">
5+
Please enter a valid email address
6+
</md-error>
7+
<md-error *ngIf="emailFormControl.hasError('required')">
8+
Email is <strong>required</strong>
9+
</md-error>
10+
</md-input-container>
11+
</form>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {Component} from '@angular/core';
2+
import {FormControl, Validators} from '@angular/forms';
3+
4+
const EMAIL_REGEX = /^[a-zA-Z0-9.!#$%&*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
5+
6+
@Component({
7+
selector: 'input-errors-example',
8+
templateUrl: 'input-errors-example.html',
9+
styleUrls: ['input-errors-example.css'],
10+
})
11+
export class InputErrorsExample {
12+
13+
emailFormControl = new FormControl('', [
14+
Validators.required,
15+
Validators.pattern(EMAIL_REGEX)]);
16+
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.example-form {
2+
width: 500px;
3+
}
4+
5+
.example-full-width {
6+
width: 100%;
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<form class="example-form">
2+
3+
<md-input-container class="example-full-width">
4+
<input mdInput #message maxlength="256" placeholder="Message">
5+
<md-hint align="start"><strong>Don't disclose personal info</strong> </md-hint>
6+
<md-hint align="end">{{message.value.length}} / 256</md-hint>
7+
</md-input-container>
8+
9+
</form>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {Component} from '@angular/core';
2+
3+
@Component({
4+
selector: 'input-hint-example',
5+
templateUrl: 'input-hint-example.html',
6+
styleUrls: ['input-hint-example.css'],
7+
})
8+
export class InputHintExample { }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.example-form {
2+
width: 500px;
3+
}
4+
5+
.example-full-width {
6+
width: 100%;
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<form class="example-form">
2+
3+
<md-input-container class="example-full-width">
4+
<span mdPrefix>+1 &nbsp;</span>
5+
<input type="tel" mdInput placeholder="Telephone">
6+
<md-icon mdSuffix>mode_edit</md-icon>
7+
</md-input-container>
8+
9+
</form>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {Component} from '@angular/core';
2+
3+
@Component({
4+
selector: 'input-prefix-suffix-example',
5+
templateUrl: 'input-prefix-suffix-example.html',
6+
styleUrls: ['input-prefix-suffix-example.css'],
7+
})
8+
export class InputPrefixSuffixExample { }

0 commit comments

Comments
 (0)