Skip to content

Commit 2112fac

Browse files
Nathan Tatejelbourn
authored andcommitted
feat(material-experimental/radio): use MDC DOM structure and styles (#17179)
1 parent 30de283 commit 2112fac

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
<!-- TODO: copy in demo template from existing mat-radio demo. -->
2-
Not yet implemented.
1+
<h1>Basic Example</h1>
2+
<section class="demo-section">
3+
<mat-radio name="group1">Option 1</mat-radio>
4+
<mat-radio name="group1">Option 2</mat-radio>
5+
<mat-radio name="group1">Option 3</mat-radio>
6+
</section>

src/material-experimental/mdc-radio/BUILD.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ sass_library(
2828
sass_binary(
2929
name = "radio_scss",
3030
src = "radio.scss",
31+
include_paths = [
32+
"external/npm/node_modules",
33+
],
34+
deps = [
35+
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib",
36+
"//src/material-experimental/mdc-helpers:mdc_scss_deps_lib",
37+
"//src/material/core:core_scss_lib",
38+
],
3139
)
3240

3341
ng_e2e_test_library(
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
<!-- TODO: MDC template here. -->
1+
<div class="mdc-form-field">
2+
<div class="mdc-radio">
3+
<input class="mdc-radio__native-control" type="radio" [id]="inputId">
4+
<div class="mdc-radio__background">
5+
<div class="mdc-radio__outer-circle"></div>
6+
<div class="mdc-radio__inner-circle"></div>
7+
</div>
8+
</div>
9+
<label [for]="inputId" #label>
10+
<ng-content></ng-content>
11+
</label>
12+
</div>
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
// TODO: MDC core styles here.
1+
@import '@material/radio/mixins';
2+
@import '@material/form-field/mixins';
3+
@import '../mdc-helpers/mdc-helpers';
4+
5+
6+
@include mdc-radio-without-ripple($query: $mat-base-styles-query);
7+
@include mdc-form-field-core-styles($query: $mat-base-styles-query);

src/material-experimental/mdc-radio/radio.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ChangeDetectionStrategy, Component, ViewEncapsulation} from '@angular/core';
9+
import {ChangeDetectionStrategy, Component, ViewEncapsulation, Input} from '@angular/core';
10+
11+
// Increasing integer for generating unique ids for radio components.
12+
let nextUniqueId = 0;
1013

1114
@Component({
1215
moduleId: module.id,
@@ -15,11 +18,21 @@ import {ChangeDetectionStrategy, Component, ViewEncapsulation} from '@angular/co
1518
styleUrls: ['radio.css'],
1619
host: {
1720
'class': 'mat-mdc-radio',
21+
'[attr.id]': 'id',
1822
},
1923
exportAs: 'matRadio',
2024
encapsulation: ViewEncapsulation.None,
2125
changeDetection: ChangeDetectionStrategy.OnPush,
2226
})
2327
export class MatRadio {
28+
29+
private _uniqueId: string = `mat-radio-${++nextUniqueId}`;
30+
31+
/** The unique ID for the radio button. */
32+
@Input() id: string = this._uniqueId;
33+
34+
/** ID of the native input element inside `<mat-radio-button>` */
35+
get inputId(): string { return `${this.id || this._uniqueId}-input`; }
36+
2437
// TODO: set up MDC foundation class.
2538
}

0 commit comments

Comments
 (0)