Skip to content

Commit 57b9b11

Browse files
authored
Merge branch 'master' into master
2 parents fbd0692 + 40257f5 commit 57b9b11

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

src/select/select.component.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from "@angular/forms";
4141
<select
4242
#select
4343
[attr.id]="id"
44+
[attr.data-invalid]="(invalid ? '' : null)"
4445
[disabled]="disabled"
4546
(change)="onChange($event)"
4647
class="bx--select-input">
@@ -49,9 +50,16 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from "@angular/forms";
4950
<svg *ngIf="!skeleton" class="bx--select__arrow" width="10" height="5" viewBox="0 0 10 5">
5051
<path d="M0 0l5 4.998L10 0z" fill-rule="evenodd" />
5152
</svg>
53+
<div *ngIf="helperText" class="bx--form__helper-text">{{helperText}}</div>
54+
<div *ngIf="invalid" class="bx--form-requirement">{{invalidText}}</div>
5255
</div>
5356
</div>
5457
`,
58+
styles: [`
59+
[data-invalid] ~ .bx--select__arrow {
60+
bottom: 2.25rem;
61+
}
62+
`],
5563
providers: [
5664
{
5765
provide: NG_VALUE_ACCESSOR,
@@ -74,6 +82,14 @@ export class Select implements ControlValueAccessor {
7482
* Label for the select. Appears above the input.
7583
*/
7684
@Input() label = "Select label";
85+
/**
86+
* Optional helper text that appears under he label.
87+
*/
88+
@Input() helperText: string;
89+
/**
90+
* Sets the invalid text.
91+
*/
92+
@Input() invalidText: string;
7793
/**
7894
* Sets the unique ID. Defaults to `select-${total count of selects instantiated}`
7995
*/
@@ -86,6 +102,11 @@ export class Select implements ControlValueAccessor {
86102
* Set to true for a loading select.
87103
*/
88104
@Input() skeleton = false;
105+
/**
106+
* Set to `true` for an invalid select component.
107+
*/
108+
@Input() invalid = false;
109+
89110
/**
90111
* `light` or `dark` select theme
91112
*/

src/select/select.stories.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { storiesOf, moduleMetadata } from "@storybook/angular";
22
import { action } from "@storybook/addon-actions";
3-
import { withKnobs, select } from "@storybook/addon-knobs/angular";
3+
import {
4+
withKnobs,
5+
select,
6+
boolean,
7+
text
8+
} from "@storybook/addon-knobs/angular";
49

510
import { SelectModule } from "../";
611

@@ -12,8 +17,13 @@ storiesOf("Select", module).addDecorator(
1217
.addDecorator(withKnobs)
1318
.add("Basic", () => ({
1419
template: `
15-
<div style="width: 165px">
16-
<ibm-select [theme]="theme" [display]="display">
20+
<ibm-select
21+
[disabled]="disabled"
22+
[invalid]="invalid"
23+
[invalidText]="invalidText"
24+
[helperText]="helperText"
25+
[theme]="theme"
26+
[display]="display">
1727
<option value="" disabled selected hidden>Choose an option</option>
1828
<option value="solong">A much longer option that is worth having around to check how text flows</option>
1929
<optgroup label="Category 1">
@@ -25,9 +35,12 @@ storiesOf("Select", module).addDecorator(
2535
<option value="option2">Option 2</option>
2636
</optgroup>
2737
</ibm-select>
28-
</div>
2938
`,
3039
props: {
40+
disabled: boolean("Disabled", false),
41+
invalid: boolean("Show form validation", false),
42+
invalidText: text("Form validation content", "Please select an option."),
43+
helperText: text("Helper text", "Optional helper text."),
3144
theme: select("Theme", ["dark", "light"], "dark"),
3245
display: select("Display", ["default", "inline"], "default")
3346
}

0 commit comments

Comments
 (0)