1 | import { InjectionToken, forwardRef, EventEmitter, Directive, ChangeDetectorRef, Output, Input, ContentChildren, ElementRef, ViewChild, Component, ViewEncapsulation, ChangeDetectionStrategy, Optional, Inject, Attribute, NgModule } from '@angular/core';
|
---|
2 | import { mixinDisableRipple, mixinTabIndex, MatRippleModule, MatCommonModule } from '@angular/material/core';
|
---|
3 | import { FocusMonitor } from '@angular/cdk/a11y';
|
---|
4 | import { coerceBooleanProperty, coerceNumberProperty } from '@angular/cdk/coercion';
|
---|
5 | import { UniqueSelectionDispatcher } from '@angular/cdk/collections';
|
---|
6 | import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
---|
7 | import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations';
|
---|
8 |
|
---|
9 | /**
|
---|
10 | * @license
|
---|
11 | * Copyright Google LLC All Rights Reserved.
|
---|
12 | *
|
---|
13 | * Use of this source code is governed by an MIT-style license that can be
|
---|
14 | * found in the LICENSE file at https://angular.io/license
|
---|
15 | */
|
---|
16 | const MAT_RADIO_DEFAULT_OPTIONS = new InjectionToken('mat-radio-default-options', {
|
---|
17 | providedIn: 'root',
|
---|
18 | factory: MAT_RADIO_DEFAULT_OPTIONS_FACTORY
|
---|
19 | });
|
---|
20 | function MAT_RADIO_DEFAULT_OPTIONS_FACTORY() {
|
---|
21 | return {
|
---|
22 | color: 'accent'
|
---|
23 | };
|
---|
24 | }
|
---|
25 | // Increasing integer for generating unique ids for radio components.
|
---|
26 | let nextUniqueId = 0;
|
---|
27 | /**
|
---|
28 | * Provider Expression that allows mat-radio-group to register as a ControlValueAccessor. This
|
---|
29 | * allows it to support [(ngModel)] and ngControl.
|
---|
30 | * @docs-private
|
---|
31 | */
|
---|
32 | const MAT_RADIO_GROUP_CONTROL_VALUE_ACCESSOR = {
|
---|
33 | provide: NG_VALUE_ACCESSOR,
|
---|
34 | useExisting: forwardRef(() => MatRadioGroup),
|
---|
35 | multi: true
|
---|
36 | };
|
---|
37 | /** Change event object emitted by MatRadio and MatRadioGroup. */
|
---|
38 | class MatRadioChange {
|
---|
39 | constructor(
|
---|
40 | /** The MatRadioButton that emits the change event. */
|
---|
41 | source,
|
---|
42 | /** The value of the MatRadioButton. */
|
---|
43 | value) {
|
---|
44 | this.source = source;
|
---|
45 | this.value = value;
|
---|
46 | }
|
---|
47 | }
|
---|
48 | /**
|
---|
49 | * Injection token that can be used to inject instances of `MatRadioGroup`. It serves as
|
---|
50 | * alternative token to the actual `MatRadioGroup` class which could cause unnecessary
|
---|
51 | * retention of the class and its component metadata.
|
---|
52 | */
|
---|
53 | const MAT_RADIO_GROUP = new InjectionToken('MatRadioGroup');
|
---|
54 | /**
|
---|
55 | * Base class with all of the `MatRadioGroup` functionality.
|
---|
56 | * @docs-private
|
---|
57 | */
|
---|
58 | class _MatRadioGroupBase {
|
---|
59 | constructor(_changeDetector) {
|
---|
60 | this._changeDetector = _changeDetector;
|
---|
61 | /** Selected value for the radio group. */
|
---|
62 | this._value = null;
|
---|
63 | /** The HTML name attribute applied to radio buttons in this group. */
|
---|
64 | this._name = `mat-radio-group-${nextUniqueId++}`;
|
---|
65 | /** The currently selected radio button. Should match value. */
|
---|
66 | this._selected = null;
|
---|
67 | /** Whether the `value` has been set to its initial value. */
|
---|
68 | this._isInitialized = false;
|
---|
69 | /** Whether the labels should appear after or before the radio-buttons. Defaults to 'after' */
|
---|
70 | this._labelPosition = 'after';
|
---|
71 | /** Whether the radio group is disabled. */
|
---|
72 | this._disabled = false;
|
---|
73 | /** Whether the radio group is required. */
|
---|
74 | this._required = false;
|
---|
75 | /** The method to be called in order to update ngModel */
|
---|
76 | this._controlValueAccessorChangeFn = () => { };
|
---|
77 | /**
|
---|
78 | * onTouch function registered via registerOnTouch (ControlValueAccessor).
|
---|
79 | * @docs-private
|
---|
80 | */
|
---|
81 | this.onTouched = () => { };
|
---|
82 | /**
|
---|
83 | * Event emitted when the group value changes.
|
---|
84 | * Change events are only emitted when the value changes due to user interaction with
|
---|
85 | * a radio button (the same behavior as `<input type-"radio">`).
|
---|
86 | */
|
---|
87 | this.change = new EventEmitter();
|
---|
88 | }
|
---|
89 | /** Name of the radio button group. All radio buttons inside this group will use this name. */
|
---|
90 | get name() { return this._name; }
|
---|
91 | set name(value) {
|
---|
92 | this._name = value;
|
---|
93 | this._updateRadioButtonNames();
|
---|
94 | }
|
---|
95 | /** Whether the labels should appear after or before the radio-buttons. Defaults to 'after' */
|
---|
96 | get labelPosition() {
|
---|
97 | return this._labelPosition;
|
---|
98 | }
|
---|
99 | set labelPosition(v) {
|
---|
100 | this._labelPosition = v === 'before' ? 'before' : 'after';
|
---|
101 | this._markRadiosForCheck();
|
---|
102 | }
|
---|
103 | /**
|
---|
104 | * Value for the radio-group. Should equal the value of the selected radio button if there is
|
---|
105 | * a corresponding radio button with a matching value. If there is not such a corresponding
|
---|
106 | * radio button, this value persists to be applied in case a new radio button is added with a
|
---|
107 | * matching value.
|
---|
108 | */
|
---|
109 | get value() { return this._value; }
|
---|
110 | set value(newValue) {
|
---|
111 | if (this._value !== newValue) {
|
---|
112 | // Set this before proceeding to ensure no circular loop occurs with selection.
|
---|
113 | this._value = newValue;
|
---|
114 | this._updateSelectedRadioFromValue();
|
---|
115 | this._checkSelectedRadioButton();
|
---|
116 | }
|
---|
117 | }
|
---|
118 | _checkSelectedRadioButton() {
|
---|
119 | if (this._selected && !this._selected.checked) {
|
---|
120 | this._selected.checked = true;
|
---|
121 | }
|
---|
122 | }
|
---|
123 | /**
|
---|
124 | * The currently selected radio button. If set to a new radio button, the radio group value
|
---|
125 | * will be updated to match the new selected button.
|
---|
126 | */
|
---|
127 | get selected() { return this._selected; }
|
---|
128 | set selected(selected) {
|
---|
129 | this._selected = selected;
|
---|
130 | this.value = selected ? selected.value : null;
|
---|
131 | this._checkSelectedRadioButton();
|
---|
132 | }
|
---|
133 | /** Whether the radio group is disabled */
|
---|
134 | get disabled() { return this._disabled; }
|
---|
135 | set disabled(value) {
|
---|
136 | this._disabled = coerceBooleanProperty(value);
|
---|
137 | this._markRadiosForCheck();
|
---|
138 | }
|
---|
139 | /** Whether the radio group is required */
|
---|
140 | get required() { return this._required; }
|
---|
141 | set required(value) {
|
---|
142 | this._required = coerceBooleanProperty(value);
|
---|
143 | this._markRadiosForCheck();
|
---|
144 | }
|
---|
145 | /**
|
---|
146 | * Initialize properties once content children are available.
|
---|
147 | * This allows us to propagate relevant attributes to associated buttons.
|
---|
148 | */
|
---|
149 | ngAfterContentInit() {
|
---|
150 | // Mark this component as initialized in AfterContentInit because the initial value can
|
---|
151 | // possibly be set by NgModel on MatRadioGroup, and it is possible that the OnInit of the
|
---|
152 | // NgModel occurs *after* the OnInit of the MatRadioGroup.
|
---|
153 | this._isInitialized = true;
|
---|
154 | }
|
---|
155 | /**
|
---|
156 | * Mark this group as being "touched" (for ngModel). Meant to be called by the contained
|
---|
157 | * radio buttons upon their blur.
|
---|
158 | */
|
---|
159 | _touch() {
|
---|
160 | if (this.onTouched) {
|
---|
161 | this.onTouched();
|
---|
162 | }
|
---|
163 | }
|
---|
164 | _updateRadioButtonNames() {
|
---|
165 | if (this._radios) {
|
---|
166 | this._radios.forEach(radio => {
|
---|
167 | radio.name = this.name;
|
---|
168 | radio._markForCheck();
|
---|
169 | });
|
---|
170 | }
|
---|
171 | }
|
---|
172 | /** Updates the `selected` radio button from the internal _value state. */
|
---|
173 | _updateSelectedRadioFromValue() {
|
---|
174 | // If the value already matches the selected radio, do nothing.
|
---|
175 | const isAlreadySelected = this._selected !== null && this._selected.value === this._value;
|
---|
176 | if (this._radios && !isAlreadySelected) {
|
---|
177 | this._selected = null;
|
---|
178 | this._radios.forEach(radio => {
|
---|
179 | radio.checked = this.value === radio.value;
|
---|
180 | if (radio.checked) {
|
---|
181 | this._selected = radio;
|
---|
182 | }
|
---|
183 | });
|
---|
184 | }
|
---|
185 | }
|
---|
186 | /** Dispatch change event with current selection and group value. */
|
---|
187 | _emitChangeEvent() {
|
---|
188 | if (this._isInitialized) {
|
---|
189 | this.change.emit(new MatRadioChange(this._selected, this._value));
|
---|
190 | }
|
---|
191 | }
|
---|
192 | _markRadiosForCheck() {
|
---|
193 | if (this._radios) {
|
---|
194 | this._radios.forEach(radio => radio._markForCheck());
|
---|
195 | }
|
---|
196 | }
|
---|
197 | /**
|
---|
198 | * Sets the model value. Implemented as part of ControlValueAccessor.
|
---|
199 | * @param value
|
---|
200 | */
|
---|
201 | writeValue(value) {
|
---|
202 | this.value = value;
|
---|
203 | this._changeDetector.markForCheck();
|
---|
204 | }
|
---|
205 | /**
|
---|
206 | * Registers a callback to be triggered when the model value changes.
|
---|
207 | * Implemented as part of ControlValueAccessor.
|
---|
208 | * @param fn Callback to be registered.
|
---|
209 | */
|
---|
210 | registerOnChange(fn) {
|
---|
211 | this._controlValueAccessorChangeFn = fn;
|
---|
212 | }
|
---|
213 | /**
|
---|
214 | * Registers a callback to be triggered when the control is touched.
|
---|
215 | * Implemented as part of ControlValueAccessor.
|
---|
216 | * @param fn Callback to be registered.
|
---|
217 | */
|
---|
218 | registerOnTouched(fn) {
|
---|
219 | this.onTouched = fn;
|
---|
220 | }
|
---|
221 | /**
|
---|
222 | * Sets the disabled state of the control. Implemented as a part of ControlValueAccessor.
|
---|
223 | * @param isDisabled Whether the control should be disabled.
|
---|
224 | */
|
---|
225 | setDisabledState(isDisabled) {
|
---|
226 | this.disabled = isDisabled;
|
---|
227 | this._changeDetector.markForCheck();
|
---|
228 | }
|
---|
229 | }
|
---|
230 | _MatRadioGroupBase.decorators = [
|
---|
231 | { type: Directive }
|
---|
232 | ];
|
---|
233 | _MatRadioGroupBase.ctorParameters = () => [
|
---|
234 | { type: ChangeDetectorRef }
|
---|
235 | ];
|
---|
236 | _MatRadioGroupBase.propDecorators = {
|
---|
237 | change: [{ type: Output }],
|
---|
238 | color: [{ type: Input }],
|
---|
239 | name: [{ type: Input }],
|
---|
240 | labelPosition: [{ type: Input }],
|
---|
241 | value: [{ type: Input }],
|
---|
242 | selected: [{ type: Input }],
|
---|
243 | disabled: [{ type: Input }],
|
---|
244 | required: [{ type: Input }]
|
---|
245 | };
|
---|
246 | /**
|
---|
247 | * A group of radio buttons. May contain one or more `<mat-radio-button>` elements.
|
---|
248 | */
|
---|
249 | class MatRadioGroup extends _MatRadioGroupBase {
|
---|
250 | }
|
---|
251 | MatRadioGroup.decorators = [
|
---|
252 | { type: Directive, args: [{
|
---|
253 | selector: 'mat-radio-group',
|
---|
254 | exportAs: 'matRadioGroup',
|
---|
255 | providers: [
|
---|
256 | MAT_RADIO_GROUP_CONTROL_VALUE_ACCESSOR,
|
---|
257 | { provide: MAT_RADIO_GROUP, useExisting: MatRadioGroup },
|
---|
258 | ],
|
---|
259 | host: {
|
---|
260 | 'role': 'radiogroup',
|
---|
261 | 'class': 'mat-radio-group',
|
---|
262 | },
|
---|
263 | },] }
|
---|
264 | ];
|
---|
265 | MatRadioGroup.propDecorators = {
|
---|
266 | _radios: [{ type: ContentChildren, args: [forwardRef(() => MatRadioButton), { descendants: true },] }]
|
---|
267 | };
|
---|
268 | // Boilerplate for applying mixins to MatRadioButton.
|
---|
269 | /** @docs-private */
|
---|
270 | class MatRadioButtonBase {
|
---|
271 | constructor(_elementRef) {
|
---|
272 | this._elementRef = _elementRef;
|
---|
273 | }
|
---|
274 | }
|
---|
275 | const _MatRadioButtonMixinBase = mixinDisableRipple(mixinTabIndex(MatRadioButtonBase));
|
---|
276 | /**
|
---|
277 | * Base class with all of the `MatRadioButton` functionality.
|
---|
278 | * @docs-private
|
---|
279 | */
|
---|
280 | class _MatRadioButtonBase extends _MatRadioButtonMixinBase {
|
---|
281 | constructor(radioGroup, elementRef, _changeDetector, _focusMonitor, _radioDispatcher, animationMode, _providerOverride, tabIndex) {
|
---|
282 | super(elementRef);
|
---|
283 | this._changeDetector = _changeDetector;
|
---|
284 | this._focusMonitor = _focusMonitor;
|
---|
285 | this._radioDispatcher = _radioDispatcher;
|
---|
286 | this._providerOverride = _providerOverride;
|
---|
287 | this._uniqueId = `mat-radio-${++nextUniqueId}`;
|
---|
288 | /** The unique ID for the radio button. */
|
---|
289 | this.id = this._uniqueId;
|
---|
290 | /**
|
---|
291 | * Event emitted when the checked state of this radio button changes.
|
---|
292 | * Change events are only emitted when the value changes due to user interaction with
|
---|
293 | * the radio button (the same behavior as `<input type-"radio">`).
|
---|
294 | */
|
---|
295 | this.change = new EventEmitter();
|
---|
296 | /** Whether this radio is checked. */
|
---|
297 | this._checked = false;
|
---|
298 | /** Value assigned to this radio. */
|
---|
299 | this._value = null;
|
---|
300 | /** Unregister function for _radioDispatcher */
|
---|
301 | this._removeUniqueSelectionListener = () => { };
|
---|
302 | // Assertions. Ideally these should be stripped out by the compiler.
|
---|
303 | // TODO(jelbourn): Assert that there's no name binding AND a parent radio group.
|
---|
304 | this.radioGroup = radioGroup;
|
---|
305 | this._noopAnimations = animationMode === 'NoopAnimations';
|
---|
306 | if (tabIndex) {
|
---|
307 | this.tabIndex = coerceNumberProperty(tabIndex, 0);
|
---|
308 | }
|
---|
309 | this._removeUniqueSelectionListener =
|
---|
310 | _radioDispatcher.listen((id, name) => {
|
---|
311 | if (id !== this.id && name === this.name) {
|
---|
312 | this.checked = false;
|
---|
313 | }
|
---|
314 | });
|
---|
315 | }
|
---|
316 | /** Whether this radio button is checked. */
|
---|
317 | get checked() { return this._checked; }
|
---|
318 | set checked(value) {
|
---|
319 | const newCheckedState = coerceBooleanProperty(value);
|
---|
320 | if (this._checked !== newCheckedState) {
|
---|
321 | this._checked = newCheckedState;
|
---|
322 | if (newCheckedState && this.radioGroup && this.radioGroup.value !== this.value) {
|
---|
323 | this.radioGroup.selected = this;
|
---|
324 | }
|
---|
325 | else if (!newCheckedState && this.radioGroup && this.radioGroup.value === this.value) {
|
---|
326 | // When unchecking the selected radio button, update the selected radio
|
---|
327 | // property on the group.
|
---|
328 | this.radioGroup.selected = null;
|
---|
329 | }
|
---|
330 | if (newCheckedState) {
|
---|
331 | // Notify all radio buttons with the same name to un-check.
|
---|
332 | this._radioDispatcher.notify(this.id, this.name);
|
---|
333 | }
|
---|
334 | this._changeDetector.markForCheck();
|
---|
335 | }
|
---|
336 | }
|
---|
337 | /** The value of this radio button. */
|
---|
338 | get value() { return this._value; }
|
---|
339 | set value(value) {
|
---|
340 | if (this._value !== value) {
|
---|
341 | this._value = value;
|
---|
342 | if (this.radioGroup !== null) {
|
---|
343 | if (!this.checked) {
|
---|
344 | // Update checked when the value changed to match the radio group's value
|
---|
345 | this.checked = this.radioGroup.value === value;
|
---|
346 | }
|
---|
347 | if (this.checked) {
|
---|
348 | this.radioGroup.selected = this;
|
---|
349 | }
|
---|
350 | }
|
---|
351 | }
|
---|
352 | }
|
---|
353 | /** Whether the label should appear after or before the radio button. Defaults to 'after' */
|
---|
354 | get labelPosition() {
|
---|
355 | return this._labelPosition || (this.radioGroup && this.radioGroup.labelPosition) || 'after';
|
---|
356 | }
|
---|
357 | set labelPosition(value) {
|
---|
358 | this._labelPosition = value;
|
---|
359 | }
|
---|
360 | /** Whether the radio button is disabled. */
|
---|
361 | get disabled() {
|
---|
362 | return this._disabled || (this.radioGroup !== null && this.radioGroup.disabled);
|
---|
363 | }
|
---|
364 | set disabled(value) {
|
---|
365 | this._setDisabled(coerceBooleanProperty(value));
|
---|
366 | }
|
---|
367 | /** Whether the radio button is required. */
|
---|
368 | get required() {
|
---|
369 | return this._required || (this.radioGroup && this.radioGroup.required);
|
---|
370 | }
|
---|
371 | set required(value) {
|
---|
372 | this._required = coerceBooleanProperty(value);
|
---|
373 | }
|
---|
374 | /** Theme color of the radio button. */
|
---|
375 | get color() {
|
---|
376 | // As per Material design specifications the selection control radio should use the accent color
|
---|
377 | // palette by default. https://material.io/guidelines/components/selection-controls.html
|
---|
378 | return this._color ||
|
---|
379 | (this.radioGroup && this.radioGroup.color) ||
|
---|
380 | this._providerOverride && this._providerOverride.color || 'accent';
|
---|
381 | }
|
---|
382 | set color(newValue) { this._color = newValue; }
|
---|
383 | /** ID of the native input element inside `<mat-radio-button>` */
|
---|
384 | get inputId() { return `${this.id || this._uniqueId}-input`; }
|
---|
385 | /** Focuses the radio button. */
|
---|
386 | focus(options, origin) {
|
---|
387 | if (origin) {
|
---|
388 | this._focusMonitor.focusVia(this._inputElement, origin, options);
|
---|
389 | }
|
---|
390 | else {
|
---|
391 | this._inputElement.nativeElement.focus(options);
|
---|
392 | }
|
---|
393 | }
|
---|
394 | /**
|
---|
395 | * Marks the radio button as needing checking for change detection.
|
---|
396 | * This method is exposed because the parent radio group will directly
|
---|
397 | * update bound properties of the radio button.
|
---|
398 | */
|
---|
399 | _markForCheck() {
|
---|
400 | // When group value changes, the button will not be notified. Use `markForCheck` to explicit
|
---|
401 | // update radio button's status
|
---|
402 | this._changeDetector.markForCheck();
|
---|
403 | }
|
---|
404 | ngOnInit() {
|
---|
405 | if (this.radioGroup) {
|
---|
406 | // If the radio is inside a radio group, determine if it should be checked
|
---|
407 | this.checked = this.radioGroup.value === this._value;
|
---|
408 | if (this.checked) {
|
---|
409 | this.radioGroup.selected = this;
|
---|
410 | }
|
---|
411 | // Copy name from parent radio group
|
---|
412 | this.name = this.radioGroup.name;
|
---|
413 | }
|
---|
414 | }
|
---|
415 | ngAfterViewInit() {
|
---|
416 | this._focusMonitor
|
---|
417 | .monitor(this._elementRef, true)
|
---|
418 | .subscribe(focusOrigin => {
|
---|
419 | if (!focusOrigin && this.radioGroup) {
|
---|
420 | this.radioGroup._touch();
|
---|
421 | }
|
---|
422 | });
|
---|
423 | }
|
---|
424 | ngOnDestroy() {
|
---|
425 | this._focusMonitor.stopMonitoring(this._elementRef);
|
---|
426 | this._removeUniqueSelectionListener();
|
---|
427 | }
|
---|
428 | /** Dispatch change event with current value. */
|
---|
429 | _emitChangeEvent() {
|
---|
430 | this.change.emit(new MatRadioChange(this, this._value));
|
---|
431 | }
|
---|
432 | _isRippleDisabled() {
|
---|
433 | return this.disableRipple || this.disabled;
|
---|
434 | }
|
---|
435 | _onInputClick(event) {
|
---|
436 | // We have to stop propagation for click events on the visual hidden input element.
|
---|
437 | // By default, when a user clicks on a label element, a generated click event will be
|
---|
438 | // dispatched on the associated input element. Since we are using a label element as our
|
---|
439 | // root container, the click event on the `radio-button` will be executed twice.
|
---|
440 | // The real click event will bubble up, and the generated click event also tries to bubble up.
|
---|
441 | // This will lead to multiple click events.
|
---|
442 | // Preventing bubbling for the second event will solve that issue.
|
---|
443 | event.stopPropagation();
|
---|
444 | }
|
---|
445 | /** Triggered when the radio button receives an interaction from the user. */
|
---|
446 | _onInputInteraction(event) {
|
---|
447 | // We always have to stop propagation on the change event.
|
---|
448 | // Otherwise the change event, from the input element, will bubble up and
|
---|
449 | // emit its event object to the `change` output.
|
---|
450 | event.stopPropagation();
|
---|
451 | if (!this.checked && !this.disabled) {
|
---|
452 | const groupValueChanged = this.radioGroup && this.value !== this.radioGroup.value;
|
---|
453 | this.checked = true;
|
---|
454 | this._emitChangeEvent();
|
---|
455 | if (this.radioGroup) {
|
---|
456 | this.radioGroup._controlValueAccessorChangeFn(this.value);
|
---|
457 | if (groupValueChanged) {
|
---|
458 | this.radioGroup._emitChangeEvent();
|
---|
459 | }
|
---|
460 | }
|
---|
461 | }
|
---|
462 | }
|
---|
463 | /** Sets the disabled state and marks for check if a change occurred. */
|
---|
464 | _setDisabled(value) {
|
---|
465 | if (this._disabled !== value) {
|
---|
466 | this._disabled = value;
|
---|
467 | this._changeDetector.markForCheck();
|
---|
468 | }
|
---|
469 | }
|
---|
470 | }
|
---|
471 | _MatRadioButtonBase.decorators = [
|
---|
472 | { type: Directive }
|
---|
473 | ];
|
---|
474 | _MatRadioButtonBase.ctorParameters = () => [
|
---|
475 | { type: _MatRadioGroupBase },
|
---|
476 | { type: ElementRef },
|
---|
477 | { type: ChangeDetectorRef },
|
---|
478 | { type: FocusMonitor },
|
---|
479 | { type: UniqueSelectionDispatcher },
|
---|
480 | { type: String },
|
---|
481 | { type: undefined },
|
---|
482 | { type: String }
|
---|
483 | ];
|
---|
484 | _MatRadioButtonBase.propDecorators = {
|
---|
485 | id: [{ type: Input }],
|
---|
486 | name: [{ type: Input }],
|
---|
487 | ariaLabel: [{ type: Input, args: ['aria-label',] }],
|
---|
488 | ariaLabelledby: [{ type: Input, args: ['aria-labelledby',] }],
|
---|
489 | ariaDescribedby: [{ type: Input, args: ['aria-describedby',] }],
|
---|
490 | checked: [{ type: Input }],
|
---|
491 | value: [{ type: Input }],
|
---|
492 | labelPosition: [{ type: Input }],
|
---|
493 | disabled: [{ type: Input }],
|
---|
494 | required: [{ type: Input }],
|
---|
495 | color: [{ type: Input }],
|
---|
496 | change: [{ type: Output }],
|
---|
497 | _inputElement: [{ type: ViewChild, args: ['input',] }]
|
---|
498 | };
|
---|
499 | /**
|
---|
500 | * A Material design radio-button. Typically placed inside of `<mat-radio-group>` elements.
|
---|
501 | */
|
---|
502 | class MatRadioButton extends _MatRadioButtonBase {
|
---|
503 | constructor(radioGroup, elementRef, changeDetector, focusMonitor, radioDispatcher, animationMode, providerOverride, tabIndex) {
|
---|
504 | super(radioGroup, elementRef, changeDetector, focusMonitor, radioDispatcher, animationMode, providerOverride, tabIndex);
|
---|
505 | }
|
---|
506 | }
|
---|
507 | MatRadioButton.decorators = [
|
---|
508 | { type: Component, args: [{
|
---|
509 | selector: 'mat-radio-button',
|
---|
510 | template: "<!-- TODO(jelbourn): render the radio on either side of the content -->\n<!-- TODO(mtlin): Evaluate trade-offs of using native radio vs. cost of additional bindings. -->\n<label [attr.for]=\"inputId\" class=\"mat-radio-label\" #label>\n <!-- The actual 'radio' part of the control. -->\n <span class=\"mat-radio-container\">\n <span class=\"mat-radio-outer-circle\"></span>\n <span class=\"mat-radio-inner-circle\"></span>\n <input #input class=\"mat-radio-input cdk-visually-hidden\" type=\"radio\"\n [id]=\"inputId\"\n [checked]=\"checked\"\n [disabled]=\"disabled\"\n [tabIndex]=\"tabIndex\"\n [attr.name]=\"name\"\n [attr.value]=\"value\"\n [required]=\"required\"\n [attr.aria-label]=\"ariaLabel\"\n [attr.aria-labelledby]=\"ariaLabelledby\"\n [attr.aria-describedby]=\"ariaDescribedby\"\n (change)=\"_onInputInteraction($event)\"\n (click)=\"_onInputClick($event)\">\n\n <!-- The ripple comes after the input so that we can target it with a CSS\n sibling selector when the input is focused. -->\n <span mat-ripple class=\"mat-radio-ripple mat-focus-indicator\"\n [matRippleTrigger]=\"label\"\n [matRippleDisabled]=\"_isRippleDisabled()\"\n [matRippleCentered]=\"true\"\n [matRippleRadius]=\"20\"\n [matRippleAnimation]=\"{enterDuration: _noopAnimations ? 0 : 150}\">\n\n <span class=\"mat-ripple-element mat-radio-persistent-ripple\"></span>\n </span>\n </span>\n\n <!-- The label content for radio control. -->\n <span class=\"mat-radio-label-content\" [class.mat-radio-label-before]=\"labelPosition == 'before'\">\n <!-- Add an invisible span so JAWS can read the label -->\n <span style=\"display:none\"> </span>\n <ng-content></ng-content>\n </span>\n</label>\n",
|
---|
511 | inputs: ['disableRipple', 'tabIndex'],
|
---|
512 | encapsulation: ViewEncapsulation.None,
|
---|
513 | exportAs: 'matRadioButton',
|
---|
514 | host: {
|
---|
515 | 'class': 'mat-radio-button',
|
---|
516 | '[class.mat-radio-checked]': 'checked',
|
---|
517 | '[class.mat-radio-disabled]': 'disabled',
|
---|
518 | '[class._mat-animation-noopable]': '_noopAnimations',
|
---|
519 | '[class.mat-primary]': 'color === "primary"',
|
---|
520 | '[class.mat-accent]': 'color === "accent"',
|
---|
521 | '[class.mat-warn]': 'color === "warn"',
|
---|
522 | // Needs to be removed since it causes some a11y issues (see #21266).
|
---|
523 | '[attr.tabindex]': 'null',
|
---|
524 | '[attr.id]': 'id',
|
---|
525 | '[attr.aria-label]': 'null',
|
---|
526 | '[attr.aria-labelledby]': 'null',
|
---|
527 | '[attr.aria-describedby]': 'null',
|
---|
528 | // Note: under normal conditions focus shouldn't land on this element, however it may be
|
---|
529 | // programmatically set, for example inside of a focus trap, in this case we want to forward
|
---|
530 | // the focus to the native element.
|
---|
531 | '(focus)': '_inputElement.nativeElement.focus()',
|
---|
532 | },
|
---|
533 | changeDetection: ChangeDetectionStrategy.OnPush,
|
---|
534 | styles: [".mat-radio-button{display:inline-block;-webkit-tap-highlight-color:transparent;outline:0}.mat-radio-label{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:pointer;display:inline-flex;align-items:center;white-space:nowrap;vertical-align:middle;width:100%}.mat-radio-container{box-sizing:border-box;display:inline-block;position:relative;width:20px;height:20px;flex-shrink:0}.mat-radio-outer-circle{box-sizing:border-box;display:block;height:20px;left:0;position:absolute;top:0;transition:border-color ease 280ms;width:20px;border-width:2px;border-style:solid;border-radius:50%}._mat-animation-noopable .mat-radio-outer-circle{transition:none}.mat-radio-inner-circle{border-radius:50%;box-sizing:border-box;display:block;height:20px;left:0;position:absolute;top:0;opacity:0;transition:transform ease 280ms,background-color ease 280ms,opacity linear 1ms 280ms;width:20px;transform:scale(0.001);-webkit-print-color-adjust:exact;color-adjust:exact}.mat-radio-checked .mat-radio-inner-circle{transform:scale(0.5);opacity:1;transition:transform ease 280ms,background-color ease 280ms}.cdk-high-contrast-active .mat-radio-checked .mat-radio-inner-circle{border:solid 10px}._mat-animation-noopable .mat-radio-inner-circle{transition:none}.mat-radio-label-content{-webkit-user-select:auto;-moz-user-select:auto;-ms-user-select:auto;user-select:auto;display:inline-block;order:0;line-height:inherit;padding-left:8px;padding-right:0}[dir=rtl] .mat-radio-label-content{padding-right:8px;padding-left:0}.mat-radio-label-content.mat-radio-label-before{order:-1;padding-left:0;padding-right:8px}[dir=rtl] .mat-radio-label-content.mat-radio-label-before{padding-right:0;padding-left:8px}.mat-radio-disabled,.mat-radio-disabled .mat-radio-label{cursor:default}.mat-radio-button .mat-radio-ripple{position:absolute;left:calc(50% - 20px);top:calc(50% - 20px);height:40px;width:40px;z-index:1;pointer-events:none}.mat-radio-button .mat-radio-ripple .mat-ripple-element:not(.mat-radio-persistent-ripple){opacity:.16}.mat-radio-persistent-ripple{width:100%;height:100%;transform:none;top:0;left:0}.mat-radio-container:hover .mat-radio-persistent-ripple{opacity:.04}.mat-radio-button:not(.mat-radio-disabled).cdk-keyboard-focused .mat-radio-persistent-ripple,.mat-radio-button:not(.mat-radio-disabled).cdk-program-focused .mat-radio-persistent-ripple{opacity:.12}.mat-radio-persistent-ripple,.mat-radio-disabled .mat-radio-container:hover .mat-radio-persistent-ripple{opacity:0}@media(hover: none){.mat-radio-container:hover .mat-radio-persistent-ripple{display:none}}.mat-radio-input{bottom:0;left:50%}.cdk-high-contrast-active .mat-radio-button:not(.mat-radio-disabled).cdk-keyboard-focused .mat-radio-ripple,.cdk-high-contrast-active .mat-radio-button:not(.mat-radio-disabled).cdk-program-focused .mat-radio-ripple{outline:solid 3px}.cdk-high-contrast-active .mat-radio-disabled{opacity:.5}\n"]
|
---|
535 | },] }
|
---|
536 | ];
|
---|
537 | MatRadioButton.ctorParameters = () => [
|
---|
538 | { type: MatRadioGroup, decorators: [{ type: Optional }, { type: Inject, args: [MAT_RADIO_GROUP,] }] },
|
---|
539 | { type: ElementRef },
|
---|
540 | { type: ChangeDetectorRef },
|
---|
541 | { type: FocusMonitor },
|
---|
542 | { type: UniqueSelectionDispatcher },
|
---|
543 | { type: String, decorators: [{ type: Optional }, { type: Inject, args: [ANIMATION_MODULE_TYPE,] }] },
|
---|
544 | { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MAT_RADIO_DEFAULT_OPTIONS,] }] },
|
---|
545 | { type: String, decorators: [{ type: Attribute, args: ['tabindex',] }] }
|
---|
546 | ];
|
---|
547 |
|
---|
548 | /**
|
---|
549 | * @license
|
---|
550 | * Copyright Google LLC All Rights Reserved.
|
---|
551 | *
|
---|
552 | * Use of this source code is governed by an MIT-style license that can be
|
---|
553 | * found in the LICENSE file at https://angular.io/license
|
---|
554 | */
|
---|
555 | class MatRadioModule {
|
---|
556 | }
|
---|
557 | MatRadioModule.decorators = [
|
---|
558 | { type: NgModule, args: [{
|
---|
559 | imports: [MatRippleModule, MatCommonModule],
|
---|
560 | exports: [MatRadioGroup, MatRadioButton, MatCommonModule],
|
---|
561 | declarations: [MatRadioGroup, MatRadioButton],
|
---|
562 | },] }
|
---|
563 | ];
|
---|
564 |
|
---|
565 | /**
|
---|
566 | * @license
|
---|
567 | * Copyright Google LLC All Rights Reserved.
|
---|
568 | *
|
---|
569 | * Use of this source code is governed by an MIT-style license that can be
|
---|
570 | * found in the LICENSE file at https://angular.io/license
|
---|
571 | */
|
---|
572 |
|
---|
573 | /**
|
---|
574 | * Generated bundle index. Do not edit.
|
---|
575 | */
|
---|
576 |
|
---|
577 | export { MAT_RADIO_DEFAULT_OPTIONS, MAT_RADIO_DEFAULT_OPTIONS_FACTORY, MAT_RADIO_GROUP, MAT_RADIO_GROUP_CONTROL_VALUE_ACCESSOR, MatRadioButton, MatRadioChange, MatRadioGroup, MatRadioModule, _MatRadioButtonBase, _MatRadioGroupBase };
|
---|
578 | //# sourceMappingURL=radio.js.map
|
---|