button-toggle.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  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 { FocusMonitor } from '@angular/cdk/a11y';
  9. import { coerceBooleanProperty } from '@angular/cdk/coercion';
  10. import { SelectionModel } from '@angular/cdk/collections';
  11. import { Attribute, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChildren, Directive, ElementRef, EventEmitter, forwardRef, Input, Optional, Output, ViewChild, ViewEncapsulation, InjectionToken, Inject, NgModule } from '@angular/core';
  12. import { NG_VALUE_ACCESSOR } from '@angular/forms';
  13. import { mixinDisableRipple, MatCommonModule, MatRippleModule } from '@angular/material/core';
  14. /**
  15. * @fileoverview added by tsickle
  16. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  17. */
  18. /**
  19. * Injection token that can be used to configure the
  20. * default options for all button toggles within an app.
  21. * @type {?}
  22. */
  23. const MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS = new InjectionToken('MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS');
  24. /**
  25. * Provider Expression that allows mat-button-toggle-group to register as a ControlValueAccessor.
  26. * This allows it to support [(ngModel)].
  27. * \@docs-private
  28. * @type {?}
  29. */
  30. const MAT_BUTTON_TOGGLE_GROUP_VALUE_ACCESSOR = {
  31. provide: NG_VALUE_ACCESSOR,
  32. useExisting: forwardRef((/**
  33. * @return {?}
  34. */
  35. () => MatButtonToggleGroup)),
  36. multi: true
  37. };
  38. /**
  39. * @deprecated Use `MatButtonToggleGroup` instead.
  40. * \@breaking-change 8.0.0
  41. */
  42. class MatButtonToggleGroupMultiple {
  43. }
  44. /** @type {?} */
  45. let _uniqueIdCounter = 0;
  46. /**
  47. * Change event object emitted by MatButtonToggle.
  48. */
  49. class MatButtonToggleChange {
  50. /**
  51. * @param {?} source
  52. * @param {?} value
  53. */
  54. constructor(source, value) {
  55. this.source = source;
  56. this.value = value;
  57. }
  58. }
  59. /**
  60. * Exclusive selection button toggle group that behaves like a radio-button group.
  61. */
  62. class MatButtonToggleGroup {
  63. /**
  64. * @param {?} _changeDetector
  65. * @param {?=} defaultOptions
  66. */
  67. constructor(_changeDetector, defaultOptions) {
  68. this._changeDetector = _changeDetector;
  69. this._vertical = false;
  70. this._multiple = false;
  71. this._disabled = false;
  72. /**
  73. * The method to be called in order to update ngModel.
  74. * Now `ngModel` binding is not supported in multiple selection mode.
  75. */
  76. this._controlValueAccessorChangeFn = (/**
  77. * @return {?}
  78. */
  79. () => { });
  80. /**
  81. * onTouch function registered via registerOnTouch (ControlValueAccessor).
  82. */
  83. this._onTouched = (/**
  84. * @return {?}
  85. */
  86. () => { });
  87. this._name = `mat-button-toggle-group-${_uniqueIdCounter++}`;
  88. /**
  89. * Event that emits whenever the value of the group changes.
  90. * Used to facilitate two-way data binding.
  91. * \@docs-private
  92. */
  93. this.valueChange = new EventEmitter();
  94. /**
  95. * Event emitted when the group's value changes.
  96. */
  97. this.change = new EventEmitter();
  98. this.appearance =
  99. defaultOptions && defaultOptions.appearance ? defaultOptions.appearance : 'standard';
  100. }
  101. /**
  102. * `name` attribute for the underlying `input` element.
  103. * @return {?}
  104. */
  105. get name() { return this._name; }
  106. /**
  107. * @param {?} value
  108. * @return {?}
  109. */
  110. set name(value) {
  111. this._name = value;
  112. if (this._buttonToggles) {
  113. this._buttonToggles.forEach((/**
  114. * @param {?} toggle
  115. * @return {?}
  116. */
  117. toggle => {
  118. toggle.name = this._name;
  119. toggle._markForCheck();
  120. }));
  121. }
  122. }
  123. /**
  124. * Whether the toggle group is vertical.
  125. * @return {?}
  126. */
  127. get vertical() { return this._vertical; }
  128. /**
  129. * @param {?} value
  130. * @return {?}
  131. */
  132. set vertical(value) {
  133. this._vertical = coerceBooleanProperty(value);
  134. }
  135. /**
  136. * Value of the toggle group.
  137. * @return {?}
  138. */
  139. get value() {
  140. /** @type {?} */
  141. const selected = this._selectionModel ? this._selectionModel.selected : [];
  142. if (this.multiple) {
  143. return selected.map((/**
  144. * @param {?} toggle
  145. * @return {?}
  146. */
  147. toggle => toggle.value));
  148. }
  149. return selected[0] ? selected[0].value : undefined;
  150. }
  151. /**
  152. * @param {?} newValue
  153. * @return {?}
  154. */
  155. set value(newValue) {
  156. this._setSelectionByValue(newValue);
  157. this.valueChange.emit(this.value);
  158. }
  159. /**
  160. * Selected button toggles in the group.
  161. * @return {?}
  162. */
  163. get selected() {
  164. /** @type {?} */
  165. const selected = this._selectionModel ? this._selectionModel.selected : [];
  166. return this.multiple ? selected : (selected[0] || null);
  167. }
  168. /**
  169. * Whether multiple button toggles can be selected.
  170. * @return {?}
  171. */
  172. get multiple() { return this._multiple; }
  173. /**
  174. * @param {?} value
  175. * @return {?}
  176. */
  177. set multiple(value) {
  178. this._multiple = coerceBooleanProperty(value);
  179. }
  180. /**
  181. * Whether multiple button toggle group is disabled.
  182. * @return {?}
  183. */
  184. get disabled() { return this._disabled; }
  185. /**
  186. * @param {?} value
  187. * @return {?}
  188. */
  189. set disabled(value) {
  190. this._disabled = coerceBooleanProperty(value);
  191. if (this._buttonToggles) {
  192. this._buttonToggles.forEach((/**
  193. * @param {?} toggle
  194. * @return {?}
  195. */
  196. toggle => toggle._markForCheck()));
  197. }
  198. }
  199. /**
  200. * @return {?}
  201. */
  202. ngOnInit() {
  203. this._selectionModel = new SelectionModel(this.multiple, undefined, false);
  204. }
  205. /**
  206. * @return {?}
  207. */
  208. ngAfterContentInit() {
  209. this._selectionModel.select(...this._buttonToggles.filter((/**
  210. * @param {?} toggle
  211. * @return {?}
  212. */
  213. toggle => toggle.checked)));
  214. }
  215. /**
  216. * Sets the model value. Implemented as part of ControlValueAccessor.
  217. * @param {?} value Value to be set to the model.
  218. * @return {?}
  219. */
  220. writeValue(value) {
  221. this.value = value;
  222. this._changeDetector.markForCheck();
  223. }
  224. // Implemented as part of ControlValueAccessor.
  225. /**
  226. * @param {?} fn
  227. * @return {?}
  228. */
  229. registerOnChange(fn) {
  230. this._controlValueAccessorChangeFn = fn;
  231. }
  232. // Implemented as part of ControlValueAccessor.
  233. /**
  234. * @param {?} fn
  235. * @return {?}
  236. */
  237. registerOnTouched(fn) {
  238. this._onTouched = fn;
  239. }
  240. // Implemented as part of ControlValueAccessor.
  241. /**
  242. * @param {?} isDisabled
  243. * @return {?}
  244. */
  245. setDisabledState(isDisabled) {
  246. this.disabled = isDisabled;
  247. }
  248. /**
  249. * Dispatch change event with current selection and group value.
  250. * @return {?}
  251. */
  252. _emitChangeEvent() {
  253. /** @type {?} */
  254. const selected = this.selected;
  255. /** @type {?} */
  256. const source = Array.isArray(selected) ? selected[selected.length - 1] : selected;
  257. /** @type {?} */
  258. const event = new MatButtonToggleChange((/** @type {?} */ (source)), this.value);
  259. this._controlValueAccessorChangeFn(event.value);
  260. this.change.emit(event);
  261. }
  262. /**
  263. * Syncs a button toggle's selected state with the model value.
  264. * @param {?} toggle Toggle to be synced.
  265. * @param {?} select Whether the toggle should be selected.
  266. * @param {?=} isUserInput Whether the change was a result of a user interaction.
  267. * @param {?=} deferEvents Whether to defer emitting the change events.
  268. * @return {?}
  269. */
  270. _syncButtonToggle(toggle, select, isUserInput = false, deferEvents = false) {
  271. // Deselect the currently-selected toggle, if we're in single-selection
  272. // mode and the button being toggled isn't selected at the moment.
  273. if (!this.multiple && this.selected && !toggle.checked) {
  274. ((/** @type {?} */ (this.selected))).checked = false;
  275. }
  276. if (this._selectionModel) {
  277. if (select) {
  278. this._selectionModel.select(toggle);
  279. }
  280. else {
  281. this._selectionModel.deselect(toggle);
  282. }
  283. }
  284. else {
  285. deferEvents = true;
  286. }
  287. // We need to defer in some cases in order to avoid "changed after checked errors", however
  288. // the side-effect is that we may end up updating the model value out of sequence in others
  289. // The `deferEvents` flag allows us to decide whether to do it on a case-by-case basis.
  290. if (deferEvents) {
  291. }
  292. else {
  293. this._updateModelValue(isUserInput);
  294. }
  295. }
  296. /**
  297. * Checks whether a button toggle is selected.
  298. * @param {?} toggle
  299. * @return {?}
  300. */
  301. _isSelected(toggle) {
  302. return this._selectionModel && this._selectionModel.isSelected(toggle);
  303. }
  304. /**
  305. * Determines whether a button toggle should be checked on init.
  306. * @param {?} toggle
  307. * @return {?}
  308. */
  309. _isPrechecked(toggle) {
  310. if (typeof this._rawValue === 'undefined') {
  311. return false;
  312. }
  313. if (this.multiple && Array.isArray(this._rawValue)) {
  314. return this._rawValue.some((/**
  315. * @param {?} value
  316. * @return {?}
  317. */
  318. value => toggle.value != null && value === toggle.value));
  319. }
  320. return toggle.value === this._rawValue;
  321. }
  322. /**
  323. * Updates the selection state of the toggles in the group based on a value.
  324. * @private
  325. * @param {?} value
  326. * @return {?}
  327. */
  328. _setSelectionByValue(value) {
  329. this._rawValue = value;
  330. if (!this._buttonToggles) {
  331. return;
  332. }
  333. if (this.multiple && value) {
  334. if (!Array.isArray(value)) {
  335. throw Error('Value must be an array in multiple-selection mode.');
  336. }
  337. this._clearSelection();
  338. value.forEach((/**
  339. * @param {?} currentValue
  340. * @return {?}
  341. */
  342. (currentValue) => this._selectValue(currentValue)));
  343. }
  344. else {
  345. this._clearSelection();
  346. this._selectValue(value);
  347. }
  348. }
  349. /**
  350. * Clears the selected toggles.
  351. * @private
  352. * @return {?}
  353. */
  354. _clearSelection() {
  355. this._selectionModel.clear();
  356. this._buttonToggles.forEach((/**
  357. * @param {?} toggle
  358. * @return {?}
  359. */
  360. toggle => toggle.checked = false));
  361. }
  362. /**
  363. * Selects a value if there's a toggle that corresponds to it.
  364. * @private
  365. * @param {?} value
  366. * @return {?}
  367. */
  368. _selectValue(value) {
  369. /** @type {?} */
  370. const correspondingOption = this._buttonToggles.find((/**
  371. * @param {?} toggle
  372. * @return {?}
  373. */
  374. toggle => {
  375. return toggle.value != null && toggle.value === value;
  376. }));
  377. if (correspondingOption) {
  378. correspondingOption.checked = true;
  379. this._selectionModel.select(correspondingOption);
  380. }
  381. }
  382. /**
  383. * Syncs up the group's value with the model and emits the change event.
  384. * @private
  385. * @param {?} isUserInput
  386. * @return {?}
  387. */
  388. _updateModelValue(isUserInput) {
  389. // Only emit the change event for user input.
  390. if (isUserInput) {
  391. this._emitChangeEvent();
  392. }
  393. // Note: we emit this one no matter whether it was a user interaction, because
  394. // it is used by Angular to sync up the two-way data binding.
  395. this.valueChange.emit(this.value);
  396. }
  397. }
  398. MatButtonToggleGroup.decorators = [
  399. { type: Directive, args: [{
  400. selector: 'mat-button-toggle-group',
  401. providers: [
  402. MAT_BUTTON_TOGGLE_GROUP_VALUE_ACCESSOR,
  403. { provide: MatButtonToggleGroupMultiple, useExisting: MatButtonToggleGroup },
  404. ],
  405. host: {
  406. 'role': 'group',
  407. 'class': 'mat-button-toggle-group',
  408. '[attr.aria-disabled]': 'disabled',
  409. '[class.mat-button-toggle-vertical]': 'vertical',
  410. '[class.mat-button-toggle-group-appearance-standard]': 'appearance === "standard"',
  411. },
  412. exportAs: 'matButtonToggleGroup',
  413. },] },
  414. ];
  415. /** @nocollapse */
  416. MatButtonToggleGroup.ctorParameters = () => [
  417. { type: ChangeDetectorRef },
  418. { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS,] }] }
  419. ];
  420. MatButtonToggleGroup.propDecorators = {
  421. _buttonToggles: [{ type: ContentChildren, args: [forwardRef((/**
  422. * @return {?}
  423. */
  424. () => MatButtonToggle)),] }],
  425. appearance: [{ type: Input }],
  426. name: [{ type: Input }],
  427. vertical: [{ type: Input }],
  428. value: [{ type: Input }],
  429. valueChange: [{ type: Output }],
  430. multiple: [{ type: Input }],
  431. disabled: [{ type: Input }],
  432. change: [{ type: Output }]
  433. };
  434. // Boilerplate for applying mixins to the MatButtonToggle class.
  435. /**
  436. * \@docs-private
  437. */
  438. class MatButtonToggleBase {
  439. }
  440. /** @type {?} */
  441. const _MatButtonToggleMixinBase = mixinDisableRipple(MatButtonToggleBase);
  442. /**
  443. * Single button inside of a toggle group.
  444. */
  445. class MatButtonToggle extends _MatButtonToggleMixinBase {
  446. /**
  447. * @param {?} toggleGroup
  448. * @param {?} _changeDetectorRef
  449. * @param {?} _elementRef
  450. * @param {?} _focusMonitor
  451. * @param {?} defaultTabIndex
  452. * @param {?=} defaultOptions
  453. */
  454. constructor(toggleGroup, _changeDetectorRef, _elementRef, _focusMonitor,
  455. // @breaking-change 8.0.0 `defaultTabIndex` to be made a required parameter.
  456. defaultTabIndex, defaultOptions) {
  457. super();
  458. this._changeDetectorRef = _changeDetectorRef;
  459. this._elementRef = _elementRef;
  460. this._focusMonitor = _focusMonitor;
  461. this._isSingleSelector = false;
  462. this._checked = false;
  463. /**
  464. * Users can specify the `aria-labelledby` attribute which will be forwarded to the input element
  465. */
  466. this.ariaLabelledby = null;
  467. this._disabled = false;
  468. /**
  469. * Event emitted when the group value changes.
  470. */
  471. this.change = new EventEmitter();
  472. /** @type {?} */
  473. const parsedTabIndex = Number(defaultTabIndex);
  474. this.tabIndex = (parsedTabIndex || parsedTabIndex === 0) ? parsedTabIndex : null;
  475. this.buttonToggleGroup = toggleGroup;
  476. this.appearance =
  477. defaultOptions && defaultOptions.appearance ? defaultOptions.appearance : 'standard';
  478. }
  479. /**
  480. * Unique ID for the underlying `button` element.
  481. * @return {?}
  482. */
  483. get buttonId() { return `${this.id}-button`; }
  484. /**
  485. * The appearance style of the button.
  486. * @return {?}
  487. */
  488. get appearance() {
  489. return this.buttonToggleGroup ? this.buttonToggleGroup.appearance : this._appearance;
  490. }
  491. /**
  492. * @param {?} value
  493. * @return {?}
  494. */
  495. set appearance(value) {
  496. this._appearance = value;
  497. }
  498. /**
  499. * Whether the button is checked.
  500. * @return {?}
  501. */
  502. get checked() {
  503. return this.buttonToggleGroup ? this.buttonToggleGroup._isSelected(this) : this._checked;
  504. }
  505. /**
  506. * @param {?} value
  507. * @return {?}
  508. */
  509. set checked(value) {
  510. /** @type {?} */
  511. const newValue = coerceBooleanProperty(value);
  512. if (newValue !== this._checked) {
  513. this._checked = newValue;
  514. if (this.buttonToggleGroup) {
  515. this.buttonToggleGroup._syncButtonToggle(this, this._checked);
  516. }
  517. this._changeDetectorRef.markForCheck();
  518. }
  519. }
  520. /**
  521. * Whether the button is disabled.
  522. * @return {?}
  523. */
  524. get disabled() {
  525. return this._disabled || (this.buttonToggleGroup && this.buttonToggleGroup.disabled);
  526. }
  527. /**
  528. * @param {?} value
  529. * @return {?}
  530. */
  531. set disabled(value) { this._disabled = coerceBooleanProperty(value); }
  532. /**
  533. * @return {?}
  534. */
  535. ngOnInit() {
  536. this._isSingleSelector = this.buttonToggleGroup && !this.buttonToggleGroup.multiple;
  537. this._type = this._isSingleSelector ? 'radio' : 'checkbox';
  538. this.id = this.id || `mat-button-toggle-${_uniqueIdCounter++}`;
  539. if (this._isSingleSelector) {
  540. this.name = this.buttonToggleGroup.name;
  541. }
  542. if (this.buttonToggleGroup && this.buttonToggleGroup._isPrechecked(this)) {
  543. this.checked = true;
  544. }
  545. this._focusMonitor.monitor(this._elementRef, true);
  546. }
  547. /**
  548. * @return {?}
  549. */
  550. ngOnDestroy() {
  551. /** @type {?} */
  552. const group = this.buttonToggleGroup;
  553. this._focusMonitor.stopMonitoring(this._elementRef);
  554. // Remove the toggle from the selection once it's destroyed. Needs to happen
  555. // on the next tick in order to avoid "changed after checked" errors.
  556. if (group && group._isSelected(this)) {
  557. group._syncButtonToggle(this, false, false, true);
  558. }
  559. }
  560. /**
  561. * Focuses the button.
  562. * @param {?=} options
  563. * @return {?}
  564. */
  565. focus(options) {
  566. this._buttonElement.nativeElement.focus(options);
  567. }
  568. /**
  569. * Checks the button toggle due to an interaction with the underlying native button.
  570. * @return {?}
  571. */
  572. _onButtonClick() {
  573. /** @type {?} */
  574. const newChecked = this._isSingleSelector ? true : !this._checked;
  575. if (newChecked !== this._checked) {
  576. this._checked = newChecked;
  577. if (this.buttonToggleGroup) {
  578. this.buttonToggleGroup._syncButtonToggle(this, this._checked, true);
  579. this.buttonToggleGroup._onTouched();
  580. }
  581. }
  582. // Emit a change event when it's the single selector
  583. this.change.emit(new MatButtonToggleChange(this, this.value));
  584. }
  585. /**
  586. * Marks the button toggle as needing checking for change detection.
  587. * This method is exposed because the parent button toggle group will directly
  588. * update bound properties of the radio button.
  589. * @return {?}
  590. */
  591. _markForCheck() {
  592. // When the group value changes, the button will not be notified.
  593. // Use `markForCheck` to explicit update button toggle's status.
  594. this._changeDetectorRef.markForCheck();
  595. }
  596. }
  597. MatButtonToggle.decorators = [
  598. { type: Component, args: [{selector: 'mat-button-toggle',
  599. template: "<button #button class=\"mat-button-toggle-button\" type=\"button\" [id]=\"buttonId\" [attr.tabindex]=\"disabled ? -1 : tabIndex\" [attr.aria-pressed]=\"checked\" [disabled]=\"disabled || null\" [attr.name]=\"name || null\" [attr.aria-label]=\"ariaLabel\" [attr.aria-labelledby]=\"ariaLabelledby\" (click)=\"_onButtonClick()\"><div class=\"mat-button-toggle-label-content\"><ng-content></ng-content></div></button><div class=\"mat-button-toggle-focus-overlay\"></div><div class=\"mat-button-toggle-ripple\" matRipple [matRippleTrigger]=\"button\" [matRippleDisabled]=\"this.disableRipple || this.disabled\"></div>",
  600. styles: [".mat-button-toggle-group,.mat-button-toggle-standalone{position:relative;display:inline-flex;flex-direction:row;white-space:nowrap;overflow:hidden;border-radius:2px;-webkit-tap-highlight-color:transparent}@media (-ms-high-contrast:active){.mat-button-toggle-group,.mat-button-toggle-standalone{outline:solid 1px}}.mat-button-toggle-group-appearance-standard,.mat-button-toggle-standalone.mat-button-toggle-appearance-standard{border-radius:4px}@media (-ms-high-contrast:active){.mat-button-toggle-group-appearance-standard,.mat-button-toggle-standalone.mat-button-toggle-appearance-standard{outline:0}}.mat-button-toggle-vertical{flex-direction:column}.mat-button-toggle-vertical .mat-button-toggle-label-content{display:block}.mat-button-toggle{white-space:nowrap;position:relative}.mat-button-toggle .mat-icon svg{vertical-align:top}.mat-button-toggle.cdk-keyboard-focused .mat-button-toggle-focus-overlay{opacity:1}@media (-ms-high-contrast:active){.mat-button-toggle.cdk-keyboard-focused .mat-button-toggle-focus-overlay{opacity:.5}}.mat-button-toggle-appearance-standard:not(.mat-button-toggle-disabled):hover .mat-button-toggle-focus-overlay{opacity:.04}.mat-button-toggle-appearance-standard.cdk-keyboard-focused:not(.mat-button-toggle-disabled) .mat-button-toggle-focus-overlay{opacity:.12}@media (-ms-high-contrast:active){.mat-button-toggle-appearance-standard.cdk-keyboard-focused:not(.mat-button-toggle-disabled) .mat-button-toggle-focus-overlay{opacity:.5}}@media (hover:none){.mat-button-toggle-appearance-standard:not(.mat-button-toggle-disabled):hover .mat-button-toggle-focus-overlay{display:none}}.mat-button-toggle-label-content{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;display:inline-block;line-height:36px;padding:0 16px;position:relative}.mat-button-toggle-appearance-standard .mat-button-toggle-label-content{line-height:48px;padding:0 12px}.mat-button-toggle-label-content>*{vertical-align:middle}.mat-button-toggle-focus-overlay{border-radius:inherit;pointer-events:none;opacity:0;top:0;left:0;right:0;bottom:0;position:absolute}.mat-button-toggle-checked .mat-button-toggle-focus-overlay{border-bottom:solid 36px}@media (-ms-high-contrast:active){.mat-button-toggle-checked .mat-button-toggle-focus-overlay{opacity:.5;height:0}}@media (-ms-high-contrast:active){.mat-button-toggle-checked.mat-button-toggle-appearance-standard .mat-button-toggle-focus-overlay{border-bottom:solid 48px}}.mat-button-toggle .mat-button-toggle-ripple{top:0;left:0;right:0;bottom:0;position:absolute;pointer-events:none}.mat-button-toggle-button{border:0;background:0 0;color:inherit;padding:0;margin:0;font:inherit;outline:0;width:100%;cursor:pointer}.mat-button-toggle-disabled .mat-button-toggle-button{cursor:default}.mat-button-toggle-button::-moz-focus-inner{border:0}"],
  601. encapsulation: ViewEncapsulation.None,
  602. exportAs: 'matButtonToggle',
  603. changeDetection: ChangeDetectionStrategy.OnPush,
  604. inputs: ['disableRipple'],
  605. host: {
  606. '[class.mat-button-toggle-standalone]': '!buttonToggleGroup',
  607. '[class.mat-button-toggle-checked]': 'checked',
  608. '[class.mat-button-toggle-disabled]': 'disabled',
  609. '[class.mat-button-toggle-appearance-standard]': 'appearance === "standard"',
  610. 'class': 'mat-button-toggle',
  611. // Always reset the tabindex to -1 so it doesn't conflict with the one on the `button`,
  612. // but can still receive focus from things like cdkFocusInitial.
  613. '[attr.tabindex]': '-1',
  614. '[attr.id]': 'id',
  615. '[attr.name]': 'null',
  616. '(focus)': 'focus()',
  617. }
  618. },] },
  619. ];
  620. /** @nocollapse */
  621. MatButtonToggle.ctorParameters = () => [
  622. { type: MatButtonToggleGroup, decorators: [{ type: Optional }] },
  623. { type: ChangeDetectorRef },
  624. { type: ElementRef },
  625. { type: FocusMonitor },
  626. { type: String, decorators: [{ type: Attribute, args: ['tabindex',] }] },
  627. { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS,] }] }
  628. ];
  629. MatButtonToggle.propDecorators = {
  630. ariaLabel: [{ type: Input, args: ['aria-label',] }],
  631. ariaLabelledby: [{ type: Input, args: ['aria-labelledby',] }],
  632. _buttonElement: [{ type: ViewChild, args: ['button', { static: false },] }],
  633. id: [{ type: Input }],
  634. name: [{ type: Input }],
  635. value: [{ type: Input }],
  636. tabIndex: [{ type: Input }],
  637. appearance: [{ type: Input }],
  638. checked: [{ type: Input }],
  639. disabled: [{ type: Input }],
  640. change: [{ type: Output }]
  641. };
  642. /**
  643. * @fileoverview added by tsickle
  644. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  645. */
  646. class MatButtonToggleModule {
  647. }
  648. MatButtonToggleModule.decorators = [
  649. { type: NgModule, args: [{
  650. imports: [MatCommonModule, MatRippleModule],
  651. exports: [MatCommonModule, MatButtonToggleGroup, MatButtonToggle],
  652. declarations: [MatButtonToggleGroup, MatButtonToggle],
  653. },] },
  654. ];
  655. /**
  656. * @fileoverview added by tsickle
  657. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  658. */
  659. /**
  660. * @fileoverview added by tsickle
  661. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  662. */
  663. export { MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS, MAT_BUTTON_TOGGLE_GROUP_VALUE_ACCESSOR, MatButtonToggleGroupMultiple, MatButtonToggleChange, MatButtonToggleGroup, MatButtonToggle, MatButtonToggleModule };
  664. //# sourceMappingURL=button-toggle.js.map