button-toggle.d-DoMJU5F_.d.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. import { Direction } from '@angular/cdk/bidi';
  2. import * as i0 from '@angular/core';
  3. import { InjectionToken, OnInit, AfterContentInit, QueryList, EventEmitter, AfterViewInit, OnDestroy, ElementRef } from '@angular/core';
  4. import { ControlValueAccessor } from '@angular/forms';
  5. /**
  6. * @deprecated No longer used.
  7. * @breaking-change 11.0.0
  8. */
  9. type ToggleType = 'checkbox' | 'radio';
  10. /** Possible appearance styles for the button toggle. */
  11. type MatButtonToggleAppearance = 'legacy' | 'standard';
  12. /**
  13. * Represents the default options for the button toggle that can be configured
  14. * using the `MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS` injection token.
  15. */
  16. interface MatButtonToggleDefaultOptions {
  17. /**
  18. * Default appearance to be used by button toggles. Can be overridden by explicitly
  19. * setting an appearance on a button toggle or group.
  20. */
  21. appearance?: MatButtonToggleAppearance;
  22. /** Whether icon indicators should be hidden for single-selection button toggle groups. */
  23. hideSingleSelectionIndicator?: boolean;
  24. /** Whether icon indicators should be hidden for multiple-selection button toggle groups. */
  25. hideMultipleSelectionIndicator?: boolean;
  26. /** Whether disabled toggle buttons should be interactive. */
  27. disabledInteractive?: boolean;
  28. }
  29. /**
  30. * Injection token that can be used to configure the
  31. * default options for all button toggles within an app.
  32. */
  33. declare const MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS: InjectionToken<MatButtonToggleDefaultOptions>;
  34. /**
  35. * @docs-private
  36. * @deprecated No longer used, will be removed.
  37. * @breaking-change 21.0.0
  38. */
  39. declare function MAT_BUTTON_TOGGLE_GROUP_DEFAULT_OPTIONS_FACTORY(): MatButtonToggleDefaultOptions;
  40. /**
  41. * Injection token that can be used to reference instances of `MatButtonToggleGroup`.
  42. * It serves as alternative token to the actual `MatButtonToggleGroup` class which
  43. * could cause unnecessary retention of the class and its component metadata.
  44. */
  45. declare const MAT_BUTTON_TOGGLE_GROUP: InjectionToken<MatButtonToggleGroup>;
  46. /**
  47. * Provider Expression that allows mat-button-toggle-group to register as a ControlValueAccessor.
  48. * This allows it to support [(ngModel)].
  49. * @docs-private
  50. */
  51. declare const MAT_BUTTON_TOGGLE_GROUP_VALUE_ACCESSOR: any;
  52. /** Change event object emitted by button toggle. */
  53. declare class MatButtonToggleChange {
  54. /** The button toggle that emits the event. */
  55. source: MatButtonToggle;
  56. /** The value assigned to the button toggle. */
  57. value: any;
  58. constructor(
  59. /** The button toggle that emits the event. */
  60. source: MatButtonToggle,
  61. /** The value assigned to the button toggle. */
  62. value: any);
  63. }
  64. /** Exclusive selection button toggle group that behaves like a radio-button group. */
  65. declare class MatButtonToggleGroup implements ControlValueAccessor, OnInit, AfterContentInit {
  66. private _changeDetector;
  67. private _dir;
  68. private _multiple;
  69. private _disabled;
  70. private _disabledInteractive;
  71. private _selectionModel;
  72. /**
  73. * Reference to the raw value that the consumer tried to assign. The real
  74. * value will exclude any values from this one that don't correspond to a
  75. * toggle. Useful for the cases where the value is assigned before the toggles
  76. * have been initialized or at the same that they're being swapped out.
  77. */
  78. private _rawValue;
  79. /**
  80. * The method to be called in order to update ngModel.
  81. * Now `ngModel` binding is not supported in multiple selection mode.
  82. */
  83. _controlValueAccessorChangeFn: (value: any) => void;
  84. /** onTouch function registered via registerOnTouch (ControlValueAccessor). */
  85. _onTouched: () => any;
  86. /** Child button toggle buttons. */
  87. _buttonToggles: QueryList<MatButtonToggle>;
  88. /** The appearance for all the buttons in the group. */
  89. appearance: MatButtonToggleAppearance;
  90. /** `name` attribute for the underlying `input` element. */
  91. get name(): string;
  92. set name(value: string);
  93. private _name;
  94. /** Whether the toggle group is vertical. */
  95. vertical: boolean;
  96. /** Value of the toggle group. */
  97. get value(): any;
  98. set value(newValue: any);
  99. /**
  100. * Event that emits whenever the value of the group changes.
  101. * Used to facilitate two-way data binding.
  102. * @docs-private
  103. */
  104. readonly valueChange: EventEmitter<any>;
  105. /** Selected button toggles in the group. */
  106. get selected(): MatButtonToggle | MatButtonToggle[];
  107. /** Whether multiple button toggles can be selected. */
  108. get multiple(): boolean;
  109. set multiple(value: boolean);
  110. /** Whether multiple button toggle group is disabled. */
  111. get disabled(): boolean;
  112. set disabled(value: boolean);
  113. /** Whether buttons in the group should be interactive while they're disabled. */
  114. get disabledInteractive(): boolean;
  115. set disabledInteractive(value: boolean);
  116. /** The layout direction of the toggle button group. */
  117. get dir(): Direction;
  118. /** Event emitted when the group's value changes. */
  119. readonly change: EventEmitter<MatButtonToggleChange>;
  120. /** Whether checkmark indicator for single-selection button toggle groups is hidden. */
  121. get hideSingleSelectionIndicator(): boolean;
  122. set hideSingleSelectionIndicator(value: boolean);
  123. private _hideSingleSelectionIndicator;
  124. /** Whether checkmark indicator for multiple-selection button toggle groups is hidden. */
  125. get hideMultipleSelectionIndicator(): boolean;
  126. set hideMultipleSelectionIndicator(value: boolean);
  127. private _hideMultipleSelectionIndicator;
  128. constructor(...args: unknown[]);
  129. ngOnInit(): void;
  130. ngAfterContentInit(): void;
  131. /**
  132. * Sets the model value. Implemented as part of ControlValueAccessor.
  133. * @param value Value to be set to the model.
  134. */
  135. writeValue(value: any): void;
  136. registerOnChange(fn: (value: any) => void): void;
  137. registerOnTouched(fn: any): void;
  138. setDisabledState(isDisabled: boolean): void;
  139. /** Handle keydown event calling to single-select button toggle. */
  140. protected _keydown(event: KeyboardEvent): void;
  141. /** Dispatch change event with current selection and group value. */
  142. _emitChangeEvent(toggle: MatButtonToggle): void;
  143. /**
  144. * Syncs a button toggle's selected state with the model value.
  145. * @param toggle Toggle to be synced.
  146. * @param select Whether the toggle should be selected.
  147. * @param isUserInput Whether the change was a result of a user interaction.
  148. * @param deferEvents Whether to defer emitting the change events.
  149. */
  150. _syncButtonToggle(toggle: MatButtonToggle, select: boolean, isUserInput?: boolean, deferEvents?: boolean): void;
  151. /** Checks whether a button toggle is selected. */
  152. _isSelected(toggle: MatButtonToggle): boolean;
  153. /** Determines whether a button toggle should be checked on init. */
  154. _isPrechecked(toggle: MatButtonToggle): boolean;
  155. /** Initializes the tabindex attribute using the radio pattern. */
  156. private _initializeTabIndex;
  157. /** Obtain the subsequent toggle to which the focus shifts. */
  158. private _getNextButton;
  159. /** Updates the selection state of the toggles in the group based on a value. */
  160. private _setSelectionByValue;
  161. /** Clears the selected toggles. */
  162. private _clearSelection;
  163. /** Selects a value if there's a toggle that corresponds to it. */
  164. private _selectValue;
  165. /** Syncs up the group's value with the model and emits the change event. */
  166. private _updateModelValue;
  167. /** Marks all of the child button toggles to be checked. */
  168. private _markButtonsForCheck;
  169. static ɵfac: i0.ɵɵFactoryDeclaration<MatButtonToggleGroup, never>;
  170. static ɵdir: i0.ɵɵDirectiveDeclaration<MatButtonToggleGroup, "mat-button-toggle-group", ["matButtonToggleGroup"], { "appearance": { "alias": "appearance"; "required": false; }; "name": { "alias": "name"; "required": false; }; "vertical": { "alias": "vertical"; "required": false; }; "value": { "alias": "value"; "required": false; }; "multiple": { "alias": "multiple"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; "disabledInteractive": { "alias": "disabledInteractive"; "required": false; }; "hideSingleSelectionIndicator": { "alias": "hideSingleSelectionIndicator"; "required": false; }; "hideMultipleSelectionIndicator": { "alias": "hideMultipleSelectionIndicator"; "required": false; }; }, { "valueChange": "valueChange"; "change": "change"; }, ["_buttonToggles"], never, true, never>;
  171. static ngAcceptInputType_vertical: unknown;
  172. static ngAcceptInputType_multiple: unknown;
  173. static ngAcceptInputType_disabled: unknown;
  174. static ngAcceptInputType_disabledInteractive: unknown;
  175. static ngAcceptInputType_hideSingleSelectionIndicator: unknown;
  176. static ngAcceptInputType_hideMultipleSelectionIndicator: unknown;
  177. }
  178. /** Single button inside of a toggle group. */
  179. declare class MatButtonToggle implements OnInit, AfterViewInit, OnDestroy {
  180. private _changeDetectorRef;
  181. private _elementRef;
  182. private _focusMonitor;
  183. private _idGenerator;
  184. private _animationMode;
  185. private _checked;
  186. /**
  187. * Attached to the aria-label attribute of the host element. In most cases, aria-labelledby will
  188. * take precedence so this may be omitted.
  189. */
  190. ariaLabel: string;
  191. /**
  192. * Users can specify the `aria-labelledby` attribute which will be forwarded to the input element
  193. */
  194. ariaLabelledby: string | null;
  195. /** Underlying native `button` element. */
  196. _buttonElement: ElementRef<HTMLButtonElement>;
  197. /** The parent button toggle group (exclusive selection). Optional. */
  198. buttonToggleGroup: MatButtonToggleGroup;
  199. /** Unique ID for the underlying `button` element. */
  200. get buttonId(): string;
  201. /** The unique ID for this button toggle. */
  202. id: string;
  203. /** HTML's 'name' attribute used to group radios for unique selection. */
  204. name: string;
  205. /** MatButtonToggleGroup reads this to assign its own value. */
  206. value: any;
  207. /** Tabindex of the toggle. */
  208. get tabIndex(): number | null;
  209. set tabIndex(value: number | null);
  210. private _tabIndex;
  211. /** Whether ripples are disabled on the button toggle. */
  212. disableRipple: boolean;
  213. /** The appearance style of the button. */
  214. get appearance(): MatButtonToggleAppearance;
  215. set appearance(value: MatButtonToggleAppearance);
  216. private _appearance;
  217. /** Whether the button is checked. */
  218. get checked(): boolean;
  219. set checked(value: boolean);
  220. /** Whether the button is disabled. */
  221. get disabled(): boolean;
  222. set disabled(value: boolean);
  223. private _disabled;
  224. /** Whether the button should remain interactive when it is disabled. */
  225. get disabledInteractive(): boolean;
  226. set disabledInteractive(value: boolean);
  227. private _disabledInteractive;
  228. /** Event emitted when the group value changes. */
  229. readonly change: EventEmitter<MatButtonToggleChange>;
  230. constructor(...args: unknown[]);
  231. ngOnInit(): void;
  232. ngAfterViewInit(): void;
  233. ngOnDestroy(): void;
  234. /** Focuses the button. */
  235. focus(options?: FocusOptions): void;
  236. /** Checks the button toggle due to an interaction with the underlying native button. */
  237. _onButtonClick(): void;
  238. /**
  239. * Marks the button toggle as needing checking for change detection.
  240. * This method is exposed because the parent button toggle group will directly
  241. * update bound properties of the radio button.
  242. */
  243. _markForCheck(): void;
  244. /** Gets the name that should be assigned to the inner DOM node. */
  245. _getButtonName(): string | null;
  246. /** Whether the toggle is in single selection mode. */
  247. isSingleSelector(): boolean;
  248. static ɵfac: i0.ɵɵFactoryDeclaration<MatButtonToggle, never>;
  249. static ɵcmp: i0.ɵɵComponentDeclaration<MatButtonToggle, "mat-button-toggle", ["matButtonToggle"], { "ariaLabel": { "alias": "aria-label"; "required": false; }; "ariaLabelledby": { "alias": "aria-labelledby"; "required": false; }; "id": { "alias": "id"; "required": false; }; "name": { "alias": "name"; "required": false; }; "value": { "alias": "value"; "required": false; }; "tabIndex": { "alias": "tabIndex"; "required": false; }; "disableRipple": { "alias": "disableRipple"; "required": false; }; "appearance": { "alias": "appearance"; "required": false; }; "checked": { "alias": "checked"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; "disabledInteractive": { "alias": "disabledInteractive"; "required": false; }; }, { "change": "change"; }, never, ["*"], true, never>;
  250. static ngAcceptInputType_disableRipple: unknown;
  251. static ngAcceptInputType_checked: unknown;
  252. static ngAcceptInputType_disabled: unknown;
  253. static ngAcceptInputType_disabledInteractive: unknown;
  254. }
  255. export { MatButtonToggleGroup as M, MatButtonToggle as a, MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS as d, MAT_BUTTON_TOGGLE_GROUP_DEFAULT_OPTIONS_FACTORY as e, MAT_BUTTON_TOGGLE_GROUP as f, MAT_BUTTON_TOGGLE_GROUP_VALUE_ACCESSOR as g, MatButtonToggleChange as h };
  256. export type { ToggleType as T, MatButtonToggleAppearance as b, MatButtonToggleDefaultOptions as c };