material-radio.umd.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. (function (global, factory) {
  9. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/cdk/a11y'), require('@angular/cdk/coercion'), require('@angular/cdk/collections'), require('@angular/core'), require('@angular/forms'), require('@angular/material/core'), require('@angular/platform-browser/animations'), require('@angular/common')) :
  10. typeof define === 'function' && define.amd ? define('@angular/material/radio', ['exports', '@angular/cdk/a11y', '@angular/cdk/coercion', '@angular/cdk/collections', '@angular/core', '@angular/forms', '@angular/material/core', '@angular/platform-browser/animations', '@angular/common'], factory) :
  11. (factory((global.ng = global.ng || {}, global.ng.material = global.ng.material || {}, global.ng.material.radio = {}),global.ng.cdk.a11y,global.ng.cdk.coercion,global.ng.cdk.collections,global.ng.core,global.ng.forms,global.ng.material.core,global.ng.platformBrowser.animations,global.ng.common));
  12. }(this, (function (exports,a11y,coercion,collections,core,forms,core$1,animations,common) { 'use strict';
  13. /*! *****************************************************************************
  14. Copyright (c) Microsoft Corporation. All rights reserved.
  15. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  16. this file except in compliance with the License. You may obtain a copy of the
  17. License at http://www.apache.org/licenses/LICENSE-2.0
  18. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  20. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  21. MERCHANTABLITY OR NON-INFRINGEMENT.
  22. See the Apache Version 2.0 License for specific language governing permissions
  23. and limitations under the License.
  24. ***************************************************************************** */
  25. /* global Reflect, Promise */
  26. var extendStatics = function(d, b) {
  27. extendStatics = Object.setPrototypeOf ||
  28. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  29. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  30. return extendStatics(d, b);
  31. };
  32. function __extends(d, b) {
  33. extendStatics(d, b);
  34. function __() { this.constructor = d; }
  35. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  36. }
  37. /**
  38. * @fileoverview added by tsickle
  39. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  40. */
  41. /** @type {?} */
  42. var MAT_RADIO_DEFAULT_OPTIONS = new core.InjectionToken('mat-radio-default-options', {
  43. providedIn: 'root',
  44. factory: MAT_RADIO_DEFAULT_OPTIONS_FACTORY
  45. });
  46. /**
  47. * @return {?}
  48. */
  49. function MAT_RADIO_DEFAULT_OPTIONS_FACTORY() {
  50. return {
  51. color: 'accent'
  52. };
  53. }
  54. // Increasing integer for generating unique ids for radio components.
  55. /** @type {?} */
  56. var nextUniqueId = 0;
  57. /**
  58. * Provider Expression that allows mat-radio-group to register as a ControlValueAccessor. This
  59. * allows it to support [(ngModel)] and ngControl.
  60. * \@docs-private
  61. * @type {?}
  62. */
  63. var MAT_RADIO_GROUP_CONTROL_VALUE_ACCESSOR = {
  64. provide: forms.NG_VALUE_ACCESSOR,
  65. useExisting: core.forwardRef((/**
  66. * @return {?}
  67. */
  68. function () { return MatRadioGroup; })),
  69. multi: true
  70. };
  71. /**
  72. * Change event object emitted by MatRadio and MatRadioGroup.
  73. */
  74. var /**
  75. * Change event object emitted by MatRadio and MatRadioGroup.
  76. */
  77. MatRadioChange = /** @class */ (function () {
  78. function MatRadioChange(source, value) {
  79. this.source = source;
  80. this.value = value;
  81. }
  82. return MatRadioChange;
  83. }());
  84. /**
  85. * A group of radio buttons. May contain one or more `<mat-radio-button>` elements.
  86. */
  87. var MatRadioGroup = /** @class */ (function () {
  88. function MatRadioGroup(_changeDetector) {
  89. this._changeDetector = _changeDetector;
  90. /**
  91. * Selected value for the radio group.
  92. */
  93. this._value = null;
  94. /**
  95. * The HTML name attribute applied to radio buttons in this group.
  96. */
  97. this._name = "mat-radio-group-" + nextUniqueId++;
  98. /**
  99. * The currently selected radio button. Should match value.
  100. */
  101. this._selected = null;
  102. /**
  103. * Whether the `value` has been set to its initial value.
  104. */
  105. this._isInitialized = false;
  106. /**
  107. * Whether the labels should appear after or before the radio-buttons. Defaults to 'after'
  108. */
  109. this._labelPosition = 'after';
  110. /**
  111. * Whether the radio group is disabled.
  112. */
  113. this._disabled = false;
  114. /**
  115. * Whether the radio group is required.
  116. */
  117. this._required = false;
  118. /**
  119. * The method to be called in order to update ngModel
  120. */
  121. this._controlValueAccessorChangeFn = (/**
  122. * @return {?}
  123. */
  124. function () { });
  125. /**
  126. * onTouch function registered via registerOnTouch (ControlValueAccessor).
  127. * \@docs-private
  128. */
  129. this.onTouched = (/**
  130. * @return {?}
  131. */
  132. function () { });
  133. /**
  134. * Event emitted when the group value changes.
  135. * Change events are only emitted when the value changes due to user interaction with
  136. * a radio button (the same behavior as `<input type-"radio">`).
  137. */
  138. this.change = new core.EventEmitter();
  139. }
  140. Object.defineProperty(MatRadioGroup.prototype, "name", {
  141. /** Name of the radio button group. All radio buttons inside this group will use this name. */
  142. get: /**
  143. * Name of the radio button group. All radio buttons inside this group will use this name.
  144. * @return {?}
  145. */
  146. function () { return this._name; },
  147. set: /**
  148. * @param {?} value
  149. * @return {?}
  150. */
  151. function (value) {
  152. this._name = value;
  153. this._updateRadioButtonNames();
  154. },
  155. enumerable: true,
  156. configurable: true
  157. });
  158. Object.defineProperty(MatRadioGroup.prototype, "labelPosition", {
  159. /** Whether the labels should appear after or before the radio-buttons. Defaults to 'after' */
  160. get: /**
  161. * Whether the labels should appear after or before the radio-buttons. Defaults to 'after'
  162. * @return {?}
  163. */
  164. function () {
  165. return this._labelPosition;
  166. },
  167. set: /**
  168. * @param {?} v
  169. * @return {?}
  170. */
  171. function (v) {
  172. this._labelPosition = v === 'before' ? 'before' : 'after';
  173. this._markRadiosForCheck();
  174. },
  175. enumerable: true,
  176. configurable: true
  177. });
  178. Object.defineProperty(MatRadioGroup.prototype, "value", {
  179. /**
  180. * Value for the radio-group. Should equal the value of the selected radio button if there is
  181. * a corresponding radio button with a matching value. If there is not such a corresponding
  182. * radio button, this value persists to be applied in case a new radio button is added with a
  183. * matching value.
  184. */
  185. get: /**
  186. * Value for the radio-group. Should equal the value of the selected radio button if there is
  187. * a corresponding radio button with a matching value. If there is not such a corresponding
  188. * radio button, this value persists to be applied in case a new radio button is added with a
  189. * matching value.
  190. * @return {?}
  191. */
  192. function () { return this._value; },
  193. set: /**
  194. * @param {?} newValue
  195. * @return {?}
  196. */
  197. function (newValue) {
  198. if (this._value !== newValue) {
  199. // Set this before proceeding to ensure no circular loop occurs with selection.
  200. this._value = newValue;
  201. this._updateSelectedRadioFromValue();
  202. this._checkSelectedRadioButton();
  203. }
  204. },
  205. enumerable: true,
  206. configurable: true
  207. });
  208. /**
  209. * @return {?}
  210. */
  211. MatRadioGroup.prototype._checkSelectedRadioButton = /**
  212. * @return {?}
  213. */
  214. function () {
  215. if (this._selected && !this._selected.checked) {
  216. this._selected.checked = true;
  217. }
  218. };
  219. Object.defineProperty(MatRadioGroup.prototype, "selected", {
  220. /**
  221. * The currently selected radio button. If set to a new radio button, the radio group value
  222. * will be updated to match the new selected button.
  223. */
  224. get: /**
  225. * The currently selected radio button. If set to a new radio button, the radio group value
  226. * will be updated to match the new selected button.
  227. * @return {?}
  228. */
  229. function () { return this._selected; },
  230. set: /**
  231. * @param {?} selected
  232. * @return {?}
  233. */
  234. function (selected) {
  235. this._selected = selected;
  236. this.value = selected ? selected.value : null;
  237. this._checkSelectedRadioButton();
  238. },
  239. enumerable: true,
  240. configurable: true
  241. });
  242. Object.defineProperty(MatRadioGroup.prototype, "disabled", {
  243. /** Whether the radio group is disabled */
  244. get: /**
  245. * Whether the radio group is disabled
  246. * @return {?}
  247. */
  248. function () { return this._disabled; },
  249. set: /**
  250. * @param {?} value
  251. * @return {?}
  252. */
  253. function (value) {
  254. this._disabled = coercion.coerceBooleanProperty(value);
  255. this._markRadiosForCheck();
  256. },
  257. enumerable: true,
  258. configurable: true
  259. });
  260. Object.defineProperty(MatRadioGroup.prototype, "required", {
  261. /** Whether the radio group is required */
  262. get: /**
  263. * Whether the radio group is required
  264. * @return {?}
  265. */
  266. function () { return this._required; },
  267. set: /**
  268. * @param {?} value
  269. * @return {?}
  270. */
  271. function (value) {
  272. this._required = coercion.coerceBooleanProperty(value);
  273. this._markRadiosForCheck();
  274. },
  275. enumerable: true,
  276. configurable: true
  277. });
  278. /**
  279. * Initialize properties once content children are available.
  280. * This allows us to propagate relevant attributes to associated buttons.
  281. */
  282. /**
  283. * Initialize properties once content children are available.
  284. * This allows us to propagate relevant attributes to associated buttons.
  285. * @return {?}
  286. */
  287. MatRadioGroup.prototype.ngAfterContentInit = /**
  288. * Initialize properties once content children are available.
  289. * This allows us to propagate relevant attributes to associated buttons.
  290. * @return {?}
  291. */
  292. function () {
  293. // Mark this component as initialized in AfterContentInit because the initial value can
  294. // possibly be set by NgModel on MatRadioGroup, and it is possible that the OnInit of the
  295. // NgModel occurs *after* the OnInit of the MatRadioGroup.
  296. this._isInitialized = true;
  297. };
  298. /**
  299. * Mark this group as being "touched" (for ngModel). Meant to be called by the contained
  300. * radio buttons upon their blur.
  301. */
  302. /**
  303. * Mark this group as being "touched" (for ngModel). Meant to be called by the contained
  304. * radio buttons upon their blur.
  305. * @return {?}
  306. */
  307. MatRadioGroup.prototype._touch = /**
  308. * Mark this group as being "touched" (for ngModel). Meant to be called by the contained
  309. * radio buttons upon their blur.
  310. * @return {?}
  311. */
  312. function () {
  313. if (this.onTouched) {
  314. this.onTouched();
  315. }
  316. };
  317. /**
  318. * @private
  319. * @return {?}
  320. */
  321. MatRadioGroup.prototype._updateRadioButtonNames = /**
  322. * @private
  323. * @return {?}
  324. */
  325. function () {
  326. var _this = this;
  327. if (this._radios) {
  328. this._radios.forEach((/**
  329. * @param {?} radio
  330. * @return {?}
  331. */
  332. function (radio) {
  333. radio.name = _this.name;
  334. radio._markForCheck();
  335. }));
  336. }
  337. };
  338. /** Updates the `selected` radio button from the internal _value state. */
  339. /**
  340. * Updates the `selected` radio button from the internal _value state.
  341. * @private
  342. * @return {?}
  343. */
  344. MatRadioGroup.prototype._updateSelectedRadioFromValue = /**
  345. * Updates the `selected` radio button from the internal _value state.
  346. * @private
  347. * @return {?}
  348. */
  349. function () {
  350. var _this = this;
  351. // If the value already matches the selected radio, do nothing.
  352. /** @type {?} */
  353. var isAlreadySelected = this._selected !== null && this._selected.value === this._value;
  354. if (this._radios && !isAlreadySelected) {
  355. this._selected = null;
  356. this._radios.forEach((/**
  357. * @param {?} radio
  358. * @return {?}
  359. */
  360. function (radio) {
  361. radio.checked = _this.value === radio.value;
  362. if (radio.checked) {
  363. _this._selected = radio;
  364. }
  365. }));
  366. }
  367. };
  368. /** Dispatch change event with current selection and group value. */
  369. /**
  370. * Dispatch change event with current selection and group value.
  371. * @return {?}
  372. */
  373. MatRadioGroup.prototype._emitChangeEvent = /**
  374. * Dispatch change event with current selection and group value.
  375. * @return {?}
  376. */
  377. function () {
  378. if (this._isInitialized) {
  379. this.change.emit(new MatRadioChange((/** @type {?} */ (this._selected)), this._value));
  380. }
  381. };
  382. /**
  383. * @return {?}
  384. */
  385. MatRadioGroup.prototype._markRadiosForCheck = /**
  386. * @return {?}
  387. */
  388. function () {
  389. if (this._radios) {
  390. this._radios.forEach((/**
  391. * @param {?} radio
  392. * @return {?}
  393. */
  394. function (radio) { return radio._markForCheck(); }));
  395. }
  396. };
  397. /**
  398. * Sets the model value. Implemented as part of ControlValueAccessor.
  399. * @param value
  400. */
  401. /**
  402. * Sets the model value. Implemented as part of ControlValueAccessor.
  403. * @param {?} value
  404. * @return {?}
  405. */
  406. MatRadioGroup.prototype.writeValue = /**
  407. * Sets the model value. Implemented as part of ControlValueAccessor.
  408. * @param {?} value
  409. * @return {?}
  410. */
  411. function (value) {
  412. this.value = value;
  413. this._changeDetector.markForCheck();
  414. };
  415. /**
  416. * Registers a callback to be triggered when the model value changes.
  417. * Implemented as part of ControlValueAccessor.
  418. * @param fn Callback to be registered.
  419. */
  420. /**
  421. * Registers a callback to be triggered when the model value changes.
  422. * Implemented as part of ControlValueAccessor.
  423. * @param {?} fn Callback to be registered.
  424. * @return {?}
  425. */
  426. MatRadioGroup.prototype.registerOnChange = /**
  427. * Registers a callback to be triggered when the model value changes.
  428. * Implemented as part of ControlValueAccessor.
  429. * @param {?} fn Callback to be registered.
  430. * @return {?}
  431. */
  432. function (fn) {
  433. this._controlValueAccessorChangeFn = fn;
  434. };
  435. /**
  436. * Registers a callback to be triggered when the control is touched.
  437. * Implemented as part of ControlValueAccessor.
  438. * @param fn Callback to be registered.
  439. */
  440. /**
  441. * Registers a callback to be triggered when the control is touched.
  442. * Implemented as part of ControlValueAccessor.
  443. * @param {?} fn Callback to be registered.
  444. * @return {?}
  445. */
  446. MatRadioGroup.prototype.registerOnTouched = /**
  447. * Registers a callback to be triggered when the control is touched.
  448. * Implemented as part of ControlValueAccessor.
  449. * @param {?} fn Callback to be registered.
  450. * @return {?}
  451. */
  452. function (fn) {
  453. this.onTouched = fn;
  454. };
  455. /**
  456. * Sets the disabled state of the control. Implemented as a part of ControlValueAccessor.
  457. * @param isDisabled Whether the control should be disabled.
  458. */
  459. /**
  460. * Sets the disabled state of the control. Implemented as a part of ControlValueAccessor.
  461. * @param {?} isDisabled Whether the control should be disabled.
  462. * @return {?}
  463. */
  464. MatRadioGroup.prototype.setDisabledState = /**
  465. * Sets the disabled state of the control. Implemented as a part of ControlValueAccessor.
  466. * @param {?} isDisabled Whether the control should be disabled.
  467. * @return {?}
  468. */
  469. function (isDisabled) {
  470. this.disabled = isDisabled;
  471. this._changeDetector.markForCheck();
  472. };
  473. MatRadioGroup.decorators = [
  474. { type: core.Directive, args: [{
  475. selector: 'mat-radio-group',
  476. exportAs: 'matRadioGroup',
  477. providers: [MAT_RADIO_GROUP_CONTROL_VALUE_ACCESSOR],
  478. host: {
  479. 'role': 'radiogroup',
  480. 'class': 'mat-radio-group',
  481. },
  482. },] },
  483. ];
  484. /** @nocollapse */
  485. MatRadioGroup.ctorParameters = function () { return [
  486. { type: core.ChangeDetectorRef }
  487. ]; };
  488. MatRadioGroup.propDecorators = {
  489. change: [{ type: core.Output }],
  490. _radios: [{ type: core.ContentChildren, args: [core.forwardRef((/**
  491. * @return {?}
  492. */
  493. function () { return MatRadioButton; })), { descendants: true },] }],
  494. color: [{ type: core.Input }],
  495. name: [{ type: core.Input }],
  496. labelPosition: [{ type: core.Input }],
  497. value: [{ type: core.Input }],
  498. selected: [{ type: core.Input }],
  499. disabled: [{ type: core.Input }],
  500. required: [{ type: core.Input }]
  501. };
  502. return MatRadioGroup;
  503. }());
  504. // Boilerplate for applying mixins to MatRadioButton.
  505. /**
  506. * \@docs-private
  507. */
  508. var
  509. // Boilerplate for applying mixins to MatRadioButton.
  510. /**
  511. * \@docs-private
  512. */
  513. MatRadioButtonBase = /** @class */ (function () {
  514. function MatRadioButtonBase(_elementRef) {
  515. this._elementRef = _elementRef;
  516. }
  517. return MatRadioButtonBase;
  518. }());
  519. // As per Material design specifications the selection control radio should use the accent color
  520. // palette by default. https://material.io/guidelines/components/selection-controls.html
  521. /** @type {?} */
  522. var _MatRadioButtonMixinBase = core$1.mixinDisableRipple(core$1.mixinTabIndex(MatRadioButtonBase));
  523. /**
  524. * A Material design radio-button. Typically placed inside of `<mat-radio-group>` elements.
  525. */
  526. var MatRadioButton = /** @class */ (function (_super) {
  527. __extends(MatRadioButton, _super);
  528. function MatRadioButton(radioGroup, elementRef, _changeDetector, _focusMonitor, _radioDispatcher, _animationMode, _providerOverride) {
  529. var _this = _super.call(this, elementRef) || this;
  530. _this._changeDetector = _changeDetector;
  531. _this._focusMonitor = _focusMonitor;
  532. _this._radioDispatcher = _radioDispatcher;
  533. _this._animationMode = _animationMode;
  534. _this._providerOverride = _providerOverride;
  535. _this._uniqueId = "mat-radio-" + ++nextUniqueId;
  536. /**
  537. * The unique ID for the radio button.
  538. */
  539. _this.id = _this._uniqueId;
  540. /**
  541. * Event emitted when the checked state of this radio button changes.
  542. * Change events are only emitted when the value changes due to user interaction with
  543. * the radio button (the same behavior as `<input type-"radio">`).
  544. */
  545. _this.change = new core.EventEmitter();
  546. /**
  547. * Whether this radio is checked.
  548. */
  549. _this._checked = false;
  550. /**
  551. * Value assigned to this radio.
  552. */
  553. _this._value = null;
  554. /**
  555. * Unregister function for _radioDispatcher
  556. */
  557. _this._removeUniqueSelectionListener = (/**
  558. * @return {?}
  559. */
  560. function () { });
  561. // Assertions. Ideally these should be stripped out by the compiler.
  562. // TODO(jelbourn): Assert that there's no name binding AND a parent radio group.
  563. _this.radioGroup = radioGroup;
  564. _this._removeUniqueSelectionListener =
  565. _radioDispatcher.listen((/**
  566. * @param {?} id
  567. * @param {?} name
  568. * @return {?}
  569. */
  570. function (id, name) {
  571. if (id !== _this.id && name === _this.name) {
  572. _this.checked = false;
  573. }
  574. }));
  575. return _this;
  576. }
  577. Object.defineProperty(MatRadioButton.prototype, "checked", {
  578. /** Whether this radio button is checked. */
  579. get: /**
  580. * Whether this radio button is checked.
  581. * @return {?}
  582. */
  583. function () { return this._checked; },
  584. set: /**
  585. * @param {?} value
  586. * @return {?}
  587. */
  588. function (value) {
  589. /** @type {?} */
  590. var newCheckedState = coercion.coerceBooleanProperty(value);
  591. if (this._checked !== newCheckedState) {
  592. this._checked = newCheckedState;
  593. if (newCheckedState && this.radioGroup && this.radioGroup.value !== this.value) {
  594. this.radioGroup.selected = this;
  595. }
  596. else if (!newCheckedState && this.radioGroup && this.radioGroup.value === this.value) {
  597. // When unchecking the selected radio button, update the selected radio
  598. // property on the group.
  599. this.radioGroup.selected = null;
  600. }
  601. if (newCheckedState) {
  602. // Notify all radio buttons with the same name to un-check.
  603. this._radioDispatcher.notify(this.id, this.name);
  604. }
  605. this._changeDetector.markForCheck();
  606. }
  607. },
  608. enumerable: true,
  609. configurable: true
  610. });
  611. Object.defineProperty(MatRadioButton.prototype, "value", {
  612. /** The value of this radio button. */
  613. get: /**
  614. * The value of this radio button.
  615. * @return {?}
  616. */
  617. function () { return this._value; },
  618. set: /**
  619. * @param {?} value
  620. * @return {?}
  621. */
  622. function (value) {
  623. if (this._value !== value) {
  624. this._value = value;
  625. if (this.radioGroup !== null) {
  626. if (!this.checked) {
  627. // Update checked when the value changed to match the radio group's value
  628. this.checked = this.radioGroup.value === value;
  629. }
  630. if (this.checked) {
  631. this.radioGroup.selected = this;
  632. }
  633. }
  634. }
  635. },
  636. enumerable: true,
  637. configurable: true
  638. });
  639. Object.defineProperty(MatRadioButton.prototype, "labelPosition", {
  640. /** Whether the label should appear after or before the radio button. Defaults to 'after' */
  641. get: /**
  642. * Whether the label should appear after or before the radio button. Defaults to 'after'
  643. * @return {?}
  644. */
  645. function () {
  646. return this._labelPosition || (this.radioGroup && this.radioGroup.labelPosition) || 'after';
  647. },
  648. set: /**
  649. * @param {?} value
  650. * @return {?}
  651. */
  652. function (value) {
  653. this._labelPosition = value;
  654. },
  655. enumerable: true,
  656. configurable: true
  657. });
  658. Object.defineProperty(MatRadioButton.prototype, "disabled", {
  659. /** Whether the radio button is disabled. */
  660. get: /**
  661. * Whether the radio button is disabled.
  662. * @return {?}
  663. */
  664. function () {
  665. return this._disabled || (this.radioGroup !== null && this.radioGroup.disabled);
  666. },
  667. set: /**
  668. * @param {?} value
  669. * @return {?}
  670. */
  671. function (value) {
  672. /** @type {?} */
  673. var newDisabledState = coercion.coerceBooleanProperty(value);
  674. if (this._disabled !== newDisabledState) {
  675. this._disabled = newDisabledState;
  676. this._changeDetector.markForCheck();
  677. }
  678. },
  679. enumerable: true,
  680. configurable: true
  681. });
  682. Object.defineProperty(MatRadioButton.prototype, "required", {
  683. /** Whether the radio button is required. */
  684. get: /**
  685. * Whether the radio button is required.
  686. * @return {?}
  687. */
  688. function () {
  689. return this._required || (this.radioGroup && this.radioGroup.required);
  690. },
  691. set: /**
  692. * @param {?} value
  693. * @return {?}
  694. */
  695. function (value) {
  696. this._required = coercion.coerceBooleanProperty(value);
  697. },
  698. enumerable: true,
  699. configurable: true
  700. });
  701. Object.defineProperty(MatRadioButton.prototype, "color", {
  702. /** Theme color of the radio button. */
  703. get: /**
  704. * Theme color of the radio button.
  705. * @return {?}
  706. */
  707. function () {
  708. return this._color ||
  709. (this.radioGroup && this.radioGroup.color) ||
  710. this._providerOverride && this._providerOverride.color || 'accent';
  711. },
  712. set: /**
  713. * @param {?} newValue
  714. * @return {?}
  715. */
  716. function (newValue) { this._color = newValue; },
  717. enumerable: true,
  718. configurable: true
  719. });
  720. Object.defineProperty(MatRadioButton.prototype, "inputId", {
  721. /** ID of the native input element inside `<mat-radio-button>` */
  722. get: /**
  723. * ID of the native input element inside `<mat-radio-button>`
  724. * @return {?}
  725. */
  726. function () { return (this.id || this._uniqueId) + "-input"; },
  727. enumerable: true,
  728. configurable: true
  729. });
  730. /** Focuses the radio button. */
  731. /**
  732. * Focuses the radio button.
  733. * @param {?=} options
  734. * @return {?}
  735. */
  736. MatRadioButton.prototype.focus = /**
  737. * Focuses the radio button.
  738. * @param {?=} options
  739. * @return {?}
  740. */
  741. function (options) {
  742. this._focusMonitor.focusVia(this._inputElement, 'keyboard', options);
  743. };
  744. /**
  745. * Marks the radio button as needing checking for change detection.
  746. * This method is exposed because the parent radio group will directly
  747. * update bound properties of the radio button.
  748. */
  749. /**
  750. * Marks the radio button as needing checking for change detection.
  751. * This method is exposed because the parent radio group will directly
  752. * update bound properties of the radio button.
  753. * @return {?}
  754. */
  755. MatRadioButton.prototype._markForCheck = /**
  756. * Marks the radio button as needing checking for change detection.
  757. * This method is exposed because the parent radio group will directly
  758. * update bound properties of the radio button.
  759. * @return {?}
  760. */
  761. function () {
  762. // When group value changes, the button will not be notified. Use `markForCheck` to explicit
  763. // update radio button's status
  764. this._changeDetector.markForCheck();
  765. };
  766. /**
  767. * @return {?}
  768. */
  769. MatRadioButton.prototype.ngOnInit = /**
  770. * @return {?}
  771. */
  772. function () {
  773. if (this.radioGroup) {
  774. // If the radio is inside a radio group, determine if it should be checked
  775. this.checked = this.radioGroup.value === this._value;
  776. // Copy name from parent radio group
  777. this.name = this.radioGroup.name;
  778. }
  779. };
  780. /**
  781. * @return {?}
  782. */
  783. MatRadioButton.prototype.ngAfterViewInit = /**
  784. * @return {?}
  785. */
  786. function () {
  787. var _this = this;
  788. this._focusMonitor
  789. .monitor(this._elementRef, true)
  790. .subscribe((/**
  791. * @param {?} focusOrigin
  792. * @return {?}
  793. */
  794. function (focusOrigin) {
  795. if (!focusOrigin && _this.radioGroup) {
  796. _this.radioGroup._touch();
  797. }
  798. }));
  799. };
  800. /**
  801. * @return {?}
  802. */
  803. MatRadioButton.prototype.ngOnDestroy = /**
  804. * @return {?}
  805. */
  806. function () {
  807. this._focusMonitor.stopMonitoring(this._elementRef);
  808. this._removeUniqueSelectionListener();
  809. };
  810. /** Dispatch change event with current value. */
  811. /**
  812. * Dispatch change event with current value.
  813. * @private
  814. * @return {?}
  815. */
  816. MatRadioButton.prototype._emitChangeEvent = /**
  817. * Dispatch change event with current value.
  818. * @private
  819. * @return {?}
  820. */
  821. function () {
  822. this.change.emit(new MatRadioChange(this, this._value));
  823. };
  824. /**
  825. * @return {?}
  826. */
  827. MatRadioButton.prototype._isRippleDisabled = /**
  828. * @return {?}
  829. */
  830. function () {
  831. return this.disableRipple || this.disabled;
  832. };
  833. /**
  834. * @param {?} event
  835. * @return {?}
  836. */
  837. MatRadioButton.prototype._onInputClick = /**
  838. * @param {?} event
  839. * @return {?}
  840. */
  841. function (event) {
  842. // We have to stop propagation for click events on the visual hidden input element.
  843. // By default, when a user clicks on a label element, a generated click event will be
  844. // dispatched on the associated input element. Since we are using a label element as our
  845. // root container, the click event on the `radio-button` will be executed twice.
  846. // The real click event will bubble up, and the generated click event also tries to bubble up.
  847. // This will lead to multiple click events.
  848. // Preventing bubbling for the second event will solve that issue.
  849. event.stopPropagation();
  850. };
  851. /**
  852. * Triggered when the radio button received a click or the input recognized any change.
  853. * Clicking on a label element, will trigger a change event on the associated input.
  854. */
  855. /**
  856. * Triggered when the radio button received a click or the input recognized any change.
  857. * Clicking on a label element, will trigger a change event on the associated input.
  858. * @param {?} event
  859. * @return {?}
  860. */
  861. MatRadioButton.prototype._onInputChange = /**
  862. * Triggered when the radio button received a click or the input recognized any change.
  863. * Clicking on a label element, will trigger a change event on the associated input.
  864. * @param {?} event
  865. * @return {?}
  866. */
  867. function (event) {
  868. // We always have to stop propagation on the change event.
  869. // Otherwise the change event, from the input element, will bubble up and
  870. // emit its event object to the `change` output.
  871. event.stopPropagation();
  872. /** @type {?} */
  873. var groupValueChanged = this.radioGroup && this.value !== this.radioGroup.value;
  874. this.checked = true;
  875. this._emitChangeEvent();
  876. if (this.radioGroup) {
  877. this.radioGroup._controlValueAccessorChangeFn(this.value);
  878. if (groupValueChanged) {
  879. this.radioGroup._emitChangeEvent();
  880. }
  881. }
  882. };
  883. MatRadioButton.decorators = [
  884. { type: core.Component, args: [{selector: 'mat-radio-button',
  885. template: "<label [attr.for]=\"inputId\" class=\"mat-radio-label\" #label><div class=\"mat-radio-container\"><div class=\"mat-radio-outer-circle\"></div><div class=\"mat-radio-inner-circle\"></div><div mat-ripple class=\"mat-radio-ripple\" [matRippleTrigger]=\"label\" [matRippleDisabled]=\"_isRippleDisabled()\" [matRippleCentered]=\"true\" [matRippleRadius]=\"20\" [matRippleAnimation]=\"{enterDuration: 150}\"><div class=\"mat-ripple-element mat-radio-persistent-ripple\"></div></div><input #input class=\"mat-radio-input cdk-visually-hidden\" type=\"radio\" [id]=\"inputId\" [checked]=\"checked\" [disabled]=\"disabled\" [tabIndex]=\"tabIndex\" [attr.name]=\"name\" [attr.value]=\"value\" [required]=\"required\" [attr.aria-label]=\"ariaLabel\" [attr.aria-labelledby]=\"ariaLabelledby\" [attr.aria-describedby]=\"ariaDescribedby\" (change)=\"_onInputChange($event)\" (click)=\"_onInputClick($event)\"></div><div class=\"mat-radio-label-content\" [class.mat-radio-label-before]=\"labelPosition == 'before'\"><span style=\"display:none\">&nbsp;</span><ng-content></ng-content></div></label>",
  886. 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;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;height:20px;left:0;position:absolute;top:0;transition:transform ease 280ms,background-color ease 280ms;width:20px;transform:scale(.001)}._mat-animation-noopable .mat-radio-inner-circle{transition:none}.mat-radio-checked .mat-radio-inner-circle{transform:scale(.5)}@media (-ms-high-contrast:active){.mat-radio-checked .mat-radio-inner-circle{border:solid 10px}}.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}.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-disabled .mat-radio-container:hover .mat-radio-persistent-ripple,.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%}@media (-ms-high-contrast:active){.mat-radio-disabled{opacity:.5}}"],
  887. inputs: ['disableRipple', 'tabIndex'],
  888. encapsulation: core.ViewEncapsulation.None,
  889. exportAs: 'matRadioButton',
  890. host: {
  891. 'class': 'mat-radio-button',
  892. '[class.mat-radio-checked]': 'checked',
  893. '[class.mat-radio-disabled]': 'disabled',
  894. '[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
  895. '[class.mat-primary]': 'color === "primary"',
  896. '[class.mat-accent]': 'color === "accent"',
  897. '[class.mat-warn]': 'color === "warn"',
  898. // Needs to be -1 so the `focus` event still fires.
  899. '[attr.tabindex]': '-1',
  900. '[attr.id]': 'id',
  901. // Note: under normal conditions focus shouldn't land on this element, however it may be
  902. // programmatically set, for example inside of a focus trap, in this case we want to forward
  903. // the focus to the native element.
  904. '(focus)': '_inputElement.nativeElement.focus()',
  905. },
  906. changeDetection: core.ChangeDetectionStrategy.OnPush,
  907. },] },
  908. ];
  909. /** @nocollapse */
  910. MatRadioButton.ctorParameters = function () { return [
  911. { type: MatRadioGroup, decorators: [{ type: core.Optional }] },
  912. { type: core.ElementRef },
  913. { type: core.ChangeDetectorRef },
  914. { type: a11y.FocusMonitor },
  915. { type: collections.UniqueSelectionDispatcher },
  916. { type: String, decorators: [{ type: core.Optional }, { type: core.Inject, args: [animations.ANIMATION_MODULE_TYPE,] }] },
  917. { type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [MAT_RADIO_DEFAULT_OPTIONS,] }] }
  918. ]; };
  919. MatRadioButton.propDecorators = {
  920. id: [{ type: core.Input }],
  921. name: [{ type: core.Input }],
  922. ariaLabel: [{ type: core.Input, args: ['aria-label',] }],
  923. ariaLabelledby: [{ type: core.Input, args: ['aria-labelledby',] }],
  924. ariaDescribedby: [{ type: core.Input, args: ['aria-describedby',] }],
  925. checked: [{ type: core.Input }],
  926. value: [{ type: core.Input }],
  927. labelPosition: [{ type: core.Input }],
  928. disabled: [{ type: core.Input }],
  929. required: [{ type: core.Input }],
  930. color: [{ type: core.Input }],
  931. change: [{ type: core.Output }],
  932. _inputElement: [{ type: core.ViewChild, args: ['input', { static: false },] }]
  933. };
  934. return MatRadioButton;
  935. }(_MatRadioButtonMixinBase));
  936. /**
  937. * @fileoverview added by tsickle
  938. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  939. */
  940. var MatRadioModule = /** @class */ (function () {
  941. function MatRadioModule() {
  942. }
  943. MatRadioModule.decorators = [
  944. { type: core.NgModule, args: [{
  945. imports: [common.CommonModule, core$1.MatRippleModule, core$1.MatCommonModule],
  946. exports: [MatRadioGroup, MatRadioButton, core$1.MatCommonModule],
  947. declarations: [MatRadioGroup, MatRadioButton],
  948. },] },
  949. ];
  950. return MatRadioModule;
  951. }());
  952. exports.MatRadioModule = MatRadioModule;
  953. exports.MAT_RADIO_DEFAULT_OPTIONS_FACTORY = MAT_RADIO_DEFAULT_OPTIONS_FACTORY;
  954. exports.MAT_RADIO_DEFAULT_OPTIONS = MAT_RADIO_DEFAULT_OPTIONS;
  955. exports.MAT_RADIO_GROUP_CONTROL_VALUE_ACCESSOR = MAT_RADIO_GROUP_CONTROL_VALUE_ACCESSOR;
  956. exports.MatRadioChange = MatRadioChange;
  957. exports.MatRadioGroup = MatRadioGroup;
  958. exports.MatRadioButton = MatRadioButton;
  959. Object.defineProperty(exports, '__esModule', { value: true });
  960. })));
  961. //# sourceMappingURL=material-radio.umd.js.map