radio.d.ts 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 { UniqueSelectionDispatcher } from '@angular/cdk/collections';
  10. import { AfterContentInit, AfterViewInit, ChangeDetectorRef, ElementRef, EventEmitter, InjectionToken, OnDestroy, OnInit, QueryList } from '@angular/core';
  11. import { ControlValueAccessor } from '@angular/forms';
  12. import { CanDisableRipple, CanDisableRippleCtor, HasTabIndex, HasTabIndexCtor, ThemePalette } from '@angular/material/core';
  13. export interface MatRadioDefaultOptions {
  14. color: ThemePalette;
  15. }
  16. export declare const MAT_RADIO_DEFAULT_OPTIONS: InjectionToken<MatRadioDefaultOptions>;
  17. export declare function MAT_RADIO_DEFAULT_OPTIONS_FACTORY(): MatRadioDefaultOptions;
  18. /**
  19. * Provider Expression that allows mat-radio-group to register as a ControlValueAccessor. This
  20. * allows it to support [(ngModel)] and ngControl.
  21. * @docs-private
  22. */
  23. export declare const MAT_RADIO_GROUP_CONTROL_VALUE_ACCESSOR: any;
  24. /** Change event object emitted by MatRadio and MatRadioGroup. */
  25. export declare class MatRadioChange {
  26. /** The MatRadioButton that emits the change event. */
  27. source: MatRadioButton;
  28. /** The value of the MatRadioButton. */
  29. value: any;
  30. constructor(
  31. /** The MatRadioButton that emits the change event. */
  32. source: MatRadioButton,
  33. /** The value of the MatRadioButton. */
  34. value: any);
  35. }
  36. /**
  37. * A group of radio buttons. May contain one or more `<mat-radio-button>` elements.
  38. */
  39. export declare class MatRadioGroup implements AfterContentInit, ControlValueAccessor {
  40. private _changeDetector;
  41. /** Selected value for the radio group. */
  42. private _value;
  43. /** The HTML name attribute applied to radio buttons in this group. */
  44. private _name;
  45. /** The currently selected radio button. Should match value. */
  46. private _selected;
  47. /** Whether the `value` has been set to its initial value. */
  48. private _isInitialized;
  49. /** Whether the labels should appear after or before the radio-buttons. Defaults to 'after' */
  50. private _labelPosition;
  51. /** Whether the radio group is disabled. */
  52. private _disabled;
  53. /** Whether the radio group is required. */
  54. private _required;
  55. /** The method to be called in order to update ngModel */
  56. _controlValueAccessorChangeFn: (value: any) => void;
  57. /**
  58. * onTouch function registered via registerOnTouch (ControlValueAccessor).
  59. * @docs-private
  60. */
  61. onTouched: () => any;
  62. /**
  63. * Event emitted when the group value changes.
  64. * Change events are only emitted when the value changes due to user interaction with
  65. * a radio button (the same behavior as `<input type-"radio">`).
  66. */
  67. readonly change: EventEmitter<MatRadioChange>;
  68. /** Child radio buttons. */
  69. _radios: QueryList<MatRadioButton>;
  70. /** Theme color for all of the radio buttons in the group. */
  71. color: ThemePalette;
  72. /** Name of the radio button group. All radio buttons inside this group will use this name. */
  73. name: string;
  74. /** Whether the labels should appear after or before the radio-buttons. Defaults to 'after' */
  75. labelPosition: 'before' | 'after';
  76. /**
  77. * Value for the radio-group. Should equal the value of the selected radio button if there is
  78. * a corresponding radio button with a matching value. If there is not such a corresponding
  79. * radio button, this value persists to be applied in case a new radio button is added with a
  80. * matching value.
  81. */
  82. value: any;
  83. _checkSelectedRadioButton(): void;
  84. /**
  85. * The currently selected radio button. If set to a new radio button, the radio group value
  86. * will be updated to match the new selected button.
  87. */
  88. selected: MatRadioButton | null;
  89. /** Whether the radio group is disabled */
  90. disabled: boolean;
  91. /** Whether the radio group is required */
  92. required: boolean;
  93. constructor(_changeDetector: ChangeDetectorRef);
  94. /**
  95. * Initialize properties once content children are available.
  96. * This allows us to propagate relevant attributes to associated buttons.
  97. */
  98. ngAfterContentInit(): void;
  99. /**
  100. * Mark this group as being "touched" (for ngModel). Meant to be called by the contained
  101. * radio buttons upon their blur.
  102. */
  103. _touch(): void;
  104. private _updateRadioButtonNames;
  105. /** Updates the `selected` radio button from the internal _value state. */
  106. private _updateSelectedRadioFromValue;
  107. /** Dispatch change event with current selection and group value. */
  108. _emitChangeEvent(): void;
  109. _markRadiosForCheck(): void;
  110. /**
  111. * Sets the model value. Implemented as part of ControlValueAccessor.
  112. * @param value
  113. */
  114. writeValue(value: any): void;
  115. /**
  116. * Registers a callback to be triggered when the model value changes.
  117. * Implemented as part of ControlValueAccessor.
  118. * @param fn Callback to be registered.
  119. */
  120. registerOnChange(fn: (value: any) => void): void;
  121. /**
  122. * Registers a callback to be triggered when the control is touched.
  123. * Implemented as part of ControlValueAccessor.
  124. * @param fn Callback to be registered.
  125. */
  126. registerOnTouched(fn: any): void;
  127. /**
  128. * Sets the disabled state of the control. Implemented as a part of ControlValueAccessor.
  129. * @param isDisabled Whether the control should be disabled.
  130. */
  131. setDisabledState(isDisabled: boolean): void;
  132. }
  133. /** @docs-private */
  134. declare class MatRadioButtonBase {
  135. _elementRef: ElementRef;
  136. disabled: boolean;
  137. constructor(_elementRef: ElementRef);
  138. }
  139. declare const _MatRadioButtonMixinBase: CanDisableRippleCtor & HasTabIndexCtor & typeof MatRadioButtonBase;
  140. /**
  141. * A Material design radio-button. Typically placed inside of `<mat-radio-group>` elements.
  142. */
  143. export declare class MatRadioButton extends _MatRadioButtonMixinBase implements OnInit, AfterViewInit, OnDestroy, CanDisableRipple, HasTabIndex {
  144. private _changeDetector;
  145. private _focusMonitor;
  146. private _radioDispatcher;
  147. _animationMode?: string | undefined;
  148. private _providerOverride?;
  149. private _uniqueId;
  150. /** The unique ID for the radio button. */
  151. id: string;
  152. /** Analog to HTML 'name' attribute used to group radios for unique selection. */
  153. name: string;
  154. /** Used to set the 'aria-label' attribute on the underlying input element. */
  155. ariaLabel: string;
  156. /** The 'aria-labelledby' attribute takes precedence as the element's text alternative. */
  157. ariaLabelledby: string;
  158. /** The 'aria-describedby' attribute is read after the element's label and field type. */
  159. ariaDescribedby: string;
  160. /** Whether this radio button is checked. */
  161. checked: boolean;
  162. /** The value of this radio button. */
  163. value: any;
  164. /** Whether the label should appear after or before the radio button. Defaults to 'after' */
  165. labelPosition: 'before' | 'after';
  166. private _labelPosition;
  167. /** Whether the radio button is disabled. */
  168. disabled: boolean;
  169. /** Whether the radio button is required. */
  170. required: boolean;
  171. /** Theme color of the radio button. */
  172. color: ThemePalette;
  173. private _color;
  174. /**
  175. * Event emitted when the checked state of this radio button changes.
  176. * Change events are only emitted when the value changes due to user interaction with
  177. * the radio button (the same behavior as `<input type-"radio">`).
  178. */
  179. readonly change: EventEmitter<MatRadioChange>;
  180. /** The parent radio group. May or may not be present. */
  181. radioGroup: MatRadioGroup;
  182. /** ID of the native input element inside `<mat-radio-button>` */
  183. readonly inputId: string;
  184. /** Whether this radio is checked. */
  185. private _checked;
  186. /** Whether this radio is disabled. */
  187. private _disabled;
  188. /** Whether this radio is required. */
  189. private _required;
  190. /** Value assigned to this radio. */
  191. private _value;
  192. /** Unregister function for _radioDispatcher */
  193. private _removeUniqueSelectionListener;
  194. /** The native `<input type=radio>` element */
  195. _inputElement: ElementRef<HTMLInputElement>;
  196. constructor(radioGroup: MatRadioGroup, elementRef: ElementRef, _changeDetector: ChangeDetectorRef, _focusMonitor: FocusMonitor, _radioDispatcher: UniqueSelectionDispatcher, _animationMode?: string | undefined, _providerOverride?: MatRadioDefaultOptions | undefined);
  197. /** Focuses the radio button. */
  198. focus(options?: FocusOptions): void;
  199. /**
  200. * Marks the radio button as needing checking for change detection.
  201. * This method is exposed because the parent radio group will directly
  202. * update bound properties of the radio button.
  203. */
  204. _markForCheck(): void;
  205. ngOnInit(): void;
  206. ngAfterViewInit(): void;
  207. ngOnDestroy(): void;
  208. /** Dispatch change event with current value. */
  209. private _emitChangeEvent;
  210. _isRippleDisabled(): boolean;
  211. _onInputClick(event: Event): void;
  212. /**
  213. * Triggered when the radio button received a click or the input recognized any change.
  214. * Clicking on a label element, will trigger a change event on the associated input.
  215. */
  216. _onInputChange(event: Event): void;
  217. }
  218. export {};