Skip to content
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

fix(input-container): New attribute hideRequiredMarker #4237

Merged
merged 2 commits into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/demo-app/input/input-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ <h4>Textarea</h4>
[placeholder]="requiredField ? 'Required field' : 'Not required field'">
</md-input-container>
</p>
<p>
<md-checkbox [(ngModel)]="hideRequiredMarker">Check to hide the required marker:</md-checkbox>
<md-input-container [hideRequiredMarker]="hideRequiredMarker" style="width: 300px">
<input mdInput
required
[placeholder]="hideRequiredMarker ? 'Required Without Marker' : 'Required With Marker'">
</md-input-container>
</p>
<p>
<md-button-toggle-group [(ngModel)]="floatingLabel">
<md-button-toggle value="auto">Auto Float</md-button-toggle>
Expand Down
1 change: 1 addition & 0 deletions src/demo-app/input/input-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class InputDemo {
floatingLabel: string = 'auto';
color: boolean;
requiredField: boolean;
hideRequiredMarker: boolean;
ctrlDisabled = false;

name: string;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/input/input-container.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*ngIf="_hasPlaceholder()">
<ng-content select="md-placeholder, mat-placeholder"></ng-content>
{{_mdInputChild.placeholder}}
<span class="mat-placeholder-required" *ngIf="_mdInputChild.required">*</span>
<span class="mat-placeholder-required" *ngIf="!hideRequiredMarker && _mdInputChild.required">*</span>
</label>
</span>
</div>
Expand Down
22 changes: 20 additions & 2 deletions src/lib/input/input-container.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,20 @@ describe('MdInputContainer', function () {
expect(el.nativeElement.textContent).toMatch(/hello\s+\*/g);
});

it('hide placeholder required star when set to hide the required marker', () => {
let fixture = TestBed.createComponent(MdInputContainerPlaceholderRequiredTestComponent);
fixture.detectChanges();

let el = fixture.debugElement.query(By.css('label'));
expect(el).not.toBeNull();
expect(el.nativeElement.textContent).toMatch(/hello\s+\*/g);

fixture.componentInstance.hideRequiredMarker = true;
fixture.detectChanges();

expect(el.nativeElement.textContent).toMatch(/hello/g);
});

it('supports the disabled attribute as binding', async(() => {
const fixture = TestBed.createComponent(MdInputContainerWithDisabled);
fixture.detectChanges();
Expand Down Expand Up @@ -741,9 +755,13 @@ class MdInputContainerWithType {
}

@Component({
template: `<md-input-container><input mdInput required placeholder="hello"></md-input-container>`
template: `<md-input-container [hideRequiredMarker]="hideRequiredMarker">
<input mdInput required placeholder="hello">
</md-input-container>`
})
class MdInputContainerPlaceholderRequiredTestComponent {}
class MdInputContainerPlaceholderRequiredTestComponent {
hideRequiredMarker: boolean;
}

@Component({
template: `
Expand Down
8 changes: 8 additions & 0 deletions src/lib/input/input-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ export class MdInputContainer implements AfterViewInit, AfterContentInit {
get dividerColor() { return this.color; }
set dividerColor(value) { this.color = value; }

/** Whether we should hide the required marker. */
@Input()
get hideRequiredMarker() { return this._hideRequiredMarker; }
set hideRequiredMarker(value: any) {
this._hideRequiredMarker = coerceBooleanProperty(value);
}
private _hideRequiredMarker: boolean;

/** Whether the floating label should always float or not. */
get _shouldAlwaysFloat() { return this._floatPlaceholder === 'always'; }

Expand Down