material-checkbox.umd.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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/core'), require('@angular/cdk/a11y'), require('@angular/cdk/coercion'), require('@angular/forms'), require('@angular/material/core'), require('@angular/platform-browser/animations'), require('@angular/cdk/observers'), require('@angular/common')) :
  10. typeof define === 'function' && define.amd ? define('@angular/material/checkbox', ['exports', '@angular/core', '@angular/cdk/a11y', '@angular/cdk/coercion', '@angular/forms', '@angular/material/core', '@angular/platform-browser/animations', '@angular/cdk/observers', '@angular/common'], factory) :
  11. (factory((global.ng = global.ng || {}, global.ng.material = global.ng.material || {}, global.ng.material.checkbox = {}),global.ng.core,global.ng.cdk.a11y,global.ng.cdk.coercion,global.ng.forms,global.ng.material.core,global.ng.platformBrowser.animations,global.ng.cdk.observers,global.ng.common));
  12. }(this, (function (exports,core,a11y,coercion,forms,core$1,animations,observers,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. /**
  42. * Injection token that can be used to specify the checkbox click behavior.
  43. * @type {?}
  44. */
  45. var MAT_CHECKBOX_CLICK_ACTION = new core.InjectionToken('mat-checkbox-click-action');
  46. /**
  47. * @fileoverview added by tsickle
  48. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  49. */
  50. // Increasing integer for generating unique ids for checkbox components.
  51. /** @type {?} */
  52. var nextUniqueId = 0;
  53. /**
  54. * Provider Expression that allows mat-checkbox to register as a ControlValueAccessor.
  55. * This allows it to support [(ngModel)].
  56. * \@docs-private
  57. * @type {?}
  58. */
  59. var MAT_CHECKBOX_CONTROL_VALUE_ACCESSOR = {
  60. provide: forms.NG_VALUE_ACCESSOR,
  61. useExisting: core.forwardRef((/**
  62. * @return {?}
  63. */
  64. function () { return MatCheckbox; })),
  65. multi: true
  66. };
  67. /** @enum {number} */
  68. var TransitionCheckState = {
  69. /** The initial state of the component before any user interaction. */
  70. Init: 0,
  71. /** The state representing the component when it's becoming checked. */
  72. Checked: 1,
  73. /** The state representing the component when it's becoming unchecked. */
  74. Unchecked: 2,
  75. /** The state representing the component when it's becoming indeterminate. */
  76. Indeterminate: 3,
  77. };
  78. TransitionCheckState[TransitionCheckState.Init] = 'Init';
  79. TransitionCheckState[TransitionCheckState.Checked] = 'Checked';
  80. TransitionCheckState[TransitionCheckState.Unchecked] = 'Unchecked';
  81. TransitionCheckState[TransitionCheckState.Indeterminate] = 'Indeterminate';
  82. /**
  83. * Change event object emitted by MatCheckbox.
  84. */
  85. var /**
  86. * Change event object emitted by MatCheckbox.
  87. */
  88. MatCheckboxChange = /** @class */ (function () {
  89. function MatCheckboxChange() {
  90. }
  91. return MatCheckboxChange;
  92. }());
  93. // Boilerplate for applying mixins to MatCheckbox.
  94. /**
  95. * \@docs-private
  96. */
  97. var
  98. // Boilerplate for applying mixins to MatCheckbox.
  99. /**
  100. * \@docs-private
  101. */
  102. MatCheckboxBase = /** @class */ (function () {
  103. function MatCheckboxBase(_elementRef) {
  104. this._elementRef = _elementRef;
  105. }
  106. return MatCheckboxBase;
  107. }());
  108. /** @type {?} */
  109. var _MatCheckboxMixinBase = core$1.mixinTabIndex(core$1.mixinColor(core$1.mixinDisableRipple(core$1.mixinDisabled(MatCheckboxBase)), 'accent'));
  110. /**
  111. * A material design checkbox component. Supports all of the functionality of an HTML5 checkbox,
  112. * and exposes a similar API. A MatCheckbox can be either checked, unchecked, indeterminate, or
  113. * disabled. Note that all additional accessibility attributes are taken care of by the component,
  114. * so there is no need to provide them yourself. However, if you want to omit a label and still
  115. * have the checkbox be accessible, you may supply an [aria-label] input.
  116. * See: https://material.io/design/components/selection-controls.html
  117. */
  118. var MatCheckbox = /** @class */ (function (_super) {
  119. __extends(MatCheckbox, _super);
  120. function MatCheckbox(elementRef, _changeDetectorRef, _focusMonitor, _ngZone, tabIndex, _clickAction, _animationMode) {
  121. var _this = _super.call(this, elementRef) || this;
  122. _this._changeDetectorRef = _changeDetectorRef;
  123. _this._focusMonitor = _focusMonitor;
  124. _this._ngZone = _ngZone;
  125. _this._clickAction = _clickAction;
  126. _this._animationMode = _animationMode;
  127. /**
  128. * Attached to the aria-label attribute of the host element. In most cases, aria-labelledby will
  129. * take precedence so this may be omitted.
  130. */
  131. _this.ariaLabel = '';
  132. /**
  133. * Users can specify the `aria-labelledby` attribute which will be forwarded to the input element
  134. */
  135. _this.ariaLabelledby = null;
  136. _this._uniqueId = "mat-checkbox-" + ++nextUniqueId;
  137. /**
  138. * A unique id for the checkbox input. If none is supplied, it will be auto-generated.
  139. */
  140. _this.id = _this._uniqueId;
  141. /**
  142. * Whether the label should appear after or before the checkbox. Defaults to 'after'
  143. */
  144. _this.labelPosition = 'after';
  145. /**
  146. * Name value will be applied to the input element if present
  147. */
  148. _this.name = null;
  149. /**
  150. * Event emitted when the checkbox's `checked` value changes.
  151. */
  152. _this.change = new core.EventEmitter();
  153. /**
  154. * Event emitted when the checkbox's `indeterminate` value changes.
  155. */
  156. _this.indeterminateChange = new core.EventEmitter();
  157. /**
  158. * Called when the checkbox is blurred. Needed to properly implement ControlValueAccessor.
  159. * \@docs-private
  160. */
  161. _this._onTouched = (/**
  162. * @return {?}
  163. */
  164. function () { });
  165. _this._currentAnimationClass = '';
  166. _this._currentCheckState = TransitionCheckState.Init;
  167. _this._controlValueAccessorChangeFn = (/**
  168. * @return {?}
  169. */
  170. function () { });
  171. _this._checked = false;
  172. _this._disabled = false;
  173. _this._indeterminate = false;
  174. _this.tabIndex = parseInt(tabIndex) || 0;
  175. _this._focusMonitor.monitor(elementRef, true).subscribe((/**
  176. * @param {?} focusOrigin
  177. * @return {?}
  178. */
  179. function (focusOrigin) {
  180. if (!focusOrigin) {
  181. // When a focused element becomes disabled, the browser *immediately* fires a blur event.
  182. // Angular does not expect events to be raised during change detection, so any state change
  183. // (such as a form control's 'ng-touched') will cause a changed-after-checked error.
  184. // See https://github.com/angular/angular/issues/17793. To work around this, we defer
  185. // telling the form control it has been touched until the next tick.
  186. Promise.resolve().then((/**
  187. * @return {?}
  188. */
  189. function () {
  190. _this._onTouched();
  191. _changeDetectorRef.markForCheck();
  192. }));
  193. }
  194. }));
  195. return _this;
  196. }
  197. Object.defineProperty(MatCheckbox.prototype, "inputId", {
  198. /** Returns the unique id for the visual hidden input. */
  199. get: /**
  200. * Returns the unique id for the visual hidden input.
  201. * @return {?}
  202. */
  203. function () { return (this.id || this._uniqueId) + "-input"; },
  204. enumerable: true,
  205. configurable: true
  206. });
  207. Object.defineProperty(MatCheckbox.prototype, "required", {
  208. /** Whether the checkbox is required. */
  209. get: /**
  210. * Whether the checkbox is required.
  211. * @return {?}
  212. */
  213. function () { return this._required; },
  214. set: /**
  215. * @param {?} value
  216. * @return {?}
  217. */
  218. function (value) { this._required = coercion.coerceBooleanProperty(value); },
  219. enumerable: true,
  220. configurable: true
  221. });
  222. // TODO: Delete next major revision.
  223. // TODO: Delete next major revision.
  224. /**
  225. * @return {?}
  226. */
  227. MatCheckbox.prototype.ngAfterViewChecked =
  228. // TODO: Delete next major revision.
  229. /**
  230. * @return {?}
  231. */
  232. function () { };
  233. /**
  234. * @return {?}
  235. */
  236. MatCheckbox.prototype.ngOnDestroy = /**
  237. * @return {?}
  238. */
  239. function () {
  240. this._focusMonitor.stopMonitoring(this._elementRef);
  241. };
  242. Object.defineProperty(MatCheckbox.prototype, "checked", {
  243. /**
  244. * Whether the checkbox is checked.
  245. */
  246. get: /**
  247. * Whether the checkbox is checked.
  248. * @return {?}
  249. */
  250. function () { return this._checked; },
  251. set: /**
  252. * @param {?} value
  253. * @return {?}
  254. */
  255. function (value) {
  256. if (value != this.checked) {
  257. this._checked = value;
  258. this._changeDetectorRef.markForCheck();
  259. }
  260. },
  261. enumerable: true,
  262. configurable: true
  263. });
  264. Object.defineProperty(MatCheckbox.prototype, "disabled", {
  265. /**
  266. * Whether the checkbox is disabled. This fully overrides the implementation provided by
  267. * mixinDisabled, but the mixin is still required because mixinTabIndex requires it.
  268. */
  269. get: /**
  270. * Whether the checkbox is disabled. This fully overrides the implementation provided by
  271. * mixinDisabled, but the mixin is still required because mixinTabIndex requires it.
  272. * @return {?}
  273. */
  274. function () { return this._disabled; },
  275. set: /**
  276. * @param {?} value
  277. * @return {?}
  278. */
  279. function (value) {
  280. /** @type {?} */
  281. var newValue = coercion.coerceBooleanProperty(value);
  282. if (newValue !== this.disabled) {
  283. this._disabled = newValue;
  284. this._changeDetectorRef.markForCheck();
  285. }
  286. },
  287. enumerable: true,
  288. configurable: true
  289. });
  290. Object.defineProperty(MatCheckbox.prototype, "indeterminate", {
  291. /**
  292. * Whether the checkbox is indeterminate. This is also known as "mixed" mode and can be used to
  293. * represent a checkbox with three states, e.g. a checkbox that represents a nested list of
  294. * checkable items. Note that whenever checkbox is manually clicked, indeterminate is immediately
  295. * set to false.
  296. */
  297. get: /**
  298. * Whether the checkbox is indeterminate. This is also known as "mixed" mode and can be used to
  299. * represent a checkbox with three states, e.g. a checkbox that represents a nested list of
  300. * checkable items. Note that whenever checkbox is manually clicked, indeterminate is immediately
  301. * set to false.
  302. * @return {?}
  303. */
  304. function () { return this._indeterminate; },
  305. set: /**
  306. * @param {?} value
  307. * @return {?}
  308. */
  309. function (value) {
  310. /** @type {?} */
  311. var changed = value != this._indeterminate;
  312. this._indeterminate = value;
  313. if (changed) {
  314. if (this._indeterminate) {
  315. this._transitionCheckState(TransitionCheckState.Indeterminate);
  316. }
  317. else {
  318. this._transitionCheckState(this.checked ? TransitionCheckState.Checked : TransitionCheckState.Unchecked);
  319. }
  320. this.indeterminateChange.emit(this._indeterminate);
  321. }
  322. },
  323. enumerable: true,
  324. configurable: true
  325. });
  326. /**
  327. * @return {?}
  328. */
  329. MatCheckbox.prototype._isRippleDisabled = /**
  330. * @return {?}
  331. */
  332. function () {
  333. return this.disableRipple || this.disabled;
  334. };
  335. /** Method being called whenever the label text changes. */
  336. /**
  337. * Method being called whenever the label text changes.
  338. * @return {?}
  339. */
  340. MatCheckbox.prototype._onLabelTextChange = /**
  341. * Method being called whenever the label text changes.
  342. * @return {?}
  343. */
  344. function () {
  345. // Since the event of the `cdkObserveContent` directive runs outside of the zone, the checkbox
  346. // component will be only marked for check, but no actual change detection runs automatically.
  347. // Instead of going back into the zone in order to trigger a change detection which causes
  348. // *all* components to be checked (if explicitly marked or not using OnPush), we only trigger
  349. // an explicit change detection for the checkbox view and it's children.
  350. this._changeDetectorRef.detectChanges();
  351. };
  352. // Implemented as part of ControlValueAccessor.
  353. // Implemented as part of ControlValueAccessor.
  354. /**
  355. * @param {?} value
  356. * @return {?}
  357. */
  358. MatCheckbox.prototype.writeValue =
  359. // Implemented as part of ControlValueAccessor.
  360. /**
  361. * @param {?} value
  362. * @return {?}
  363. */
  364. function (value) {
  365. this.checked = !!value;
  366. };
  367. // Implemented as part of ControlValueAccessor.
  368. // Implemented as part of ControlValueAccessor.
  369. /**
  370. * @param {?} fn
  371. * @return {?}
  372. */
  373. MatCheckbox.prototype.registerOnChange =
  374. // Implemented as part of ControlValueAccessor.
  375. /**
  376. * @param {?} fn
  377. * @return {?}
  378. */
  379. function (fn) {
  380. this._controlValueAccessorChangeFn = fn;
  381. };
  382. // Implemented as part of ControlValueAccessor.
  383. // Implemented as part of ControlValueAccessor.
  384. /**
  385. * @param {?} fn
  386. * @return {?}
  387. */
  388. MatCheckbox.prototype.registerOnTouched =
  389. // Implemented as part of ControlValueAccessor.
  390. /**
  391. * @param {?} fn
  392. * @return {?}
  393. */
  394. function (fn) {
  395. this._onTouched = fn;
  396. };
  397. // Implemented as part of ControlValueAccessor.
  398. // Implemented as part of ControlValueAccessor.
  399. /**
  400. * @param {?} isDisabled
  401. * @return {?}
  402. */
  403. MatCheckbox.prototype.setDisabledState =
  404. // Implemented as part of ControlValueAccessor.
  405. /**
  406. * @param {?} isDisabled
  407. * @return {?}
  408. */
  409. function (isDisabled) {
  410. this.disabled = isDisabled;
  411. };
  412. /**
  413. * @return {?}
  414. */
  415. MatCheckbox.prototype._getAriaChecked = /**
  416. * @return {?}
  417. */
  418. function () {
  419. return this.checked ? 'true' : (this.indeterminate ? 'mixed' : 'false');
  420. };
  421. /**
  422. * @private
  423. * @param {?} newState
  424. * @return {?}
  425. */
  426. MatCheckbox.prototype._transitionCheckState = /**
  427. * @private
  428. * @param {?} newState
  429. * @return {?}
  430. */
  431. function (newState) {
  432. /** @type {?} */
  433. var oldState = this._currentCheckState;
  434. /** @type {?} */
  435. var element = this._elementRef.nativeElement;
  436. if (oldState === newState) {
  437. return;
  438. }
  439. if (this._currentAnimationClass.length > 0) {
  440. element.classList.remove(this._currentAnimationClass);
  441. }
  442. this._currentAnimationClass = this._getAnimationClassForCheckStateTransition(oldState, newState);
  443. this._currentCheckState = newState;
  444. if (this._currentAnimationClass.length > 0) {
  445. element.classList.add(this._currentAnimationClass);
  446. // Remove the animation class to avoid animation when the checkbox is moved between containers
  447. /** @type {?} */
  448. var animationClass_1 = this._currentAnimationClass;
  449. this._ngZone.runOutsideAngular((/**
  450. * @return {?}
  451. */
  452. function () {
  453. setTimeout((/**
  454. * @return {?}
  455. */
  456. function () {
  457. element.classList.remove(animationClass_1);
  458. }), 1000);
  459. }));
  460. }
  461. };
  462. /**
  463. * @private
  464. * @return {?}
  465. */
  466. MatCheckbox.prototype._emitChangeEvent = /**
  467. * @private
  468. * @return {?}
  469. */
  470. function () {
  471. /** @type {?} */
  472. var event = new MatCheckboxChange();
  473. event.source = this;
  474. event.checked = this.checked;
  475. this._controlValueAccessorChangeFn(this.checked);
  476. this.change.emit(event);
  477. };
  478. /** Toggles the `checked` state of the checkbox. */
  479. /**
  480. * Toggles the `checked` state of the checkbox.
  481. * @return {?}
  482. */
  483. MatCheckbox.prototype.toggle = /**
  484. * Toggles the `checked` state of the checkbox.
  485. * @return {?}
  486. */
  487. function () {
  488. this.checked = !this.checked;
  489. };
  490. /**
  491. * Event handler for checkbox input element.
  492. * Toggles checked state if element is not disabled.
  493. * Do not toggle on (change) event since IE doesn't fire change event when
  494. * indeterminate checkbox is clicked.
  495. * @param event
  496. */
  497. /**
  498. * Event handler for checkbox input element.
  499. * Toggles checked state if element is not disabled.
  500. * Do not toggle on (change) event since IE doesn't fire change event when
  501. * indeterminate checkbox is clicked.
  502. * @param {?} event
  503. * @return {?}
  504. */
  505. MatCheckbox.prototype._onInputClick = /**
  506. * Event handler for checkbox input element.
  507. * Toggles checked state if element is not disabled.
  508. * Do not toggle on (change) event since IE doesn't fire change event when
  509. * indeterminate checkbox is clicked.
  510. * @param {?} event
  511. * @return {?}
  512. */
  513. function (event) {
  514. var _this = this;
  515. // We have to stop propagation for click events on the visual hidden input element.
  516. // By default, when a user clicks on a label element, a generated click event will be
  517. // dispatched on the associated input element. Since we are using a label element as our
  518. // root container, the click event on the `checkbox` will be executed twice.
  519. // The real click event will bubble up, and the generated click event also tries to bubble up.
  520. // This will lead to multiple click events.
  521. // Preventing bubbling for the second event will solve that issue.
  522. event.stopPropagation();
  523. // If resetIndeterminate is false, and the current state is indeterminate, do nothing on click
  524. if (!this.disabled && this._clickAction !== 'noop') {
  525. // When user manually click on the checkbox, `indeterminate` is set to false.
  526. if (this.indeterminate && this._clickAction !== 'check') {
  527. Promise.resolve().then((/**
  528. * @return {?}
  529. */
  530. function () {
  531. _this._indeterminate = false;
  532. _this.indeterminateChange.emit(_this._indeterminate);
  533. }));
  534. }
  535. this.toggle();
  536. this._transitionCheckState(this._checked ? TransitionCheckState.Checked : TransitionCheckState.Unchecked);
  537. // Emit our custom change event if the native input emitted one.
  538. // It is important to only emit it, if the native input triggered one, because
  539. // we don't want to trigger a change event, when the `checked` variable changes for example.
  540. this._emitChangeEvent();
  541. }
  542. else if (!this.disabled && this._clickAction === 'noop') {
  543. // Reset native input when clicked with noop. The native checkbox becomes checked after
  544. // click, reset it to be align with `checked` value of `mat-checkbox`.
  545. this._inputElement.nativeElement.checked = this.checked;
  546. this._inputElement.nativeElement.indeterminate = this.indeterminate;
  547. }
  548. };
  549. /** Focuses the checkbox. */
  550. /**
  551. * Focuses the checkbox.
  552. * @param {?=} origin
  553. * @param {?=} options
  554. * @return {?}
  555. */
  556. MatCheckbox.prototype.focus = /**
  557. * Focuses the checkbox.
  558. * @param {?=} origin
  559. * @param {?=} options
  560. * @return {?}
  561. */
  562. function (origin, options) {
  563. if (origin === void 0) { origin = 'keyboard'; }
  564. this._focusMonitor.focusVia(this._inputElement, origin, options);
  565. };
  566. /**
  567. * @param {?} event
  568. * @return {?}
  569. */
  570. MatCheckbox.prototype._onInteractionEvent = /**
  571. * @param {?} event
  572. * @return {?}
  573. */
  574. function (event) {
  575. // We always have to stop propagation on the change event.
  576. // Otherwise the change event, from the input element, will bubble up and
  577. // emit its event object to the `change` output.
  578. event.stopPropagation();
  579. };
  580. /**
  581. * @private
  582. * @param {?} oldState
  583. * @param {?} newState
  584. * @return {?}
  585. */
  586. MatCheckbox.prototype._getAnimationClassForCheckStateTransition = /**
  587. * @private
  588. * @param {?} oldState
  589. * @param {?} newState
  590. * @return {?}
  591. */
  592. function (oldState, newState) {
  593. // Don't transition if animations are disabled.
  594. if (this._animationMode === 'NoopAnimations') {
  595. return '';
  596. }
  597. /** @type {?} */
  598. var animSuffix = '';
  599. switch (oldState) {
  600. case TransitionCheckState.Init:
  601. // Handle edge case where user interacts with checkbox that does not have [(ngModel)] or
  602. // [checked] bound to it.
  603. if (newState === TransitionCheckState.Checked) {
  604. animSuffix = 'unchecked-checked';
  605. }
  606. else if (newState == TransitionCheckState.Indeterminate) {
  607. animSuffix = 'unchecked-indeterminate';
  608. }
  609. else {
  610. return '';
  611. }
  612. break;
  613. case TransitionCheckState.Unchecked:
  614. animSuffix = newState === TransitionCheckState.Checked ?
  615. 'unchecked-checked' : 'unchecked-indeterminate';
  616. break;
  617. case TransitionCheckState.Checked:
  618. animSuffix = newState === TransitionCheckState.Unchecked ?
  619. 'checked-unchecked' : 'checked-indeterminate';
  620. break;
  621. case TransitionCheckState.Indeterminate:
  622. animSuffix = newState === TransitionCheckState.Checked ?
  623. 'indeterminate-checked' : 'indeterminate-unchecked';
  624. break;
  625. }
  626. return "mat-checkbox-anim-" + animSuffix;
  627. };
  628. MatCheckbox.decorators = [
  629. { type: core.Component, args: [{selector: 'mat-checkbox',
  630. template: "<label [attr.for]=\"inputId\" class=\"mat-checkbox-layout\" #label><div class=\"mat-checkbox-inner-container\" [class.mat-checkbox-inner-container-no-side-margin]=\"!checkboxLabel.textContent || !checkboxLabel.textContent.trim()\"><input #input class=\"mat-checkbox-input cdk-visually-hidden\" type=\"checkbox\" [id]=\"inputId\" [required]=\"required\" [checked]=\"checked\" [attr.value]=\"value\" [disabled]=\"disabled\" [attr.name]=\"name\" [tabIndex]=\"tabIndex\" [indeterminate]=\"indeterminate\" [attr.aria-label]=\"ariaLabel || null\" [attr.aria-labelledby]=\"ariaLabelledby\" [attr.aria-checked]=\"_getAriaChecked()\" (change)=\"_onInteractionEvent($event)\" (click)=\"_onInputClick($event)\"><div matRipple class=\"mat-checkbox-ripple\" [matRippleTrigger]=\"label\" [matRippleDisabled]=\"_isRippleDisabled()\" [matRippleRadius]=\"20\" [matRippleCentered]=\"true\" [matRippleAnimation]=\"{enterDuration: 150}\"><div class=\"mat-ripple-element mat-checkbox-persistent-ripple\"></div></div><div class=\"mat-checkbox-frame\"></div><div class=\"mat-checkbox-background\"><svg version=\"1.1\" focusable=\"false\" class=\"mat-checkbox-checkmark\" viewBox=\"0 0 24 24\" xml:space=\"preserve\"><path class=\"mat-checkbox-checkmark-path\" fill=\"none\" stroke=\"white\" d=\"M4.1,12.7 9,17.6 20.3,6.3\"/></svg><div class=\"mat-checkbox-mixedmark\"></div></div></div><span class=\"mat-checkbox-label\" #checkboxLabel (cdkObserveContent)=\"_onLabelTextChange()\"><span style=\"display:none\">&nbsp;</span><ng-content></ng-content></span></label>",
  631. styles: ["@keyframes mat-checkbox-fade-in-background{0%{opacity:0}50%{opacity:1}}@keyframes mat-checkbox-fade-out-background{0%,50%{opacity:1}100%{opacity:0}}@keyframes mat-checkbox-unchecked-checked-checkmark-path{0%,50%{stroke-dashoffset:22.91026}50%{animation-timing-function:cubic-bezier(0,0,.2,.1)}100%{stroke-dashoffset:0}}@keyframes mat-checkbox-unchecked-indeterminate-mixedmark{0%,68.2%{transform:scaleX(0)}68.2%{animation-timing-function:cubic-bezier(0,0,0,1)}100%{transform:scaleX(1)}}@keyframes mat-checkbox-checked-unchecked-checkmark-path{from{animation-timing-function:cubic-bezier(.4,0,1,1);stroke-dashoffset:0}to{stroke-dashoffset:-22.91026}}@keyframes mat-checkbox-checked-indeterminate-checkmark{from{animation-timing-function:cubic-bezier(0,0,.2,.1);opacity:1;transform:rotate(0)}to{opacity:0;transform:rotate(45deg)}}@keyframes mat-checkbox-indeterminate-checked-checkmark{from{animation-timing-function:cubic-bezier(.14,0,0,1);opacity:0;transform:rotate(45deg)}to{opacity:1;transform:rotate(360deg)}}@keyframes mat-checkbox-checked-indeterminate-mixedmark{from{animation-timing-function:cubic-bezier(0,0,.2,.1);opacity:0;transform:rotate(-45deg)}to{opacity:1;transform:rotate(0)}}@keyframes mat-checkbox-indeterminate-checked-mixedmark{from{animation-timing-function:cubic-bezier(.14,0,0,1);opacity:1;transform:rotate(0)}to{opacity:0;transform:rotate(315deg)}}@keyframes mat-checkbox-indeterminate-unchecked-mixedmark{0%{animation-timing-function:linear;opacity:1;transform:scaleX(1)}100%,32.8%{opacity:0;transform:scaleX(0)}}.mat-checkbox-background,.mat-checkbox-frame{top:0;left:0;right:0;bottom:0;position:absolute;border-radius:2px;box-sizing:border-box;pointer-events:none}.mat-checkbox{transition:background .4s cubic-bezier(.25,.8,.25,1),box-shadow 280ms cubic-bezier(.4,0,.2,1);cursor:pointer;-webkit-tap-highlight-color:transparent}._mat-animation-noopable.mat-checkbox{transition:none;animation:none}.mat-checkbox .mat-ripple-element:not(.mat-checkbox-persistent-ripple){opacity:.16}.mat-checkbox-layout{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:inherit;align-items:baseline;vertical-align:middle;display:inline-flex;white-space:nowrap}.mat-checkbox-label{-webkit-user-select:auto;-moz-user-select:auto;-ms-user-select:auto;user-select:auto}.mat-checkbox-inner-container{display:inline-block;height:16px;line-height:0;margin:auto;margin-right:8px;order:0;position:relative;vertical-align:middle;white-space:nowrap;width:16px;flex-shrink:0}[dir=rtl] .mat-checkbox-inner-container{margin-left:8px;margin-right:auto}.mat-checkbox-inner-container-no-side-margin{margin-left:0;margin-right:0}.mat-checkbox-frame{background-color:transparent;transition:border-color 90ms cubic-bezier(0,0,.2,.1);border-width:2px;border-style:solid}._mat-animation-noopable .mat-checkbox-frame{transition:none}@media (-ms-high-contrast:active){.mat-checkbox.cdk-keyboard-focused .mat-checkbox-frame{border-style:dotted}}.mat-checkbox-background{align-items:center;display:inline-flex;justify-content:center;transition:background-color 90ms cubic-bezier(0,0,.2,.1),opacity 90ms cubic-bezier(0,0,.2,.1)}._mat-animation-noopable .mat-checkbox-background{transition:none}.mat-checkbox-persistent-ripple{width:100%;height:100%;transform:none}.mat-checkbox-inner-container:hover .mat-checkbox-persistent-ripple{opacity:.04}.mat-checkbox.cdk-keyboard-focused .mat-checkbox-persistent-ripple{opacity:.12}.mat-checkbox-persistent-ripple,.mat-checkbox.mat-checkbox-disabled .mat-checkbox-inner-container:hover .mat-checkbox-persistent-ripple{opacity:0}@media (hover:none){.mat-checkbox-inner-container:hover .mat-checkbox-persistent-ripple{display:none}}.mat-checkbox-checkmark{top:0;left:0;right:0;bottom:0;position:absolute;width:100%}.mat-checkbox-checkmark-path{stroke-dashoffset:22.91026;stroke-dasharray:22.91026;stroke-width:2.13333px}.mat-checkbox-mixedmark{width:calc(100% - 6px);height:2px;opacity:0;transform:scaleX(0) rotate(0);border-radius:2px}@media (-ms-high-contrast:active){.mat-checkbox-mixedmark{height:0;border-top:solid 2px;margin-top:2px}}.mat-checkbox-label-before .mat-checkbox-inner-container{order:1;margin-left:8px;margin-right:auto}[dir=rtl] .mat-checkbox-label-before .mat-checkbox-inner-container{margin-left:auto;margin-right:8px}.mat-checkbox-checked .mat-checkbox-checkmark{opacity:1}.mat-checkbox-checked .mat-checkbox-checkmark-path{stroke-dashoffset:0}.mat-checkbox-checked .mat-checkbox-mixedmark{transform:scaleX(1) rotate(-45deg)}.mat-checkbox-indeterminate .mat-checkbox-checkmark{opacity:0;transform:rotate(45deg)}.mat-checkbox-indeterminate .mat-checkbox-checkmark-path{stroke-dashoffset:0}.mat-checkbox-indeterminate .mat-checkbox-mixedmark{opacity:1;transform:scaleX(1) rotate(0)}.mat-checkbox-unchecked .mat-checkbox-background{background-color:transparent}.mat-checkbox-disabled{cursor:default}.mat-checkbox-anim-unchecked-checked .mat-checkbox-background{animation:180ms linear 0s mat-checkbox-fade-in-background}.mat-checkbox-anim-unchecked-checked .mat-checkbox-checkmark-path{animation:180ms linear 0s mat-checkbox-unchecked-checked-checkmark-path}.mat-checkbox-anim-unchecked-indeterminate .mat-checkbox-background{animation:180ms linear 0s mat-checkbox-fade-in-background}.mat-checkbox-anim-unchecked-indeterminate .mat-checkbox-mixedmark{animation:90ms linear 0s mat-checkbox-unchecked-indeterminate-mixedmark}.mat-checkbox-anim-checked-unchecked .mat-checkbox-background{animation:180ms linear 0s mat-checkbox-fade-out-background}.mat-checkbox-anim-checked-unchecked .mat-checkbox-checkmark-path{animation:90ms linear 0s mat-checkbox-checked-unchecked-checkmark-path}.mat-checkbox-anim-checked-indeterminate .mat-checkbox-checkmark{animation:90ms linear 0s mat-checkbox-checked-indeterminate-checkmark}.mat-checkbox-anim-checked-indeterminate .mat-checkbox-mixedmark{animation:90ms linear 0s mat-checkbox-checked-indeterminate-mixedmark}.mat-checkbox-anim-indeterminate-checked .mat-checkbox-checkmark{animation:.5s linear 0s mat-checkbox-indeterminate-checked-checkmark}.mat-checkbox-anim-indeterminate-checked .mat-checkbox-mixedmark{animation:.5s linear 0s mat-checkbox-indeterminate-checked-mixedmark}.mat-checkbox-anim-indeterminate-unchecked .mat-checkbox-background{animation:180ms linear 0s mat-checkbox-fade-out-background}.mat-checkbox-anim-indeterminate-unchecked .mat-checkbox-mixedmark{animation:.3s linear 0s mat-checkbox-indeterminate-unchecked-mixedmark}.mat-checkbox-input{bottom:0;left:50%}.mat-checkbox .mat-checkbox-ripple{position:absolute;left:calc(50% - 20px);top:calc(50% - 20px);height:40px;width:40px;z-index:1;pointer-events:none}"],
  632. exportAs: 'matCheckbox',
  633. host: {
  634. 'class': 'mat-checkbox',
  635. '[id]': 'id',
  636. '[attr.tabindex]': 'null',
  637. '[class.mat-checkbox-indeterminate]': 'indeterminate',
  638. '[class.mat-checkbox-checked]': 'checked',
  639. '[class.mat-checkbox-disabled]': 'disabled',
  640. '[class.mat-checkbox-label-before]': 'labelPosition == "before"',
  641. '[class._mat-animation-noopable]': "_animationMode === 'NoopAnimations'",
  642. },
  643. providers: [MAT_CHECKBOX_CONTROL_VALUE_ACCESSOR],
  644. inputs: ['disableRipple', 'color', 'tabIndex'],
  645. encapsulation: core.ViewEncapsulation.None,
  646. changeDetection: core.ChangeDetectionStrategy.OnPush
  647. },] },
  648. ];
  649. /** @nocollapse */
  650. MatCheckbox.ctorParameters = function () { return [
  651. { type: core.ElementRef },
  652. { type: core.ChangeDetectorRef },
  653. { type: a11y.FocusMonitor },
  654. { type: core.NgZone },
  655. { type: String, decorators: [{ type: core.Attribute, args: ['tabindex',] }] },
  656. { type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [MAT_CHECKBOX_CLICK_ACTION,] }] },
  657. { type: String, decorators: [{ type: core.Optional }, { type: core.Inject, args: [animations.ANIMATION_MODULE_TYPE,] }] }
  658. ]; };
  659. MatCheckbox.propDecorators = {
  660. ariaLabel: [{ type: core.Input, args: ['aria-label',] }],
  661. ariaLabelledby: [{ type: core.Input, args: ['aria-labelledby',] }],
  662. id: [{ type: core.Input }],
  663. required: [{ type: core.Input }],
  664. labelPosition: [{ type: core.Input }],
  665. name: [{ type: core.Input }],
  666. change: [{ type: core.Output }],
  667. indeterminateChange: [{ type: core.Output }],
  668. value: [{ type: core.Input }],
  669. _inputElement: [{ type: core.ViewChild, args: ['input', { static: false },] }],
  670. ripple: [{ type: core.ViewChild, args: [core$1.MatRipple, { static: false },] }],
  671. checked: [{ type: core.Input }],
  672. disabled: [{ type: core.Input }],
  673. indeterminate: [{ type: core.Input }]
  674. };
  675. return MatCheckbox;
  676. }(_MatCheckboxMixinBase));
  677. /**
  678. * @fileoverview added by tsickle
  679. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  680. */
  681. /** @type {?} */
  682. var MAT_CHECKBOX_REQUIRED_VALIDATOR = {
  683. provide: forms.NG_VALIDATORS,
  684. useExisting: core.forwardRef((/**
  685. * @return {?}
  686. */
  687. function () { return MatCheckboxRequiredValidator; })),
  688. multi: true
  689. };
  690. /**
  691. * Validator for Material checkbox's required attribute in template-driven checkbox.
  692. * Current CheckboxRequiredValidator only work with `input type=checkbox` and does not
  693. * work with `mat-checkbox`.
  694. */
  695. var MatCheckboxRequiredValidator = /** @class */ (function (_super) {
  696. __extends(MatCheckboxRequiredValidator, _super);
  697. function MatCheckboxRequiredValidator() {
  698. return _super !== null && _super.apply(this, arguments) || this;
  699. }
  700. MatCheckboxRequiredValidator.decorators = [
  701. { type: core.Directive, args: [{
  702. selector: "mat-checkbox[required][formControlName],\n mat-checkbox[required][formControl], mat-checkbox[required][ngModel]",
  703. providers: [MAT_CHECKBOX_REQUIRED_VALIDATOR],
  704. },] },
  705. ];
  706. return MatCheckboxRequiredValidator;
  707. }(forms.CheckboxRequiredValidator));
  708. /**
  709. * @fileoverview added by tsickle
  710. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  711. */
  712. /**
  713. * This module is used by both original and MDC-based checkbox implementations.
  714. */
  715. var _MatCheckboxRequiredValidatorModule = /** @class */ (function () {
  716. function _MatCheckboxRequiredValidatorModule() {
  717. }
  718. _MatCheckboxRequiredValidatorModule.decorators = [
  719. { type: core.NgModule, args: [{
  720. exports: [MatCheckboxRequiredValidator],
  721. declarations: [MatCheckboxRequiredValidator],
  722. },] },
  723. ];
  724. return _MatCheckboxRequiredValidatorModule;
  725. }());
  726. var MatCheckboxModule = /** @class */ (function () {
  727. function MatCheckboxModule() {
  728. }
  729. MatCheckboxModule.decorators = [
  730. { type: core.NgModule, args: [{
  731. imports: [
  732. common.CommonModule, core$1.MatRippleModule, core$1.MatCommonModule, observers.ObserversModule,
  733. _MatCheckboxRequiredValidatorModule
  734. ],
  735. exports: [MatCheckbox, core$1.MatCommonModule, _MatCheckboxRequiredValidatorModule],
  736. declarations: [MatCheckbox],
  737. },] },
  738. ];
  739. return MatCheckboxModule;
  740. }());
  741. exports.MAT_CHECKBOX_CONTROL_VALUE_ACCESSOR = MAT_CHECKBOX_CONTROL_VALUE_ACCESSOR;
  742. exports.TransitionCheckState = TransitionCheckState;
  743. exports.MatCheckboxChange = MatCheckboxChange;
  744. exports.MatCheckbox = MatCheckbox;
  745. exports.MAT_CHECKBOX_CLICK_ACTION = MAT_CHECKBOX_CLICK_ACTION;
  746. exports._MatCheckboxRequiredValidatorModule = _MatCheckboxRequiredValidatorModule;
  747. exports.MatCheckboxModule = MatCheckboxModule;
  748. exports.MAT_CHECKBOX_REQUIRED_VALIDATOR = MAT_CHECKBOX_REQUIRED_VALIDATOR;
  749. exports.MatCheckboxRequiredValidator = MatCheckboxRequiredValidator;
  750. Object.defineProperty(exports, '__esModule', { value: true });
  751. })));
  752. //# sourceMappingURL=material-checkbox.umd.js.map