button-toggle.d.ts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 { AfterContentInit, ChangeDetectorRef, ElementRef, EventEmitter, OnDestroy, OnInit, QueryList, InjectionToken } from '@angular/core';
  10. import { ControlValueAccessor } from '@angular/forms';
  11. import { CanDisableRipple, CanDisableRippleCtor } from '@angular/material/core';
  12. /** Acceptable types for a button toggle. */
  13. export declare type ToggleType = 'checkbox' | 'radio';
  14. /** Possible appearance styles for the button toggle. */
  15. export declare type MatButtonToggleAppearance = 'legacy' | 'standard';
  16. /**
  17. * Represents the default options for the button toggle that can be configured
  18. * using the `MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS` injection token.
  19. */
  20. export interface MatButtonToggleDefaultOptions {
  21. appearance?: MatButtonToggleAppearance;
  22. }
  23. /**
  24. * Injection token that can be used to configure the
  25. * default options for all button toggles within an app.
  26. */
  27. export declare const MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS: InjectionToken<MatButtonToggleDefaultOptions>;
  28. /**
  29. * Provider Expression that allows mat-button-toggle-group to register as a ControlValueAccessor.
  30. * This allows it to support [(ngModel)].
  31. * @docs-private
  32. */
  33. export declare const MAT_BUTTON_TOGGLE_GROUP_VALUE_ACCESSOR: any;
  34. /**
  35. * @deprecated Use `MatButtonToggleGroup` instead.
  36. * @breaking-change 8.0.0
  37. */
  38. export declare class MatButtonToggleGroupMultiple {
  39. }
  40. /** Change event object emitted by MatButtonToggle. */
  41. export declare class MatButtonToggleChange {
  42. /** The MatButtonToggle that emits the event. */
  43. source: MatButtonToggle;
  44. /** The value assigned to the MatButtonToggle. */
  45. value: any;
  46. constructor(
  47. /** The MatButtonToggle that emits the event. */
  48. source: MatButtonToggle,
  49. /** The value assigned to the MatButtonToggle. */
  50. value: any);
  51. }
  52. /** Exclusive selection button toggle group that behaves like a radio-button group. */
  53. export declare class MatButtonToggleGroup implements ControlValueAccessor, OnInit, AfterContentInit {
  54. private _changeDetector;
  55. private _vertical;
  56. private _multiple;
  57. private _disabled;
  58. private _selectionModel;
  59. /**
  60. * Reference to the raw value that the consumer tried to assign. The real
  61. * value will exclude any values from this one that don't correspond to a
  62. * toggle. Useful for the cases where the value is assigned before the toggles
  63. * have been initialized or at the same that they're being swapped out.
  64. */
  65. private _rawValue;
  66. /**
  67. * The method to be called in order to update ngModel.
  68. * Now `ngModel` binding is not supported in multiple selection mode.
  69. */
  70. _controlValueAccessorChangeFn: (value: any) => void;
  71. /** onTouch function registered via registerOnTouch (ControlValueAccessor). */
  72. _onTouched: () => any;
  73. /** Child button toggle buttons. */
  74. _buttonToggles: QueryList<MatButtonToggle>;
  75. /** The appearance for all the buttons in the group. */
  76. appearance: MatButtonToggleAppearance;
  77. /** `name` attribute for the underlying `input` element. */
  78. name: string;
  79. private _name;
  80. /** Whether the toggle group is vertical. */
  81. vertical: boolean;
  82. /** Value of the toggle group. */
  83. value: any;
  84. /**
  85. * Event that emits whenever the value of the group changes.
  86. * Used to facilitate two-way data binding.
  87. * @docs-private
  88. */
  89. readonly valueChange: EventEmitter<any>;
  90. /** Selected button toggles in the group. */
  91. readonly selected: MatButtonToggle | MatButtonToggle[];
  92. /** Whether multiple button toggles can be selected. */
  93. multiple: boolean;
  94. /** Whether multiple button toggle group is disabled. */
  95. disabled: boolean;
  96. /** Event emitted when the group's value changes. */
  97. readonly change: EventEmitter<MatButtonToggleChange>;
  98. constructor(_changeDetector: ChangeDetectorRef, defaultOptions?: MatButtonToggleDefaultOptions);
  99. ngOnInit(): void;
  100. ngAfterContentInit(): void;
  101. /**
  102. * Sets the model value. Implemented as part of ControlValueAccessor.
  103. * @param value Value to be set to the model.
  104. */
  105. writeValue(value: any): void;
  106. registerOnChange(fn: (value: any) => void): void;
  107. registerOnTouched(fn: any): void;
  108. setDisabledState(isDisabled: boolean): void;
  109. /** Dispatch change event with current selection and group value. */
  110. _emitChangeEvent(): void;
  111. /**
  112. * Syncs a button toggle's selected state with the model value.
  113. * @param toggle Toggle to be synced.
  114. * @param select Whether the toggle should be selected.
  115. * @param isUserInput Whether the change was a result of a user interaction.
  116. * @param deferEvents Whether to defer emitting the change events.
  117. */
  118. _syncButtonToggle(toggle: MatButtonToggle, select: boolean, isUserInput?: boolean, deferEvents?: boolean): void;
  119. /** Checks whether a button toggle is selected. */
  120. _isSelected(toggle: MatButtonToggle): boolean;
  121. /** Determines whether a button toggle should be checked on init. */
  122. _isPrechecked(toggle: MatButtonToggle): boolean;
  123. /** Updates the selection state of the toggles in the group based on a value. */
  124. private _setSelectionByValue;
  125. /** Clears the selected toggles. */
  126. private _clearSelection;
  127. /** Selects a value if there's a toggle that corresponds to it. */
  128. private _selectValue;
  129. /** Syncs up the group's value with the model and emits the change event. */
  130. private _updateModelValue;
  131. }
  132. /** @docs-private */
  133. declare class MatButtonToggleBase {
  134. }
  135. declare const _MatButtonToggleMixinBase: CanDisableRippleCtor & typeof MatButtonToggleBase;
  136. /** Single button inside of a toggle group. */
  137. export declare class MatButtonToggle extends _MatButtonToggleMixinBase implements OnInit, CanDisableRipple, OnDestroy {
  138. private _changeDetectorRef;
  139. private _elementRef;
  140. private _focusMonitor;
  141. private _isSingleSelector;
  142. private _checked;
  143. /**
  144. * Attached to the aria-label attribute of the host element. In most cases, aria-labelledby will
  145. * take precedence so this may be omitted.
  146. */
  147. ariaLabel: string;
  148. /**
  149. * Users can specify the `aria-labelledby` attribute which will be forwarded to the input element
  150. */
  151. ariaLabelledby: string | null;
  152. /** Type of the button toggle. Either 'radio' or 'checkbox'. */
  153. _type: ToggleType;
  154. _buttonElement: ElementRef<HTMLButtonElement>;
  155. /** The parent button toggle group (exclusive selection). Optional. */
  156. buttonToggleGroup: MatButtonToggleGroup;
  157. /** Unique ID for the underlying `button` element. */
  158. readonly buttonId: string;
  159. /** The unique ID for this button toggle. */
  160. id: string;
  161. /** HTML's 'name' attribute used to group radios for unique selection. */
  162. name: string;
  163. /** MatButtonToggleGroup reads this to assign its own value. */
  164. value: any;
  165. /** Tabindex for the toggle. */
  166. tabIndex: number | null;
  167. /** The appearance style of the button. */
  168. appearance: MatButtonToggleAppearance;
  169. private _appearance;
  170. /** Whether the button is checked. */
  171. checked: boolean;
  172. /** Whether the button is disabled. */
  173. disabled: boolean;
  174. private _disabled;
  175. /** Event emitted when the group value changes. */
  176. readonly change: EventEmitter<MatButtonToggleChange>;
  177. constructor(toggleGroup: MatButtonToggleGroup, _changeDetectorRef: ChangeDetectorRef, _elementRef: ElementRef<HTMLElement>, _focusMonitor: FocusMonitor, defaultTabIndex: string, defaultOptions?: MatButtonToggleDefaultOptions);
  178. ngOnInit(): void;
  179. ngOnDestroy(): void;
  180. /** Focuses the button. */
  181. focus(options?: FocusOptions): void;
  182. /** Checks the button toggle due to an interaction with the underlying native button. */
  183. _onButtonClick(): void;
  184. /**
  185. * Marks the button toggle as needing checking for change detection.
  186. * This method is exposed because the parent button toggle group will directly
  187. * update bound properties of the radio button.
  188. */
  189. _markForCheck(): void;
  190. }
  191. export {};