Skip to content

Commit acb5b71

Browse files
authored
Merge branch 'master' into dropdown-placeholder
2 parents 7658c36 + 6eeae0c commit acb5b71

File tree

5 files changed

+54
-30
lines changed

5 files changed

+54
-30
lines changed

src/dialog/dialog.directive.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,15 @@ export class DialogDirective implements OnInit, OnDestroy, OnChanges {
8787
/**
8888
* Config object passed to the rendered component
8989
*/
90-
@Output() onClose: EventEmitter<any> = new EventEmitter<any>();
9190
dialogConfig: DialogConfig;
91+
/**
92+
* Emits an event when the dialog is closed
93+
*/
94+
@Output() onClose: EventEmitter<any> = new EventEmitter();
95+
/**
96+
* Emits an event when the dialog is opened
97+
*/
98+
@Output() onOpen: EventEmitter<any> = new EventEmitter();
9299

93100
@HostBinding("attr.role") role = "button";
94101
@HostBinding("attr.aria-expanded") expanded = false;
@@ -197,6 +204,7 @@ export class DialogDirective implements OnInit, OnDestroy, OnChanges {
197204
open() {
198205
this.dialogService.open(this.viewContainerRef, this.dialogConfig);
199206
this.expanded = true;
207+
this.onOpen.emit();
200208
}
201209

202210
/**
@@ -206,6 +214,9 @@ export class DialogDirective implements OnInit, OnDestroy, OnChanges {
206214
toggle() {
207215
this.dialogService.toggle(this.viewContainerRef, this.dialogConfig);
208216
this.expanded = this.dialogService.isOpen;
217+
if (this.expanded) {
218+
this.onOpen.emit();
219+
}
209220
}
210221

211222
/**

src/dialog/overflow-menu/overflow-menu-option.component.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
Input,
55
ElementRef,
66
Output,
7-
EventEmitter
7+
EventEmitter,
8+
AfterViewInit
89
} from "@angular/core";
910

1011
/**
@@ -17,7 +18,7 @@ import {
1718
* <ibm-overflow-menu-option type="danger">Danger option</ibm-overflow-menu-option>
1819
* ```
1920
*
20-
* For content that expands beyod the overflow menu `OverflowMenuOption` automatically adds a title attribute.
21+
* For content that expands beyond the overflow menu `OverflowMenuOption` automatically adds a title attribute.
2122
*/
2223
@Component({
2324
selector: "ibm-overflow-menu-option",
@@ -30,12 +31,12 @@ import {
3031
(blur)="tabIndex = -1"
3132
(click)="onClick($event)"
3233
[disabled]="disabled"
33-
[title]="(titleEnabled ? content : '')">
34+
[title]="title">
3435
<ng-content></ng-content>
3536
</button>
3637
`
3738
})
38-
export class OverflowMenuOption {
39+
export class OverflowMenuOption implements AfterViewInit {
3940
@HostBinding("class") optionClass = "bx--overflow-menu-options__option";
4041
@HostBinding("attr.role") role = "presentation";
4142

@@ -60,30 +61,20 @@ export class OverflowMenuOption {
6061
@Output() selected: EventEmitter<any> = new EventEmitter();
6162

6263
public tabIndex = -1;
64+
// note: title must be a real attribute (i.e. not a getter) as of Angular@6 due to
65+
// change after checked errors
66+
public title = null;
6367

6468
constructor(protected elementRef: ElementRef) {}
6569

6670
onClick(event) {
6771
this.selected.emit();
6872
}
6973

70-
/**
71-
* Returns true if the content string is longer than the width of the containing button
72-
*
73-
* note: getter ties into the view check cycle so we always get an accurate value
74-
*/
75-
get titleEnabled() {
74+
ngAfterViewInit() {
7675
const button = this.elementRef.nativeElement.querySelector("button");
7776
if (button.scrollWidth > button.offsetWidth) {
78-
return true;
77+
this.title = this.elementRef.nativeElement.querySelector("button").textContent;
7978
}
80-
return false;
81-
}
82-
83-
/**
84-
* Returns the text content projected into the component
85-
*/
86-
get content(): string {
87-
return this.elementRef.nativeElement.querySelector("button").textContent;
8879
}
8980
}

src/dialog/overflow-menu/overflow-menu.component.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import {
22
Component,
33
ElementRef,
44
Input,
5-
ViewEncapsulation
5+
ViewEncapsulation,
6+
ContentChild
67
} from "@angular/core";
78
import { I18n } from "./../../i18n/i18n.module";
9+
import { OverflowMenuDirective } from "./overflow-menu.directive";
810

911
/**
1012
* The OverFlow menu component encapsulates the OverFlowMenu directive, and the menu iconography into one convienent component
@@ -22,9 +24,11 @@ import { I18n } from "./../../i18n/i18n.module";
2224
template: `
2325
<div
2426
[ibmOverflowMenu]="options"
25-
[ngClass]="{'bx--overflow-menu--open': open === true}"
27+
[ngClass]="{'bx--overflow-menu--open': open}"
2628
[attr.aria-label]="buttonLabel"
2729
[flip]="flip"
30+
(onOpen)="open = true"
31+
(onClose)="open = false"
2832
role="button"
2933
aria-haspopup="true"
3034
class="bx--overflow-menu"
@@ -67,12 +71,9 @@ export class OverflowMenu {
6771

6872
@Input() flip = false;
6973

70-
constructor(protected elementRef: ElementRef, protected i18n: I18n) {}
74+
@ContentChild(OverflowMenuDirective) overflowMenuDirective: OverflowMenuDirective;
7175

72-
get open() {
73-
if (this.elementRef.nativeElement.children[0].getAttribute("aria-expanded") === "true") {
74-
return true;
75-
}
76-
return false;
77-
}
76+
open = false;
77+
78+
constructor(protected elementRef: ElementRef, protected i18n: I18n) {}
7879
}

src/number-input/number.component.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class NumberChange {
3333
<label *ngIf="skeleton && label" class="bx--label bx--skeleton"></label>
3434
<div
3535
data-numberinput
36+
[attr.data-invalid]="(invalid ? '' : null)"
3637
class="bx--number"
3738
[ngClass]="{
3839
'bx--number--light': theme === 'light',
@@ -48,7 +49,8 @@ export class NumberChange {
4849
[min]="min"
4950
[max]="max"
5051
[disabled]="disabled"
51-
[required]="required"/>
52+
[required]="required"
53+
(input)="onNumberInputChange($event)"/>
5254
<div *ngIf="!skeleton" class="bx--number__controls">
5355
<button
5456
class="bx--number__control-btn up-icon"
@@ -65,6 +67,9 @@ export class NumberChange {
6567
</svg>
6668
</button>
6769
</div>
70+
<div *ngIf="invalid" class="bx--form-requirement">
71+
{{invalidText}}
72+
</div>
6873
<div *ngIf="helperText" class="bx--form__helper-text">{{helperText}}</div>
6974
</div>
7075
`,
@@ -96,6 +101,10 @@ export class Number implements ControlValueAccessor {
96101
* Set to `true` for a loading number component.
97102
*/
98103
@Input() skeleton = false;
104+
/**
105+
* Set to `true` for an invalid number component.
106+
*/
107+
@Input() invalid = false;
99108
/**
100109
* The unique id for the number component.
101110
*/
@@ -124,6 +133,10 @@ export class Number implements ControlValueAccessor {
124133
* Sets the optional helper text.
125134
*/
126135
@Input() helperText;
136+
/**
137+
* Sets the invalid text.
138+
*/
139+
@Input() invalidText;
127140
/**
128141
* Emits event notifying other classes when a change in state occurs in the input.
129142
*/
@@ -205,4 +218,8 @@ export class Number implements ControlValueAccessor {
205218
this.propagateChange(this.value);
206219
}
207220

221+
onNumberInputChange(event) {
222+
this.value = event.target.value;
223+
this.emitChangeEvent();
224+
}
208225
}

src/number-input/number.stories.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@ storiesOf("Number", module).addDecorator(
1717
[theme]="theme"
1818
[min]="min"
1919
[max]="max"
20+
[invalid]="invalid"
21+
[invalidText]="invalidText"
2022
[disabled]="disabled">
2123
</ibm-number>
2224
`,
2325
props: {
2426
label: text("label", "Number Input Label"),
2527
helperText: text("helper text", "Optional helper text here"),
28+
invalidText: text("Form validation content", "Invalid number"),
2629
theme: select("theme", ["dark", "light"], "dark"),
2730
min: number("min", 0),
2831
max: number("max", 100),
32+
invalid: boolean("Show form validation", false),
2933
disabled: boolean("disabled", false)
3034
}
3135
}))

0 commit comments

Comments
 (0)