slide-toggle.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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. import { InjectionToken, Attribute, ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, forwardRef, Input, Output, ViewChild, ViewEncapsulation, NgZone, Optional, Inject, Directive, NgModule } from '@angular/core';
  9. import { FocusMonitor } from '@angular/cdk/a11y';
  10. import { Directionality } from '@angular/cdk/bidi';
  11. import { coerceBooleanProperty } from '@angular/cdk/coercion';
  12. import { NG_VALUE_ACCESSOR, CheckboxRequiredValidator, NG_VALIDATORS } from '@angular/forms';
  13. import { mixinColor, mixinDisabled, mixinDisableRipple, mixinTabIndex, GestureConfig, MatCommonModule, MatRippleModule } from '@angular/material/core';
  14. import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations';
  15. import { ObserversModule } from '@angular/cdk/observers';
  16. import { HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
  17. /**
  18. * @fileoverview added by tsickle
  19. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  20. */
  21. /**
  22. * Injection token to be used to override the default options for `mat-slide-toggle`.
  23. * @type {?}
  24. */
  25. const MAT_SLIDE_TOGGLE_DEFAULT_OPTIONS = new InjectionToken('mat-slide-toggle-default-options', {
  26. providedIn: 'root',
  27. factory: (/**
  28. * @return {?}
  29. */
  30. () => ({ disableToggleValue: false, disableDragValue: false }))
  31. });
  32. /**
  33. * @fileoverview added by tsickle
  34. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  35. */
  36. // Increasing integer for generating unique ids for slide-toggle components.
  37. /** @type {?} */
  38. let nextUniqueId = 0;
  39. /**
  40. * \@docs-private
  41. * @type {?}
  42. */
  43. const MAT_SLIDE_TOGGLE_VALUE_ACCESSOR = {
  44. provide: NG_VALUE_ACCESSOR,
  45. useExisting: forwardRef((/**
  46. * @return {?}
  47. */
  48. () => MatSlideToggle)),
  49. multi: true
  50. };
  51. /**
  52. * Change event object emitted by a MatSlideToggle.
  53. */
  54. class MatSlideToggleChange {
  55. /**
  56. * @param {?} source
  57. * @param {?} checked
  58. */
  59. constructor(source, checked) {
  60. this.source = source;
  61. this.checked = checked;
  62. }
  63. }
  64. // Boilerplate for applying mixins to MatSlideToggle.
  65. /**
  66. * \@docs-private
  67. */
  68. class MatSlideToggleBase {
  69. /**
  70. * @param {?} _elementRef
  71. */
  72. constructor(_elementRef) {
  73. this._elementRef = _elementRef;
  74. }
  75. }
  76. /** @type {?} */
  77. const _MatSlideToggleMixinBase = mixinTabIndex(mixinColor(mixinDisableRipple(mixinDisabled(MatSlideToggleBase)), 'accent'));
  78. /**
  79. * Represents a slidable "switch" toggle that can be moved between on and off.
  80. */
  81. class MatSlideToggle extends _MatSlideToggleMixinBase {
  82. /**
  83. * @param {?} elementRef
  84. * @param {?} _focusMonitor
  85. * @param {?} _changeDetectorRef
  86. * @param {?} tabIndex
  87. * @param {?} _ngZone
  88. * @param {?} defaults
  89. * @param {?=} _animationMode
  90. * @param {?=} _dir
  91. */
  92. constructor(elementRef, _focusMonitor, _changeDetectorRef, tabIndex, _ngZone, defaults, _animationMode, _dir) {
  93. super(elementRef);
  94. this._focusMonitor = _focusMonitor;
  95. this._changeDetectorRef = _changeDetectorRef;
  96. this._ngZone = _ngZone;
  97. this.defaults = defaults;
  98. this._animationMode = _animationMode;
  99. this._dir = _dir;
  100. this._onChange = (/**
  101. * @param {?} _
  102. * @return {?}
  103. */
  104. (_) => { });
  105. this._onTouched = (/**
  106. * @return {?}
  107. */
  108. () => { });
  109. this._uniqueId = `mat-slide-toggle-${++nextUniqueId}`;
  110. this._required = false;
  111. this._checked = false;
  112. /**
  113. * Whether the thumb is currently being dragged.
  114. */
  115. this._dragging = false;
  116. /**
  117. * Name value will be applied to the input element if present.
  118. */
  119. this.name = null;
  120. /**
  121. * A unique id for the slide-toggle input. If none is supplied, it will be auto-generated.
  122. */
  123. this.id = this._uniqueId;
  124. /**
  125. * Whether the label should appear after or before the slide-toggle. Defaults to 'after'.
  126. */
  127. this.labelPosition = 'after';
  128. /**
  129. * Used to set the aria-label attribute on the underlying input element.
  130. */
  131. this.ariaLabel = null;
  132. /**
  133. * Used to set the aria-labelledby attribute on the underlying input element.
  134. */
  135. this.ariaLabelledby = null;
  136. /**
  137. * An event will be dispatched each time the slide-toggle changes its value.
  138. */
  139. this.change = new EventEmitter();
  140. /**
  141. * An event will be dispatched each time the slide-toggle input is toggled.
  142. * This event is always emitted when the user toggles the slide toggle, but this does not mean
  143. * the slide toggle's value has changed. The event does not fire when the user drags to change
  144. * the slide toggle value.
  145. */
  146. this.toggleChange = new EventEmitter();
  147. /**
  148. * An event will be dispatched each time the slide-toggle is dragged.
  149. * This event is always emitted when the user drags the slide toggle to make a change greater
  150. * than 50%. It does not mean the slide toggle's value is changed. The event is not emitted when
  151. * the user toggles the slide toggle to change its value.
  152. */
  153. this.dragChange = new EventEmitter();
  154. this.tabIndex = parseInt(tabIndex) || 0;
  155. }
  156. /**
  157. * Whether the slide-toggle is required.
  158. * @return {?}
  159. */
  160. get required() { return this._required; }
  161. /**
  162. * @param {?} value
  163. * @return {?}
  164. */
  165. set required(value) { this._required = coerceBooleanProperty(value); }
  166. /**
  167. * Whether the slide-toggle element is checked or not.
  168. * @return {?}
  169. */
  170. get checked() { return this._checked; }
  171. /**
  172. * @param {?} value
  173. * @return {?}
  174. */
  175. set checked(value) {
  176. this._checked = coerceBooleanProperty(value);
  177. this._changeDetectorRef.markForCheck();
  178. }
  179. /**
  180. * Returns the unique id for the visual hidden input.
  181. * @return {?}
  182. */
  183. get inputId() { return `${this.id || this._uniqueId}-input`; }
  184. /**
  185. * @return {?}
  186. */
  187. ngAfterContentInit() {
  188. this._focusMonitor
  189. .monitor(this._elementRef, true)
  190. .subscribe((/**
  191. * @param {?} focusOrigin
  192. * @return {?}
  193. */
  194. focusOrigin => {
  195. if (!focusOrigin) {
  196. // When a focused element becomes disabled, the browser *immediately* fires a blur event.
  197. // Angular does not expect events to be raised during change detection, so any state
  198. // change (such as a form control's 'ng-touched') will cause a changed-after-checked
  199. // error. See https://github.com/angular/angular/issues/17793. To work around this,
  200. // we defer telling the form control it has been touched until the next tick.
  201. Promise.resolve().then((/**
  202. * @return {?}
  203. */
  204. () => this._onTouched()));
  205. }
  206. }));
  207. }
  208. /**
  209. * @return {?}
  210. */
  211. ngOnDestroy() {
  212. this._focusMonitor.stopMonitoring(this._elementRef);
  213. }
  214. /**
  215. * Method being called whenever the underlying input emits a change event.
  216. * @param {?} event
  217. * @return {?}
  218. */
  219. _onChangeEvent(event) {
  220. // We always have to stop propagation on the change event.
  221. // Otherwise the change event, from the input element, will bubble up and
  222. // emit its event object to the component's `change` output.
  223. event.stopPropagation();
  224. if (!this._dragging) {
  225. this.toggleChange.emit();
  226. }
  227. // Releasing the pointer over the `<label>` element while dragging triggers another
  228. // click event on the `<label>` element. This means that the checked state of the underlying
  229. // input changed unintentionally and needs to be changed back. Or when the slide toggle's config
  230. // disabled toggle change event by setting `disableToggleValue: true`, the slide toggle's value
  231. // does not change, and the checked state of the underlying input needs to be changed back.
  232. if (this._dragging || this.defaults.disableToggleValue) {
  233. this._inputElement.nativeElement.checked = this.checked;
  234. return;
  235. }
  236. // Sync the value from the underlying input element with the component instance.
  237. this.checked = this._inputElement.nativeElement.checked;
  238. // Emit our custom change event only if the underlying input emitted one. This ensures that
  239. // there is no change event, when the checked state changes programmatically.
  240. this._emitChangeEvent();
  241. }
  242. /**
  243. * Method being called whenever the slide-toggle has been clicked.
  244. * @param {?} event
  245. * @return {?}
  246. */
  247. _onInputClick(event) {
  248. // We have to stop propagation for click events on the visual hidden input element.
  249. // By default, when a user clicks on a label element, a generated click event will be
  250. // dispatched on the associated input element. Since we are using a label element as our
  251. // root container, the click event on the `slide-toggle` will be executed twice.
  252. // The real click event will bubble up, and the generated click event also tries to bubble up.
  253. // This will lead to multiple click events.
  254. // Preventing bubbling for the second event will solve that issue.
  255. event.stopPropagation();
  256. }
  257. /**
  258. * Implemented as part of ControlValueAccessor.
  259. * @param {?} value
  260. * @return {?}
  261. */
  262. writeValue(value) {
  263. this.checked = !!value;
  264. }
  265. /**
  266. * Implemented as part of ControlValueAccessor.
  267. * @param {?} fn
  268. * @return {?}
  269. */
  270. registerOnChange(fn) {
  271. this._onChange = fn;
  272. }
  273. /**
  274. * Implemented as part of ControlValueAccessor.
  275. * @param {?} fn
  276. * @return {?}
  277. */
  278. registerOnTouched(fn) {
  279. this._onTouched = fn;
  280. }
  281. /**
  282. * Implemented as a part of ControlValueAccessor.
  283. * @param {?} isDisabled
  284. * @return {?}
  285. */
  286. setDisabledState(isDisabled) {
  287. this.disabled = isDisabled;
  288. this._changeDetectorRef.markForCheck();
  289. }
  290. /**
  291. * Focuses the slide-toggle.
  292. * @param {?=} options
  293. * @return {?}
  294. */
  295. focus(options) {
  296. this._focusMonitor.focusVia(this._inputElement, 'keyboard', options);
  297. }
  298. /**
  299. * Toggles the checked state of the slide-toggle.
  300. * @return {?}
  301. */
  302. toggle() {
  303. this.checked = !this.checked;
  304. this._onChange(this.checked);
  305. }
  306. /**
  307. * Emits a change event on the `change` output. Also notifies the FormControl about the change.
  308. * @private
  309. * @return {?}
  310. */
  311. _emitChangeEvent() {
  312. this._onChange(this.checked);
  313. this.change.emit(new MatSlideToggleChange(this, this.checked));
  314. }
  315. /**
  316. * Retrieves the percentage of thumb from the moved distance. Percentage as fraction of 100.
  317. * @private
  318. * @param {?} distance
  319. * @return {?}
  320. */
  321. _getDragPercentage(distance) {
  322. /** @type {?} */
  323. let percentage = (distance / this._thumbBarWidth) * 100;
  324. // When the toggle was initially checked, then we have to start the drag at the end.
  325. if (this._previousChecked) {
  326. percentage += 100;
  327. }
  328. return Math.max(0, Math.min(percentage, 100));
  329. }
  330. /**
  331. * @return {?}
  332. */
  333. _onDragStart() {
  334. if (!this.disabled && !this._dragging) {
  335. /** @type {?} */
  336. const thumbEl = this._thumbEl.nativeElement;
  337. this._thumbBarWidth = this._thumbBarEl.nativeElement.clientWidth - thumbEl.clientWidth;
  338. thumbEl.classList.add('mat-dragging');
  339. this._previousChecked = this.checked;
  340. this._dragging = true;
  341. }
  342. }
  343. /**
  344. * @param {?} event
  345. * @return {?}
  346. */
  347. _onDrag(event) {
  348. if (this._dragging) {
  349. /** @type {?} */
  350. const direction = this._dir && this._dir.value === 'rtl' ? -1 : 1;
  351. this._dragPercentage = this._getDragPercentage(event.deltaX * direction);
  352. // Calculate the moved distance based on the thumb bar width.
  353. /** @type {?} */
  354. const dragX = (this._dragPercentage / 100) * this._thumbBarWidth * direction;
  355. this._thumbEl.nativeElement.style.transform = `translate3d(${dragX}px, 0, 0)`;
  356. }
  357. }
  358. /**
  359. * @return {?}
  360. */
  361. _onDragEnd() {
  362. if (this._dragging) {
  363. /** @type {?} */
  364. const newCheckedValue = this._dragPercentage > 50;
  365. if (newCheckedValue !== this.checked) {
  366. this.dragChange.emit();
  367. if (!this.defaults.disableDragValue) {
  368. this.checked = newCheckedValue;
  369. this._emitChangeEvent();
  370. }
  371. }
  372. // The drag should be stopped outside of the current event handler, otherwise the
  373. // click event will be fired before it and will revert the drag change.
  374. this._ngZone.runOutsideAngular((/**
  375. * @return {?}
  376. */
  377. () => setTimeout((/**
  378. * @return {?}
  379. */
  380. () => {
  381. if (this._dragging) {
  382. this._dragging = false;
  383. this._thumbEl.nativeElement.classList.remove('mat-dragging');
  384. // Reset the transform because the component will take care
  385. // of the thumb position after drag.
  386. this._thumbEl.nativeElement.style.transform = '';
  387. }
  388. }))));
  389. }
  390. }
  391. /**
  392. * Method being called whenever the label text changes.
  393. * @return {?}
  394. */
  395. _onLabelTextChange() {
  396. // Since the event of the `cdkObserveContent` directive runs outside of the zone, the
  397. // slide-toggle component will be only marked for check, but no actual change detection runs
  398. // automatically. Instead of going back into the zone in order to trigger a change detection
  399. // which causes *all* components to be checked (if explicitly marked or not using OnPush),
  400. // we only trigger an explicit change detection for the slide-toggle view and it's children.
  401. this._changeDetectorRef.detectChanges();
  402. }
  403. }
  404. MatSlideToggle.decorators = [
  405. { type: Component, args: [{selector: 'mat-slide-toggle',
  406. exportAs: 'matSlideToggle',
  407. host: {
  408. 'class': 'mat-slide-toggle',
  409. '[id]': 'id',
  410. // Needs to be `-1` so it can still receive programmatic focus.
  411. '[attr.tabindex]': 'disabled ? null : -1',
  412. '[class.mat-checked]': 'checked',
  413. '[class.mat-disabled]': 'disabled',
  414. '[class.mat-slide-toggle-label-before]': 'labelPosition == "before"',
  415. '[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
  416. '(focus)': '_inputElement.nativeElement.focus()',
  417. },
  418. template: "<label [attr.for]=\"inputId\" class=\"mat-slide-toggle-label\" #label><div #toggleBar class=\"mat-slide-toggle-bar\" [class.mat-slide-toggle-bar-no-side-margin]=\"!labelContent.textContent || !labelContent.textContent.trim()\"><input #input class=\"mat-slide-toggle-input cdk-visually-hidden\" type=\"checkbox\" role=\"switch\" [id]=\"inputId\" [required]=\"required\" [tabIndex]=\"tabIndex\" [checked]=\"checked\" [disabled]=\"disabled\" [attr.name]=\"name\" [attr.aria-checked]=\"checked.toString()\" [attr.aria-label]=\"ariaLabel\" [attr.aria-labelledby]=\"ariaLabelledby\" (change)=\"_onChangeEvent($event)\" (click)=\"_onInputClick($event)\"><div class=\"mat-slide-toggle-thumb-container\" #thumbContainer (slidestart)=\"_onDragStart()\" (slide)=\"_onDrag($event)\" (slideend)=\"_onDragEnd()\"><div class=\"mat-slide-toggle-thumb\"></div><div class=\"mat-slide-toggle-ripple\" mat-ripple [matRippleTrigger]=\"label\" [matRippleDisabled]=\"disableRipple || disabled\" [matRippleCentered]=\"true\" [matRippleRadius]=\"20\" [matRippleAnimation]=\"{enterDuration: 150}\"><div class=\"mat-ripple-element mat-slide-toggle-persistent-ripple\"></div></div></div></div><span class=\"mat-slide-toggle-content\" #labelContent (cdkObserveContent)=\"_onLabelTextChange()\"><span style=\"display:none\">&nbsp;</span><ng-content></ng-content></span></label>",
  419. styles: [".mat-slide-toggle{display:inline-block;height:24px;max-width:100%;line-height:24px;white-space:nowrap;outline:0;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-tap-highlight-color:transparent}.mat-slide-toggle.mat-checked .mat-slide-toggle-thumb-container{transform:translate3d(16px,0,0)}[dir=rtl] .mat-slide-toggle.mat-checked .mat-slide-toggle-thumb-container{transform:translate3d(-16px,0,0)}.mat-slide-toggle.mat-disabled{opacity:.38}.mat-slide-toggle.mat-disabled .mat-slide-toggle-label,.mat-slide-toggle.mat-disabled .mat-slide-toggle-thumb-container{cursor:default}.mat-slide-toggle-label{display:flex;flex:1;flex-direction:row;align-items:center;height:inherit;cursor:pointer}.mat-slide-toggle-content{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.mat-slide-toggle-label-before .mat-slide-toggle-label{order:1}.mat-slide-toggle-label-before .mat-slide-toggle-bar{order:2}.mat-slide-toggle-bar,[dir=rtl] .mat-slide-toggle-label-before .mat-slide-toggle-bar{margin-right:8px;margin-left:0}.mat-slide-toggle-label-before .mat-slide-toggle-bar,[dir=rtl] .mat-slide-toggle-bar{margin-left:8px;margin-right:0}.mat-slide-toggle-bar-no-side-margin{margin-left:0;margin-right:0}.mat-slide-toggle-thumb-container{position:absolute;z-index:1;width:20px;height:20px;top:-3px;left:0;transform:translate3d(0,0,0);transition:all 80ms linear;transition-property:transform;cursor:-webkit-grab;cursor:grab}.mat-slide-toggle-thumb-container.mat-dragging{transition-duration:0s}.mat-slide-toggle-thumb-container:active{cursor:-webkit-grabbing;cursor:grabbing}._mat-animation-noopable .mat-slide-toggle-thumb-container{transition:none}[dir=rtl] .mat-slide-toggle-thumb-container{left:auto;right:0}.mat-slide-toggle-thumb{height:20px;width:20px;border-radius:50%}.mat-slide-toggle-bar{position:relative;width:36px;height:14px;flex-shrink:0;border-radius:8px}.mat-slide-toggle-input{bottom:0;left:10px}[dir=rtl] .mat-slide-toggle-input{left:auto;right:10px}.mat-slide-toggle-bar,.mat-slide-toggle-thumb{transition:all 80ms linear;transition-property:background-color;transition-delay:50ms}._mat-animation-noopable .mat-slide-toggle-bar,._mat-animation-noopable .mat-slide-toggle-thumb{transition:none}.mat-slide-toggle .mat-slide-toggle-ripple{position:absolute;top:calc(50% - 20px);left:calc(50% - 20px);height:40px;width:40px;z-index:1;pointer-events:none}.mat-slide-toggle .mat-slide-toggle-ripple .mat-ripple-element:not(.mat-slide-toggle-persistent-ripple){opacity:.12}.mat-slide-toggle-persistent-ripple{width:100%;height:100%;transform:none}.mat-slide-toggle-bar:hover .mat-slide-toggle-persistent-ripple{opacity:.04}.mat-slide-toggle:not(.mat-disabled).cdk-keyboard-focused .mat-slide-toggle-persistent-ripple{opacity:.12}.mat-slide-toggle-persistent-ripple,.mat-slide-toggle.mat-disabled .mat-slide-toggle-bar:hover .mat-slide-toggle-persistent-ripple{opacity:0}@media (hover:none){.mat-slide-toggle-bar:hover .mat-slide-toggle-persistent-ripple{display:none}}@media (-ms-high-contrast:active){.mat-slide-toggle-thumb{background:#fff;border:1px solid #000}.mat-slide-toggle.mat-checked .mat-slide-toggle-thumb{background:#000;border:1px solid #fff}.mat-slide-toggle-bar{background:#fff}.mat-slide-toggle.cdk-keyboard-focused .mat-slide-toggle-bar{outline:1px dotted;outline-offset:5px}}@media (-ms-high-contrast:black-on-white){.mat-slide-toggle-bar{border:1px solid #000}}"],
  420. providers: [MAT_SLIDE_TOGGLE_VALUE_ACCESSOR],
  421. inputs: ['disabled', 'disableRipple', 'color', 'tabIndex'],
  422. encapsulation: ViewEncapsulation.None,
  423. changeDetection: ChangeDetectionStrategy.OnPush,
  424. },] },
  425. ];
  426. /** @nocollapse */
  427. MatSlideToggle.ctorParameters = () => [
  428. { type: ElementRef },
  429. { type: FocusMonitor },
  430. { type: ChangeDetectorRef },
  431. { type: String, decorators: [{ type: Attribute, args: ['tabindex',] }] },
  432. { type: NgZone },
  433. { type: undefined, decorators: [{ type: Inject, args: [MAT_SLIDE_TOGGLE_DEFAULT_OPTIONS,] }] },
  434. { type: String, decorators: [{ type: Optional }, { type: Inject, args: [ANIMATION_MODULE_TYPE,] }] },
  435. { type: Directionality, decorators: [{ type: Optional }] }
  436. ];
  437. MatSlideToggle.propDecorators = {
  438. _thumbEl: [{ type: ViewChild, args: ['thumbContainer', { static: false },] }],
  439. _thumbBarEl: [{ type: ViewChild, args: ['toggleBar', { static: false },] }],
  440. name: [{ type: Input }],
  441. id: [{ type: Input }],
  442. labelPosition: [{ type: Input }],
  443. ariaLabel: [{ type: Input, args: ['aria-label',] }],
  444. ariaLabelledby: [{ type: Input, args: ['aria-labelledby',] }],
  445. required: [{ type: Input }],
  446. checked: [{ type: Input }],
  447. change: [{ type: Output }],
  448. toggleChange: [{ type: Output }],
  449. dragChange: [{ type: Output }],
  450. _inputElement: [{ type: ViewChild, args: ['input', { static: false },] }]
  451. };
  452. /**
  453. * @fileoverview added by tsickle
  454. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  455. */
  456. /** @type {?} */
  457. const MAT_SLIDE_TOGGLE_REQUIRED_VALIDATOR = {
  458. provide: NG_VALIDATORS,
  459. useExisting: forwardRef((/**
  460. * @return {?}
  461. */
  462. () => MatSlideToggleRequiredValidator)),
  463. multi: true
  464. };
  465. /**
  466. * Validator for Material slide-toggle components with the required attribute in a
  467. * template-driven form. The default validator for required form controls asserts
  468. * that the control value is not undefined but that is not appropriate for a slide-toggle
  469. * where the value is always defined.
  470. *
  471. * Required slide-toggle form controls are valid when checked.
  472. */
  473. class MatSlideToggleRequiredValidator extends CheckboxRequiredValidator {
  474. }
  475. MatSlideToggleRequiredValidator.decorators = [
  476. { type: Directive, args: [{
  477. selector: `mat-slide-toggle[required][formControlName],
  478. mat-slide-toggle[required][formControl], mat-slide-toggle[required][ngModel]`,
  479. providers: [MAT_SLIDE_TOGGLE_REQUIRED_VALIDATOR],
  480. },] },
  481. ];
  482. /**
  483. * @fileoverview added by tsickle
  484. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  485. */
  486. /**
  487. * This module is used by both original and MDC-based slide-toggle implementations.
  488. */
  489. // tslint:disable-next-line:class-name
  490. class _MatSlideToggleRequiredValidatorModule {
  491. }
  492. _MatSlideToggleRequiredValidatorModule.decorators = [
  493. { type: NgModule, args: [{
  494. exports: [MatSlideToggleRequiredValidator],
  495. declarations: [MatSlideToggleRequiredValidator],
  496. },] },
  497. ];
  498. class MatSlideToggleModule {
  499. }
  500. MatSlideToggleModule.decorators = [
  501. { type: NgModule, args: [{
  502. imports: [
  503. _MatSlideToggleRequiredValidatorModule,
  504. MatRippleModule,
  505. MatCommonModule,
  506. ObserversModule,
  507. ],
  508. exports: [
  509. _MatSlideToggleRequiredValidatorModule,
  510. MatSlideToggle,
  511. MatCommonModule
  512. ],
  513. declarations: [MatSlideToggle],
  514. providers: [
  515. { provide: HAMMER_GESTURE_CONFIG, useClass: GestureConfig }
  516. ],
  517. },] },
  518. ];
  519. /**
  520. * @fileoverview added by tsickle
  521. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  522. */
  523. /**
  524. * @fileoverview added by tsickle
  525. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  526. */
  527. export { _MatSlideToggleRequiredValidatorModule, MatSlideToggleModule, MAT_SLIDE_TOGGLE_VALUE_ACCESSOR, MatSlideToggleChange, MatSlideToggle, MAT_SLIDE_TOGGLE_DEFAULT_OPTIONS, MAT_SLIDE_TOGGLE_REQUIRED_VALIDATOR, MatSlideToggleRequiredValidator };
  528. //# sourceMappingURL=slide-toggle.js.map