Skip to content

Commit 03d1882

Browse files
committed
feat(select): Add invalid and optional text fields
1 parent 3231be7 commit 03d1882

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-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: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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 { withKnobs, select, boolean, text } from "@storybook/addon-knobs/angular";
44

55
import { SelectModule } from "../";
66

@@ -12,8 +12,13 @@ storiesOf("Select", module).addDecorator(
1212
.addDecorator(withKnobs)
1313
.add("Basic", () => ({
1414
template: `
15-
<div style="width: 165px">
16-
<ibm-select [theme]="theme" [display]="display">
15+
<ibm-select
16+
[disabled]="disabled"
17+
[invalid]="invalid"
18+
[invalidText]="invalidText"
19+
[helperText]="helperText"
20+
[theme]="theme"
21+
[display]="display">
1722
<option value="" disabled selected hidden>Choose an option</option>
1823
<option value="solong">A much longer option that is worth having around to check how text flows</option>
1924
<optgroup label="Category 1">
@@ -25,9 +30,12 @@ storiesOf("Select", module).addDecorator(
2530
<option value="option2">Option 2</option>
2631
</optgroup>
2732
</ibm-select>
28-
</div>
2933
`,
3034
props: {
35+
disabled: boolean("Disabled", false),
36+
invalid: boolean("Show form validation", false),
37+
invalidText: text("Form validation content", "Please select an option."),
38+
helperText: text("Helper text", "Optional helper text."),
3139
theme: select("Theme", ["dark", "light"], "dark"),
3240
display: select("Display", ["default", "inline"], "default")
3341
}

0 commit comments

Comments
 (0)