@angular/material 19.0.0-next.7 → 19.0.0-next.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_index.scss +2 -0
- package/core/_core-theme.scss +11 -3
- package/core/_core.scss +0 -2
- package/core/index.d.ts +14 -0
- package/core/theming/_all-theme.scss +3 -0
- package/core/tokens/_density.scss +1 -0
- package/core/tokens/m2/_index.scss +2 -0
- package/core/tokens/m2/mat/_timepicker.scss +44 -0
- package/core/tokens/m3/_index.scss +2 -0
- package/core/tokens/m3/mat/_timepicker.scss +22 -0
- package/core/typography/_all-typography.scss +2 -0
- package/dialog/index.d.ts +6 -3
- package/fesm2022/autocomplete.mjs +13 -13
- package/fesm2022/badge.mjs +10 -10
- package/fesm2022/bottom-sheet.mjs +10 -10
- package/fesm2022/button-toggle.mjs +13 -11
- package/fesm2022/button-toggle.mjs.map +1 -1
- package/fesm2022/button.mjs +37 -35
- package/fesm2022/button.mjs.map +1 -1
- package/fesm2022/card.mjs +46 -46
- package/fesm2022/checkbox.mjs +17 -15
- package/fesm2022/checkbox.mjs.map +1 -1
- package/fesm2022/chips.mjs +44 -41
- package/fesm2022/chips.mjs.map +1 -1
- package/fesm2022/core.mjs +117 -109
- package/fesm2022/core.mjs.map +1 -1
- package/fesm2022/datepicker.mjs +85 -83
- package/fesm2022/datepicker.mjs.map +1 -1
- package/fesm2022/dialog.mjs +25 -25
- package/fesm2022/dialog.mjs.map +1 -1
- package/fesm2022/divider.mjs +7 -7
- package/fesm2022/expansion.mjs +28 -26
- package/fesm2022/expansion.mjs.map +1 -1
- package/fesm2022/form-field.mjs +34 -34
- package/fesm2022/grid-list.mjs +22 -22
- package/fesm2022/icon/testing.mjs +7 -7
- package/fesm2022/icon.mjs +11 -11
- package/fesm2022/icon.mjs.map +1 -1
- package/fesm2022/input.mjs +7 -7
- package/fesm2022/list.mjs +52 -50
- package/fesm2022/list.mjs.map +1 -1
- package/fesm2022/menu.mjs +21 -20
- package/fesm2022/menu.mjs.map +1 -1
- package/fesm2022/paginator/testing.mjs +2 -2
- package/fesm2022/paginator/testing.mjs.map +1 -1
- package/fesm2022/paginator.mjs +11 -11
- package/fesm2022/paginator.mjs.map +1 -1
- package/fesm2022/progress-bar.mjs +7 -7
- package/fesm2022/progress-spinner.mjs +7 -7
- package/fesm2022/radio.mjs +13 -11
- package/fesm2022/radio.mjs.map +1 -1
- package/fesm2022/select.mjs +10 -10
- package/fesm2022/sidenav.mjs +22 -22
- package/fesm2022/slide-toggle.mjs +17 -15
- package/fesm2022/slide-toggle.mjs.map +1 -1
- package/fesm2022/slider.mjs +19 -17
- package/fesm2022/slider.mjs.map +1 -1
- package/fesm2022/snack-bar.mjs +22 -22
- package/fesm2022/sort.mjs +16 -14
- package/fesm2022/sort.mjs.map +1 -1
- package/fesm2022/stepper.mjs +34 -32
- package/fesm2022/stepper.mjs.map +1 -1
- package/fesm2022/table.mjs +55 -55
- package/fesm2022/tabs.mjs +49 -50
- package/fesm2022/tabs.mjs.map +1 -1
- package/fesm2022/timepicker/testing.mjs +196 -0
- package/fesm2022/timepicker/testing.mjs.map +1 -0
- package/fesm2022/timepicker.mjs +843 -0
- package/fesm2022/timepicker.mjs.map +1 -0
- package/fesm2022/toolbar.mjs +10 -10
- package/fesm2022/tooltip.mjs +10 -10
- package/fesm2022/tree.mjs +25 -25
- package/icon/index.d.ts +1 -1
- package/menu/index.d.ts +0 -1
- package/package.json +10 -2
- package/prebuilt-themes/azure-blue.css +1 -1
- package/prebuilt-themes/cyan-orange.css +1 -1
- package/prebuilt-themes/deeppurple-amber.css +1 -1
- package/prebuilt-themes/indigo-pink.css +1 -1
- package/prebuilt-themes/magenta-violet.css +1 -1
- package/prebuilt-themes/pink-bluegrey.css +1 -1
- package/prebuilt-themes/purple-green.css +1 -1
- package/prebuilt-themes/rose-red.css +1 -1
- package/schematics/ng-add/index.js +1 -1
- package/schematics/ng-add/index.mjs +1 -1
- package/timepicker/_timepicker-theme.scss +111 -0
- package/timepicker/index.d.ts +297 -0
- package/timepicker/testing/index.d.ts +113 -0
|
@@ -0,0 +1,843 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { InjectionToken, inject, ViewContainerRef, Injector, signal, viewChild, viewChildren, input, output, booleanAttribute, effect, ElementRef, afterNextRender, untracked, Component, ChangeDetectionStrategy, ViewEncapsulation, computed, model, Directive, HostAttributeToken, NgModule } from '@angular/core';
|
|
3
|
+
import { trigger, state, style, transition, group, animate } from '@angular/animations';
|
|
4
|
+
import { DateAdapter, MAT_DATE_FORMATS, MatOption, MAT_OPTION_PARENT_COMPONENT } from '@angular/material/core';
|
|
5
|
+
import { Directionality } from '@angular/cdk/bidi';
|
|
6
|
+
import { Overlay } from '@angular/cdk/overlay';
|
|
7
|
+
import { TemplatePortal } from '@angular/cdk/portal';
|
|
8
|
+
import { _getEventTarget } from '@angular/cdk/platform';
|
|
9
|
+
import { TAB, ESCAPE, hasModifierKey, ENTER, DOWN_ARROW, UP_ARROW } from '@angular/cdk/keycodes';
|
|
10
|
+
import { ActiveDescendantKeyManager } from '@angular/cdk/a11y';
|
|
11
|
+
import { Validators, NG_VALUE_ACCESSOR, NG_VALIDATORS } from '@angular/forms';
|
|
12
|
+
import { MAT_FORM_FIELD } from '@angular/material/form-field';
|
|
13
|
+
import { MAT_INPUT_VALUE_ACCESSOR } from '@angular/material/input';
|
|
14
|
+
import { DOCUMENT } from '@angular/common';
|
|
15
|
+
import { MatIconButton } from '@angular/material/button';
|
|
16
|
+
import { CdkScrollableModule } from '@angular/cdk/scrolling';
|
|
17
|
+
|
|
18
|
+
/** Pattern that interval strings have to match. */
|
|
19
|
+
const INTERVAL_PATTERN = /^(\d*\.?\d+)\s*(h|hour|hours|m|min|minute|minutes|s|second|seconds)?$/i;
|
|
20
|
+
/**
|
|
21
|
+
* Injection token that can be used to configure the default options for the timepicker component.
|
|
22
|
+
*/
|
|
23
|
+
const MAT_TIMEPICKER_CONFIG = new InjectionToken('MAT_TIMEPICKER_CONFIG');
|
|
24
|
+
/** Parses an interval value into seconds. */
|
|
25
|
+
function parseInterval(value) {
|
|
26
|
+
let result;
|
|
27
|
+
if (value === null) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
else if (typeof value === 'number') {
|
|
31
|
+
result = value;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
if (value.trim().length === 0) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const parsed = value.match(INTERVAL_PATTERN);
|
|
38
|
+
const amount = parsed ? parseFloat(parsed[1]) : null;
|
|
39
|
+
const unit = parsed?.[2]?.toLowerCase() || null;
|
|
40
|
+
if (!parsed || amount === null || isNaN(amount)) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
if (unit === 'h' || unit === 'hour' || unit === 'hours') {
|
|
44
|
+
result = amount * 3600;
|
|
45
|
+
}
|
|
46
|
+
else if (unit === 'm' || unit === 'min' || unit === 'minute' || unit === 'minutes') {
|
|
47
|
+
result = amount * 60;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
result = amount;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Generates the options to show in a timepicker.
|
|
57
|
+
* @param adapter Date adapter to be used to generate the options.
|
|
58
|
+
* @param formats Formatting config to use when displaying the options.
|
|
59
|
+
* @param min Time from which to start generating the options.
|
|
60
|
+
* @param max Time at which to stop generating the options.
|
|
61
|
+
* @param interval Amount of seconds between each option.
|
|
62
|
+
*/
|
|
63
|
+
function generateOptions(adapter, formats, min, max, interval) {
|
|
64
|
+
const options = [];
|
|
65
|
+
let current = adapter.compareTime(min, max) < 1 ? min : max;
|
|
66
|
+
while (adapter.sameDate(current, min) &&
|
|
67
|
+
adapter.compareTime(current, max) < 1 &&
|
|
68
|
+
adapter.isValid(current)) {
|
|
69
|
+
options.push({ value: current, label: adapter.format(current, formats.display.timeOptionLabel) });
|
|
70
|
+
current = adapter.addSeconds(current, interval);
|
|
71
|
+
}
|
|
72
|
+
return options;
|
|
73
|
+
}
|
|
74
|
+
/** Checks whether a date adapter is set up correctly for use with the timepicker. */
|
|
75
|
+
function validateAdapter(adapter, formats) {
|
|
76
|
+
function missingAdapterError(provider) {
|
|
77
|
+
return Error(`MatTimepicker: No provider found for ${provider}. You must add one of the following ` +
|
|
78
|
+
`to your app config: provideNativeDateAdapter, provideDateFnsAdapter, ` +
|
|
79
|
+
`provideLuxonDateAdapter, provideMomentDateAdapter, or provide a custom implementation.`);
|
|
80
|
+
}
|
|
81
|
+
if (!adapter) {
|
|
82
|
+
throw missingAdapterError('DateAdapter');
|
|
83
|
+
}
|
|
84
|
+
if (!formats) {
|
|
85
|
+
throw missingAdapterError('MAT_DATE_FORMATS');
|
|
86
|
+
}
|
|
87
|
+
if (formats.display.timeInput === undefined ||
|
|
88
|
+
formats.display.timeOptionLabel === undefined ||
|
|
89
|
+
formats.parse.timeInput === undefined) {
|
|
90
|
+
throw new Error('MatTimepicker: Incomplete `MAT_DATE_FORMATS` has been provided. ' +
|
|
91
|
+
'`MAT_DATE_FORMATS` must provide `display.timeInput`, `display.timeOptionLabel` ' +
|
|
92
|
+
'and `parse.timeInput` formats in order to be compatible with MatTimepicker.');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Counter used to generate unique IDs. */
|
|
97
|
+
let uniqueId = 0;
|
|
98
|
+
/**
|
|
99
|
+
* Renders out a listbox that can be used to select a time of day.
|
|
100
|
+
* Intended to be used together with `MatTimepickerInput`.
|
|
101
|
+
*/
|
|
102
|
+
class MatTimepicker {
|
|
103
|
+
constructor() {
|
|
104
|
+
this._overlay = inject(Overlay);
|
|
105
|
+
this._dir = inject(Directionality, { optional: true });
|
|
106
|
+
this._viewContainerRef = inject(ViewContainerRef);
|
|
107
|
+
this._injector = inject(Injector);
|
|
108
|
+
this._defaultConfig = inject(MAT_TIMEPICKER_CONFIG, { optional: true });
|
|
109
|
+
this._dateAdapter = inject(DateAdapter, { optional: true });
|
|
110
|
+
this._dateFormats = inject(MAT_DATE_FORMATS, { optional: true });
|
|
111
|
+
this._isOpen = signal(false);
|
|
112
|
+
this._activeDescendant = signal(null);
|
|
113
|
+
this._overlayRef = null;
|
|
114
|
+
this._portal = null;
|
|
115
|
+
this._optionsCacheKey = null;
|
|
116
|
+
this._onOpenRender = null;
|
|
117
|
+
this._panelTemplate = viewChild.required('panelTemplate');
|
|
118
|
+
this._timeOptions = [];
|
|
119
|
+
this._options = viewChildren(MatOption);
|
|
120
|
+
this._keyManager = new ActiveDescendantKeyManager(this._options, this._injector)
|
|
121
|
+
.withHomeAndEnd(true)
|
|
122
|
+
.withPageUpDown(true)
|
|
123
|
+
.withVerticalOrientation(true);
|
|
124
|
+
/**
|
|
125
|
+
* Interval between each option in the timepicker. The value can either be an amount of
|
|
126
|
+
* seconds (e.g. 90) or a number with a unit (e.g. 45m). Supported units are `s` for seconds,
|
|
127
|
+
* `m` for minutes or `h` for hours.
|
|
128
|
+
*/
|
|
129
|
+
this.interval = input(parseInterval(this._defaultConfig?.interval || null), { transform: parseInterval });
|
|
130
|
+
/**
|
|
131
|
+
* Array of pre-defined options that the user can select from, as an alternative to using the
|
|
132
|
+
* `interval` input. An error will be thrown if both `options` and `interval` are specified.
|
|
133
|
+
*/
|
|
134
|
+
this.options = input(null);
|
|
135
|
+
/** Whether the timepicker is open. */
|
|
136
|
+
this.isOpen = this._isOpen.asReadonly();
|
|
137
|
+
/** Emits when the user selects a time. */
|
|
138
|
+
this.selected = output();
|
|
139
|
+
/** Emits when the timepicker is opened. */
|
|
140
|
+
this.opened = output();
|
|
141
|
+
/** Emits when the timepicker is closed. */
|
|
142
|
+
this.closed = output();
|
|
143
|
+
/** ID of the active descendant option. */
|
|
144
|
+
this.activeDescendant = this._activeDescendant.asReadonly();
|
|
145
|
+
/** Unique ID of the timepicker's panel */
|
|
146
|
+
this.panelId = `mat-timepicker-panel-${uniqueId++}`;
|
|
147
|
+
/** Whether ripples within the timepicker should be disabled. */
|
|
148
|
+
this.disableRipple = input(this._defaultConfig?.disableRipple ?? false, {
|
|
149
|
+
transform: booleanAttribute,
|
|
150
|
+
});
|
|
151
|
+
/** ARIA label for the timepicker panel. */
|
|
152
|
+
this.ariaLabel = input(null, {
|
|
153
|
+
alias: 'aria-label',
|
|
154
|
+
});
|
|
155
|
+
/** ID of the label element for the timepicker panel. */
|
|
156
|
+
this.ariaLabelledby = input(null, {
|
|
157
|
+
alias: 'aria-labelledby',
|
|
158
|
+
});
|
|
159
|
+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
160
|
+
validateAdapter(this._dateAdapter, this._dateFormats);
|
|
161
|
+
effect(() => {
|
|
162
|
+
const options = this.options();
|
|
163
|
+
const interval = this.interval();
|
|
164
|
+
if (options !== null && interval !== null) {
|
|
165
|
+
throw new Error('Cannot specify both the `options` and `interval` inputs at the same time');
|
|
166
|
+
}
|
|
167
|
+
else if (options?.length === 0) {
|
|
168
|
+
throw new Error('Value of `options` input cannot be an empty array');
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
// Since the panel ID is static, we can set it once without having to maintain a host binding.
|
|
173
|
+
const element = inject(ElementRef);
|
|
174
|
+
element.nativeElement.setAttribute('mat-timepicker-panel-id', this.panelId);
|
|
175
|
+
this._handleLocaleChanges();
|
|
176
|
+
this._handleInputStateChanges();
|
|
177
|
+
this._keyManager.change.subscribe(() => this._activeDescendant.set(this._keyManager.activeItem?.id || null));
|
|
178
|
+
}
|
|
179
|
+
/** Opens the timepicker. */
|
|
180
|
+
open() {
|
|
181
|
+
if (!this._input) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
// Focus should already be on the input, but this call is in case the timepicker is opened
|
|
185
|
+
// programmatically. We need to call this even if the timepicker is already open, because
|
|
186
|
+
// the user might be clicking the toggle.
|
|
187
|
+
this._input.focus();
|
|
188
|
+
if (this._isOpen()) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
this._isOpen.set(true);
|
|
192
|
+
this._generateOptions();
|
|
193
|
+
const overlayRef = this._getOverlayRef();
|
|
194
|
+
overlayRef.updateSize({ width: this._input.getOverlayOrigin().nativeElement.offsetWidth });
|
|
195
|
+
this._portal ??= new TemplatePortal(this._panelTemplate(), this._viewContainerRef);
|
|
196
|
+
overlayRef.attach(this._portal);
|
|
197
|
+
this._onOpenRender?.destroy();
|
|
198
|
+
this._onOpenRender = afterNextRender(() => {
|
|
199
|
+
const options = this._options();
|
|
200
|
+
this._syncSelectedState(this._input.value(), options, options[0]);
|
|
201
|
+
this._onOpenRender = null;
|
|
202
|
+
}, { injector: this._injector });
|
|
203
|
+
this.opened.emit();
|
|
204
|
+
}
|
|
205
|
+
/** Closes the timepicker. */
|
|
206
|
+
close() {
|
|
207
|
+
if (this._isOpen()) {
|
|
208
|
+
this._isOpen.set(false);
|
|
209
|
+
this._overlayRef?.detach();
|
|
210
|
+
this.closed.emit();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/** Registers an input with the timepicker. */
|
|
214
|
+
registerInput(input) {
|
|
215
|
+
if (this._input && input !== this._input && (typeof ngDevMode === 'undefined' || ngDevMode)) {
|
|
216
|
+
throw new Error('MatTimepicker can only be registered with one input at a time');
|
|
217
|
+
}
|
|
218
|
+
this._input = input;
|
|
219
|
+
}
|
|
220
|
+
ngOnDestroy() {
|
|
221
|
+
this._keyManager.destroy();
|
|
222
|
+
this._localeChanges.unsubscribe();
|
|
223
|
+
this._onOpenRender?.destroy();
|
|
224
|
+
this._overlayRef?.dispose();
|
|
225
|
+
}
|
|
226
|
+
/** Selects a specific time value. */
|
|
227
|
+
_selectValue(value) {
|
|
228
|
+
this.close();
|
|
229
|
+
this.selected.emit({ value, source: this });
|
|
230
|
+
this._input.focus();
|
|
231
|
+
}
|
|
232
|
+
/** Gets the value of the `aria-labelledby` attribute. */
|
|
233
|
+
_getAriaLabelledby() {
|
|
234
|
+
if (this.ariaLabel()) {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
return this.ariaLabelledby() || this._input?._getLabelId() || null;
|
|
238
|
+
}
|
|
239
|
+
/** Creates an overlay reference for the timepicker panel. */
|
|
240
|
+
_getOverlayRef() {
|
|
241
|
+
if (this._overlayRef) {
|
|
242
|
+
return this._overlayRef;
|
|
243
|
+
}
|
|
244
|
+
const positionStrategy = this._overlay
|
|
245
|
+
.position()
|
|
246
|
+
.flexibleConnectedTo(this._input.getOverlayOrigin())
|
|
247
|
+
.withFlexibleDimensions(false)
|
|
248
|
+
.withPush(false)
|
|
249
|
+
.withTransformOriginOn('.mat-timepicker-panel')
|
|
250
|
+
.withPositions([
|
|
251
|
+
{
|
|
252
|
+
originX: 'start',
|
|
253
|
+
originY: 'bottom',
|
|
254
|
+
overlayX: 'start',
|
|
255
|
+
overlayY: 'top',
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
originX: 'start',
|
|
259
|
+
originY: 'top',
|
|
260
|
+
overlayX: 'start',
|
|
261
|
+
overlayY: 'bottom',
|
|
262
|
+
panelClass: 'mat-timepicker-above',
|
|
263
|
+
},
|
|
264
|
+
]);
|
|
265
|
+
this._overlayRef = this._overlay.create({
|
|
266
|
+
positionStrategy,
|
|
267
|
+
scrollStrategy: this._overlay.scrollStrategies.reposition(),
|
|
268
|
+
direction: this._dir || 'ltr',
|
|
269
|
+
hasBackdrop: false,
|
|
270
|
+
});
|
|
271
|
+
this._overlayRef.keydownEvents().subscribe(event => {
|
|
272
|
+
this._handleKeydown(event);
|
|
273
|
+
});
|
|
274
|
+
this._overlayRef.outsidePointerEvents().subscribe(event => {
|
|
275
|
+
const target = _getEventTarget(event);
|
|
276
|
+
const origin = this._input.getOverlayOrigin().nativeElement;
|
|
277
|
+
if (target && target !== origin && !origin.contains(target)) {
|
|
278
|
+
this.close();
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
return this._overlayRef;
|
|
282
|
+
}
|
|
283
|
+
/** Generates the list of options from which the user can select.. */
|
|
284
|
+
_generateOptions() {
|
|
285
|
+
// Default the interval to 30 minutes.
|
|
286
|
+
const interval = this.interval() ?? 30 * 60;
|
|
287
|
+
const options = this.options();
|
|
288
|
+
if (options !== null) {
|
|
289
|
+
this._timeOptions = options;
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
const adapter = this._dateAdapter;
|
|
293
|
+
const timeFormat = this._dateFormats.display.timeInput;
|
|
294
|
+
const min = this._input.min() || adapter.setTime(adapter.today(), 0, 0, 0);
|
|
295
|
+
const max = this._input.max() || adapter.setTime(adapter.today(), 23, 59, 0);
|
|
296
|
+
const cacheKey = interval + '/' + adapter.format(min, timeFormat) + '/' + adapter.format(max, timeFormat);
|
|
297
|
+
// Don't re-generate the options if the inputs haven't changed.
|
|
298
|
+
if (cacheKey !== this._optionsCacheKey) {
|
|
299
|
+
this._optionsCacheKey = cacheKey;
|
|
300
|
+
this._timeOptions = generateOptions(adapter, this._dateFormats, min, max, interval);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Synchronizes the internal state of the component based on a specific selected date.
|
|
306
|
+
* @param value Currently selected date.
|
|
307
|
+
* @param options Options rendered out in the timepicker.
|
|
308
|
+
* @param fallback Option to set as active if no option is selected.
|
|
309
|
+
*/
|
|
310
|
+
_syncSelectedState(value, options, fallback) {
|
|
311
|
+
let hasSelected = false;
|
|
312
|
+
for (const option of options) {
|
|
313
|
+
if (value && this._dateAdapter.sameTime(option.value, value)) {
|
|
314
|
+
option.select(false);
|
|
315
|
+
scrollOptionIntoView(option, 'center');
|
|
316
|
+
untracked(() => this._keyManager.setActiveItem(option));
|
|
317
|
+
hasSelected = true;
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
option.deselect(false);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
// If no option was selected, we need to reset the key manager since
|
|
324
|
+
// it might be holding onto an option that no longer exists.
|
|
325
|
+
if (!hasSelected) {
|
|
326
|
+
if (fallback) {
|
|
327
|
+
untracked(() => this._keyManager.setActiveItem(fallback));
|
|
328
|
+
scrollOptionIntoView(fallback, 'center');
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
untracked(() => this._keyManager.setActiveItem(-1));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
/** Handles keyboard events while the overlay is open. */
|
|
336
|
+
_handleKeydown(event) {
|
|
337
|
+
const keyCode = event.keyCode;
|
|
338
|
+
if (keyCode === TAB) {
|
|
339
|
+
this.close();
|
|
340
|
+
}
|
|
341
|
+
else if (keyCode === ESCAPE && !hasModifierKey(event)) {
|
|
342
|
+
event.preventDefault();
|
|
343
|
+
this.close();
|
|
344
|
+
}
|
|
345
|
+
else if (keyCode === ENTER) {
|
|
346
|
+
event.preventDefault();
|
|
347
|
+
if (this._keyManager.activeItem) {
|
|
348
|
+
this._selectValue(this._keyManager.activeItem.value);
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
this.close();
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
const previousActive = this._keyManager.activeItem;
|
|
356
|
+
this._keyManager.onKeydown(event);
|
|
357
|
+
const currentActive = this._keyManager.activeItem;
|
|
358
|
+
if (currentActive && currentActive !== previousActive) {
|
|
359
|
+
scrollOptionIntoView(currentActive, 'nearest');
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
/** Sets up the logic that updates the timepicker when the locale changes. */
|
|
364
|
+
_handleLocaleChanges() {
|
|
365
|
+
// Re-generate the options list if the locale changes.
|
|
366
|
+
this._localeChanges = this._dateAdapter.localeChanges.subscribe(() => {
|
|
367
|
+
this._optionsCacheKey = null;
|
|
368
|
+
if (this.isOpen()) {
|
|
369
|
+
this._generateOptions();
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Sets up the logic that updates the timepicker when the state of the connected input changes.
|
|
375
|
+
*/
|
|
376
|
+
_handleInputStateChanges() {
|
|
377
|
+
effect(() => {
|
|
378
|
+
const value = this._input?.value();
|
|
379
|
+
const options = this._options();
|
|
380
|
+
if (this._isOpen()) {
|
|
381
|
+
this._syncSelectedState(value, options, null);
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0-next.8", ngImport: i0, type: MatTimepicker, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
386
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.0.0-next.8", type: MatTimepicker, isStandalone: true, selector: "mat-timepicker", inputs: { interval: { classPropertyName: "interval", publicName: "interval", isSignal: true, isRequired: false, transformFunction: null }, options: { classPropertyName: "options", publicName: "options", isSignal: true, isRequired: false, transformFunction: null }, disableRipple: { classPropertyName: "disableRipple", publicName: "disableRipple", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "aria-label", isSignal: true, isRequired: false, transformFunction: null }, ariaLabelledby: { classPropertyName: "ariaLabelledby", publicName: "aria-labelledby", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { selected: "selected", opened: "opened", closed: "closed" }, providers: [
|
|
387
|
+
{
|
|
388
|
+
provide: MAT_OPTION_PARENT_COMPONENT,
|
|
389
|
+
useExisting: MatTimepicker,
|
|
390
|
+
},
|
|
391
|
+
], viewQueries: [{ propertyName: "_panelTemplate", first: true, predicate: ["panelTemplate"], descendants: true, isSignal: true }, { propertyName: "_options", predicate: MatOption, descendants: true, isSignal: true }], exportAs: ["matTimepicker"], ngImport: i0, template: "<ng-template #panelTemplate>\n <div\n role=\"listbox\"\n class=\"mat-timepicker-panel\"\n [attr.aria-label]=\"ariaLabel() || null\"\n [attr.aria-labelledby]=\"_getAriaLabelledby()\"\n [id]=\"panelId\"\n @panel>\n @for (option of _timeOptions; track option.value) {\n <mat-option\n [value]=\"option.value\"\n (onSelectionChange)=\"_selectValue(option.value)\">{{option.label}}</mat-option>\n }\n </div>\n</ng-template>\n", styles: ["mat-timepicker{display:none}.mat-timepicker-panel{width:100%;max-height:256px;transform-origin:center top;overflow:auto;padding:8px 0;box-sizing:border-box;border-bottom-left-radius:var(--mat-timepicker-container-shape, var(--mat-app-corner-extra-small));border-bottom-right-radius:var(--mat-timepicker-container-shape, var(--mat-app-corner-extra-small));box-shadow:var(--mat-timepicker-container-elevation-shadow, 0px 3px 1px -2px rgba(0, 0, 0, 0.2), 0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 1px 5px 0px rgba(0, 0, 0, 0.12));background-color:var(--mat-timepicker-container-background-color, var(--mat-app-surface-container))}@media(forced-colors: active){.mat-timepicker-panel{outline:solid 1px}}.mat-timepicker-above .mat-timepicker-panel{border-bottom-left-radius:0;border-bottom-right-radius:0;border-top-left-radius:var(--mat-timepicker-container-shape, var(--mat-app-corner-extra-small));border-top-right-radius:var(--mat-timepicker-container-shape, var(--mat-app-corner-extra-small))}.mat-timepicker-input:read-only{cursor:pointer}@media(forced-colors: active){.mat-timepicker-toggle-default-icon{color:CanvasText}}"], dependencies: [{ kind: "component", type: MatOption, selector: "mat-option", inputs: ["value", "id", "disabled"], outputs: ["onSelectionChange"], exportAs: ["matOption"] }], animations: [
|
|
392
|
+
trigger('panel', [
|
|
393
|
+
state('void', style({ opacity: 0, transform: 'scaleY(0.8)' })),
|
|
394
|
+
transition(':enter', [
|
|
395
|
+
group([
|
|
396
|
+
animate('0.03s linear', style({ opacity: 1 })),
|
|
397
|
+
animate('0.12s cubic-bezier(0, 0, 0.2, 1)', style({ transform: 'scaleY(1)' })),
|
|
398
|
+
]),
|
|
399
|
+
]),
|
|
400
|
+
transition(':leave', [animate('0.075s linear', style({ opacity: 0 }))]),
|
|
401
|
+
]),
|
|
402
|
+
], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
|
403
|
+
}
|
|
404
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0-next.8", ngImport: i0, type: MatTimepicker, decorators: [{
|
|
405
|
+
type: Component,
|
|
406
|
+
args: [{ selector: 'mat-timepicker', exportAs: 'matTimepicker', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, standalone: true, imports: [MatOption], providers: [
|
|
407
|
+
{
|
|
408
|
+
provide: MAT_OPTION_PARENT_COMPONENT,
|
|
409
|
+
useExisting: MatTimepicker,
|
|
410
|
+
},
|
|
411
|
+
], animations: [
|
|
412
|
+
trigger('panel', [
|
|
413
|
+
state('void', style({ opacity: 0, transform: 'scaleY(0.8)' })),
|
|
414
|
+
transition(':enter', [
|
|
415
|
+
group([
|
|
416
|
+
animate('0.03s linear', style({ opacity: 1 })),
|
|
417
|
+
animate('0.12s cubic-bezier(0, 0, 0.2, 1)', style({ transform: 'scaleY(1)' })),
|
|
418
|
+
]),
|
|
419
|
+
]),
|
|
420
|
+
transition(':leave', [animate('0.075s linear', style({ opacity: 0 }))]),
|
|
421
|
+
]),
|
|
422
|
+
], template: "<ng-template #panelTemplate>\n <div\n role=\"listbox\"\n class=\"mat-timepicker-panel\"\n [attr.aria-label]=\"ariaLabel() || null\"\n [attr.aria-labelledby]=\"_getAriaLabelledby()\"\n [id]=\"panelId\"\n @panel>\n @for (option of _timeOptions; track option.value) {\n <mat-option\n [value]=\"option.value\"\n (onSelectionChange)=\"_selectValue(option.value)\">{{option.label}}</mat-option>\n }\n </div>\n</ng-template>\n", styles: ["mat-timepicker{display:none}.mat-timepicker-panel{width:100%;max-height:256px;transform-origin:center top;overflow:auto;padding:8px 0;box-sizing:border-box;border-bottom-left-radius:var(--mat-timepicker-container-shape, var(--mat-app-corner-extra-small));border-bottom-right-radius:var(--mat-timepicker-container-shape, var(--mat-app-corner-extra-small));box-shadow:var(--mat-timepicker-container-elevation-shadow, 0px 3px 1px -2px rgba(0, 0, 0, 0.2), 0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 1px 5px 0px rgba(0, 0, 0, 0.12));background-color:var(--mat-timepicker-container-background-color, var(--mat-app-surface-container))}@media(forced-colors: active){.mat-timepicker-panel{outline:solid 1px}}.mat-timepicker-above .mat-timepicker-panel{border-bottom-left-radius:0;border-bottom-right-radius:0;border-top-left-radius:var(--mat-timepicker-container-shape, var(--mat-app-corner-extra-small));border-top-right-radius:var(--mat-timepicker-container-shape, var(--mat-app-corner-extra-small))}.mat-timepicker-input:read-only{cursor:pointer}@media(forced-colors: active){.mat-timepicker-toggle-default-icon{color:CanvasText}}"] }]
|
|
423
|
+
}], ctorParameters: () => [] });
|
|
424
|
+
/**
|
|
425
|
+
* Scrolls an option into view.
|
|
426
|
+
* @param option Option to be scrolled into view.
|
|
427
|
+
* @param position Position to which to align the option relative to the scrollable container.
|
|
428
|
+
*/
|
|
429
|
+
function scrollOptionIntoView(option, position) {
|
|
430
|
+
option._getHostElement().scrollIntoView({ block: position, inline: position });
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Input that can be used to enter time and connect to a `mat-timepicker`.
|
|
435
|
+
*/
|
|
436
|
+
class MatTimepickerInput {
|
|
437
|
+
constructor() {
|
|
438
|
+
this._elementRef = inject(ElementRef);
|
|
439
|
+
this._document = inject(DOCUMENT);
|
|
440
|
+
this._dateAdapter = inject(DateAdapter, { optional: true });
|
|
441
|
+
this._dateFormats = inject(MAT_DATE_FORMATS, { optional: true });
|
|
442
|
+
this._formField = inject(MAT_FORM_FIELD, { optional: true });
|
|
443
|
+
this._accessorDisabled = signal(false);
|
|
444
|
+
this._lastValueValid = false;
|
|
445
|
+
this._lastValidDate = null;
|
|
446
|
+
/** Value of the `aria-activedescendant` attribute. */
|
|
447
|
+
this._ariaActiveDescendant = computed(() => {
|
|
448
|
+
const timepicker = this.timepicker();
|
|
449
|
+
const isOpen = timepicker.isOpen();
|
|
450
|
+
const activeDescendant = timepicker.activeDescendant();
|
|
451
|
+
return isOpen && activeDescendant ? activeDescendant : null;
|
|
452
|
+
});
|
|
453
|
+
/** Value of the `aria-expanded` attribute. */
|
|
454
|
+
this._ariaExpanded = computed(() => this.timepicker().isOpen() + '');
|
|
455
|
+
/** Value of the `aria-controls` attribute. */
|
|
456
|
+
this._ariaControls = computed(() => {
|
|
457
|
+
const timepicker = this.timepicker();
|
|
458
|
+
return timepicker.isOpen() ? timepicker.panelId : null;
|
|
459
|
+
});
|
|
460
|
+
/** Current value of the input. */
|
|
461
|
+
this.value = model(null);
|
|
462
|
+
/** Timepicker that the input is associated with. */
|
|
463
|
+
this.timepicker = input.required({
|
|
464
|
+
alias: 'matTimepicker',
|
|
465
|
+
});
|
|
466
|
+
/**
|
|
467
|
+
* Minimum time that can be selected or typed in. Can be either
|
|
468
|
+
* a date object (only time will be used) or a valid time string.
|
|
469
|
+
*/
|
|
470
|
+
this.min = input(null, {
|
|
471
|
+
alias: 'matTimepickerMin',
|
|
472
|
+
transform: (value) => this._transformDateInput(value),
|
|
473
|
+
});
|
|
474
|
+
/**
|
|
475
|
+
* Maximum time that can be selected or typed in. Can be either
|
|
476
|
+
* a date object (only time will be used) or a valid time string.
|
|
477
|
+
*/
|
|
478
|
+
this.max = input(null, {
|
|
479
|
+
alias: 'matTimepickerMax',
|
|
480
|
+
transform: (value) => this._transformDateInput(value),
|
|
481
|
+
});
|
|
482
|
+
/** Whether the input is disabled. */
|
|
483
|
+
this.disabled = computed(() => this.disabledInput() || this._accessorDisabled());
|
|
484
|
+
/** Whether the input should be disabled through the template. */
|
|
485
|
+
this.disabledInput = input(false, {
|
|
486
|
+
transform: booleanAttribute,
|
|
487
|
+
alias: 'disabled',
|
|
488
|
+
});
|
|
489
|
+
/** Handles clicks on the input or the containing form field. */
|
|
490
|
+
this._handleClick = () => {
|
|
491
|
+
this.timepicker().open();
|
|
492
|
+
};
|
|
493
|
+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
494
|
+
validateAdapter(this._dateAdapter, this._dateFormats);
|
|
495
|
+
}
|
|
496
|
+
this._validator = this._getValidator();
|
|
497
|
+
this._respondToValueChanges();
|
|
498
|
+
this._respondToMinMaxChanges();
|
|
499
|
+
this._registerTimepicker();
|
|
500
|
+
this._localeSubscription = this._dateAdapter.localeChanges.subscribe(() => {
|
|
501
|
+
if (!this._hasFocus()) {
|
|
502
|
+
this._formatValue(this.value());
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
// Bind the click listener manually to the overlay origin, because we want the entire
|
|
506
|
+
// form field to be clickable, if the timepicker is used in `mat-form-field`.
|
|
507
|
+
this.getOverlayOrigin().nativeElement.addEventListener('click', this._handleClick);
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Implemented as a part of `ControlValueAccessor`.
|
|
511
|
+
* @docs-private
|
|
512
|
+
*/
|
|
513
|
+
writeValue(value) {
|
|
514
|
+
this.value.set(this._dateAdapter.getValidDateOrNull(value));
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Implemented as a part of `ControlValueAccessor`.
|
|
518
|
+
* @docs-private
|
|
519
|
+
*/
|
|
520
|
+
registerOnChange(fn) {
|
|
521
|
+
this._onChange = fn;
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Implemented as a part of `ControlValueAccessor`.
|
|
525
|
+
* @docs-private
|
|
526
|
+
*/
|
|
527
|
+
registerOnTouched(fn) {
|
|
528
|
+
this._onTouched = fn;
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Implemented as a part of `ControlValueAccessor`.
|
|
532
|
+
* @docs-private
|
|
533
|
+
*/
|
|
534
|
+
setDisabledState(isDisabled) {
|
|
535
|
+
this._accessorDisabled.set(isDisabled);
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Implemented as a part of `Validator`.
|
|
539
|
+
* @docs-private
|
|
540
|
+
*/
|
|
541
|
+
validate(control) {
|
|
542
|
+
return this._validator(control);
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Implemented as a part of `Validator`.
|
|
546
|
+
* @docs-private
|
|
547
|
+
*/
|
|
548
|
+
registerOnValidatorChange(fn) {
|
|
549
|
+
this._validatorOnChange = fn;
|
|
550
|
+
}
|
|
551
|
+
/** Gets the element to which the timepicker popup should be attached. */
|
|
552
|
+
getOverlayOrigin() {
|
|
553
|
+
return this._formField?.getConnectedOverlayOrigin() || this._elementRef;
|
|
554
|
+
}
|
|
555
|
+
/** Focuses the input. */
|
|
556
|
+
focus() {
|
|
557
|
+
this._elementRef.nativeElement.focus();
|
|
558
|
+
}
|
|
559
|
+
ngOnDestroy() {
|
|
560
|
+
this.getOverlayOrigin().nativeElement.removeEventListener('click', this._handleClick);
|
|
561
|
+
this._timepickerSubscription?.unsubscribe();
|
|
562
|
+
this._localeSubscription.unsubscribe();
|
|
563
|
+
}
|
|
564
|
+
/** Gets the ID of the input's label. */
|
|
565
|
+
_getLabelId() {
|
|
566
|
+
return this._formField?.getLabelId() || null;
|
|
567
|
+
}
|
|
568
|
+
/** Handles the `input` event. */
|
|
569
|
+
_handleInput(value) {
|
|
570
|
+
const currentValue = this.value();
|
|
571
|
+
const date = this._dateAdapter.parseTime(value, this._dateFormats.parse.timeInput);
|
|
572
|
+
const hasChanged = !this._dateAdapter.sameTime(date, currentValue);
|
|
573
|
+
if (!date || hasChanged || !!(value && !currentValue)) {
|
|
574
|
+
// We need to fire the CVA change event for all nulls, otherwise the validators won't run.
|
|
575
|
+
this._assignUserSelection(date, true);
|
|
576
|
+
}
|
|
577
|
+
else {
|
|
578
|
+
// Call the validator even if the value hasn't changed since
|
|
579
|
+
// some fields change depending on what the user has entered.
|
|
580
|
+
this._validatorOnChange?.();
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
/** Handles the `blur` event. */
|
|
584
|
+
_handleBlur() {
|
|
585
|
+
const value = this.value();
|
|
586
|
+
// Only reformat on blur so the value doesn't change while the user is interacting.
|
|
587
|
+
if (value && this._isValid(value)) {
|
|
588
|
+
this._formatValue(value);
|
|
589
|
+
}
|
|
590
|
+
this._onTouched?.();
|
|
591
|
+
}
|
|
592
|
+
/** Handles the `keydown` event. */
|
|
593
|
+
_handleKeydown(event) {
|
|
594
|
+
// All keyboard events while open are handled through the timepicker.
|
|
595
|
+
if (this.timepicker().isOpen()) {
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
if (event.keyCode === ESCAPE && !hasModifierKey(event) && this.value() !== null) {
|
|
599
|
+
event.preventDefault();
|
|
600
|
+
this.value.set(null);
|
|
601
|
+
this._formatValue(null);
|
|
602
|
+
}
|
|
603
|
+
else if ((event.keyCode === DOWN_ARROW || event.keyCode === UP_ARROW) && !this.disabled()) {
|
|
604
|
+
event.preventDefault();
|
|
605
|
+
this.timepicker().open();
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
/** Sets up the code that watches for changes in the value and adjusts the input. */
|
|
609
|
+
_respondToValueChanges() {
|
|
610
|
+
effect(() => {
|
|
611
|
+
const value = this._dateAdapter.deserialize(this.value());
|
|
612
|
+
const wasValid = this._lastValueValid;
|
|
613
|
+
this._lastValueValid = this._isValid(value);
|
|
614
|
+
// Reformat the value if it changes while the user isn't interacting.
|
|
615
|
+
if (!this._hasFocus()) {
|
|
616
|
+
this._formatValue(value);
|
|
617
|
+
}
|
|
618
|
+
if (value && this._lastValueValid) {
|
|
619
|
+
this._lastValidDate = value;
|
|
620
|
+
}
|
|
621
|
+
// Trigger the validator if the state changed.
|
|
622
|
+
if (wasValid !== this._lastValueValid) {
|
|
623
|
+
this._validatorOnChange?.();
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
/** Sets up the logic that registers the input with the timepicker. */
|
|
628
|
+
_registerTimepicker() {
|
|
629
|
+
effect(() => {
|
|
630
|
+
const timepicker = this.timepicker();
|
|
631
|
+
timepicker.registerInput(this);
|
|
632
|
+
timepicker.closed.subscribe(() => this._onTouched?.());
|
|
633
|
+
timepicker.selected.subscribe(({ value }) => {
|
|
634
|
+
if (!this._dateAdapter.sameTime(value, this.value())) {
|
|
635
|
+
this._assignUserSelection(value, true);
|
|
636
|
+
this._formatValue(value);
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
/** Sets up the logic that adjusts the input if the min/max changes. */
|
|
642
|
+
_respondToMinMaxChanges() {
|
|
643
|
+
effect(() => {
|
|
644
|
+
// Read the min/max so the effect knows when to fire.
|
|
645
|
+
this.min();
|
|
646
|
+
this.max();
|
|
647
|
+
this._validatorOnChange?.();
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Assigns a value set by the user to the input's model.
|
|
652
|
+
* @param selection Time selected by the user that should be assigned.
|
|
653
|
+
* @param propagateToAccessor Whether the value should be propagated to the ControlValueAccessor.
|
|
654
|
+
*/
|
|
655
|
+
_assignUserSelection(selection, propagateToAccessor) {
|
|
656
|
+
if (selection == null || !this._isValid(selection)) {
|
|
657
|
+
this.value.set(selection);
|
|
658
|
+
}
|
|
659
|
+
else {
|
|
660
|
+
// If a datepicker and timepicker are writing to the same object and the user enters an
|
|
661
|
+
// invalid time into the timepicker, we may end up clearing their selection from the
|
|
662
|
+
// datepicker. If the user enters a valid time afterwards, the datepicker's selection will
|
|
663
|
+
// have been lost. This logic restores the previously-valid date and sets its time to
|
|
664
|
+
// the newly-selected time.
|
|
665
|
+
const adapter = this._dateAdapter;
|
|
666
|
+
const target = adapter.getValidDateOrNull(this._lastValidDate || this.value());
|
|
667
|
+
const hours = adapter.getHours(selection);
|
|
668
|
+
const minutes = adapter.getMinutes(selection);
|
|
669
|
+
const seconds = adapter.getSeconds(selection);
|
|
670
|
+
this.value.set(target ? adapter.setTime(target, hours, minutes, seconds) : selection);
|
|
671
|
+
}
|
|
672
|
+
if (propagateToAccessor) {
|
|
673
|
+
this._onChange?.(this.value());
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
/** Formats the current value and assigns it to the input. */
|
|
677
|
+
_formatValue(value) {
|
|
678
|
+
value = this._dateAdapter.getValidDateOrNull(value);
|
|
679
|
+
this._elementRef.nativeElement.value =
|
|
680
|
+
value == null ? '' : this._dateAdapter.format(value, this._dateFormats.display.timeInput);
|
|
681
|
+
}
|
|
682
|
+
/** Checks whether a value is valid. */
|
|
683
|
+
_isValid(value) {
|
|
684
|
+
return !value || this._dateAdapter.isValid(value);
|
|
685
|
+
}
|
|
686
|
+
/** Transforms an arbitrary value into a value that can be assigned to a date-based input. */
|
|
687
|
+
_transformDateInput(value) {
|
|
688
|
+
const date = typeof value === 'string'
|
|
689
|
+
? this._dateAdapter.parseTime(value, this._dateFormats.parse.timeInput)
|
|
690
|
+
: this._dateAdapter.deserialize(value);
|
|
691
|
+
return date && this._dateAdapter.isValid(date) ? date : null;
|
|
692
|
+
}
|
|
693
|
+
/** Whether the input is currently focused. */
|
|
694
|
+
_hasFocus() {
|
|
695
|
+
return this._document.activeElement === this._elementRef.nativeElement;
|
|
696
|
+
}
|
|
697
|
+
/** Gets a function that can be used to validate the input. */
|
|
698
|
+
_getValidator() {
|
|
699
|
+
return Validators.compose([
|
|
700
|
+
() => this._lastValueValid
|
|
701
|
+
? null
|
|
702
|
+
: { 'matTimepickerParse': { 'text': this._elementRef.nativeElement.value } },
|
|
703
|
+
control => {
|
|
704
|
+
const controlValue = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(control.value));
|
|
705
|
+
const min = this.min();
|
|
706
|
+
return !min || !controlValue || this._dateAdapter.compareTime(min, controlValue) <= 0
|
|
707
|
+
? null
|
|
708
|
+
: { 'matTimepickerMin': { 'min': min, 'actual': controlValue } };
|
|
709
|
+
},
|
|
710
|
+
control => {
|
|
711
|
+
const controlValue = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(control.value));
|
|
712
|
+
const max = this.max();
|
|
713
|
+
return !max || !controlValue || this._dateAdapter.compareTime(max, controlValue) >= 0
|
|
714
|
+
? null
|
|
715
|
+
: { 'matTimepickerMax': { 'max': max, 'actual': controlValue } };
|
|
716
|
+
},
|
|
717
|
+
]);
|
|
718
|
+
}
|
|
719
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0-next.8", ngImport: i0, type: MatTimepickerInput, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
720
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.0.0-next.8", type: MatTimepickerInput, isStandalone: true, selector: "input[matTimepicker]", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, timepicker: { classPropertyName: "timepicker", publicName: "matTimepicker", isSignal: true, isRequired: true, transformFunction: null }, min: { classPropertyName: "min", publicName: "matTimepickerMin", isSignal: true, isRequired: false, transformFunction: null }, max: { classPropertyName: "max", publicName: "matTimepickerMax", isSignal: true, isRequired: false, transformFunction: null }, disabledInput: { classPropertyName: "disabledInput", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { value: "valueChange" }, host: { attributes: { "role": "combobox", "type": "text", "aria-haspopup": "listbox" }, listeners: { "blur": "_handleBlur()", "input": "_handleInput($event.target.value)", "keydown": "_handleKeydown($event)" }, properties: { "attr.aria-activedescendant": "_ariaActiveDescendant()", "attr.aria-expanded": "_ariaExpanded()", "attr.aria-controls": "_ariaControls()", "attr.mat-timepicker-id": "timepicker()?.panelId", "disabled": "disabled()" }, classAttribute: "mat-timepicker-input" }, providers: [
|
|
721
|
+
{
|
|
722
|
+
provide: NG_VALUE_ACCESSOR,
|
|
723
|
+
useExisting: MatTimepickerInput,
|
|
724
|
+
multi: true,
|
|
725
|
+
},
|
|
726
|
+
{
|
|
727
|
+
provide: NG_VALIDATORS,
|
|
728
|
+
useExisting: MatTimepickerInput,
|
|
729
|
+
multi: true,
|
|
730
|
+
},
|
|
731
|
+
{
|
|
732
|
+
provide: MAT_INPUT_VALUE_ACCESSOR,
|
|
733
|
+
useExisting: MatTimepickerInput,
|
|
734
|
+
},
|
|
735
|
+
], exportAs: ["matTimepickerInput"], ngImport: i0 }); }
|
|
736
|
+
}
|
|
737
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0-next.8", ngImport: i0, type: MatTimepickerInput, decorators: [{
|
|
738
|
+
type: Directive,
|
|
739
|
+
args: [{
|
|
740
|
+
standalone: true,
|
|
741
|
+
selector: 'input[matTimepicker]',
|
|
742
|
+
exportAs: 'matTimepickerInput',
|
|
743
|
+
host: {
|
|
744
|
+
'class': 'mat-timepicker-input',
|
|
745
|
+
'role': 'combobox',
|
|
746
|
+
'type': 'text',
|
|
747
|
+
'aria-haspopup': 'listbox',
|
|
748
|
+
'[attr.aria-activedescendant]': '_ariaActiveDescendant()',
|
|
749
|
+
'[attr.aria-expanded]': '_ariaExpanded()',
|
|
750
|
+
'[attr.aria-controls]': '_ariaControls()',
|
|
751
|
+
'[attr.mat-timepicker-id]': 'timepicker()?.panelId',
|
|
752
|
+
'[disabled]': 'disabled()',
|
|
753
|
+
'(blur)': '_handleBlur()',
|
|
754
|
+
'(input)': '_handleInput($event.target.value)',
|
|
755
|
+
'(keydown)': '_handleKeydown($event)',
|
|
756
|
+
},
|
|
757
|
+
providers: [
|
|
758
|
+
{
|
|
759
|
+
provide: NG_VALUE_ACCESSOR,
|
|
760
|
+
useExisting: MatTimepickerInput,
|
|
761
|
+
multi: true,
|
|
762
|
+
},
|
|
763
|
+
{
|
|
764
|
+
provide: NG_VALIDATORS,
|
|
765
|
+
useExisting: MatTimepickerInput,
|
|
766
|
+
multi: true,
|
|
767
|
+
},
|
|
768
|
+
{
|
|
769
|
+
provide: MAT_INPUT_VALUE_ACCESSOR,
|
|
770
|
+
useExisting: MatTimepickerInput,
|
|
771
|
+
},
|
|
772
|
+
],
|
|
773
|
+
}]
|
|
774
|
+
}], ctorParameters: () => [] });
|
|
775
|
+
|
|
776
|
+
/** Button that can be used to open a `mat-timepicker`. */
|
|
777
|
+
class MatTimepickerToggle {
|
|
778
|
+
constructor() {
|
|
779
|
+
this._defaultConfig = inject(MAT_TIMEPICKER_CONFIG, { optional: true });
|
|
780
|
+
this._defaultTabIndex = (() => {
|
|
781
|
+
const value = inject(new HostAttributeToken('tabindex'), { optional: true });
|
|
782
|
+
const parsed = Number(value);
|
|
783
|
+
return isNaN(parsed) ? null : parsed;
|
|
784
|
+
})();
|
|
785
|
+
/** Timepicker instance that the button will toggle. */
|
|
786
|
+
this.timepicker = input.required({
|
|
787
|
+
alias: 'for',
|
|
788
|
+
});
|
|
789
|
+
/** Screen-reader label for the button. */
|
|
790
|
+
this.ariaLabel = input(undefined, {
|
|
791
|
+
alias: 'aria-label',
|
|
792
|
+
});
|
|
793
|
+
/** Whether the toggle button is disabled. */
|
|
794
|
+
this.disabled = input(false, {
|
|
795
|
+
transform: booleanAttribute,
|
|
796
|
+
alias: 'disabled',
|
|
797
|
+
});
|
|
798
|
+
/** Tabindex for the toggle. */
|
|
799
|
+
this.tabIndex = input(this._defaultTabIndex);
|
|
800
|
+
/** Whether ripples on the toggle should be disabled. */
|
|
801
|
+
this.disableRipple = input(this._defaultConfig?.disableRipple ?? false, { transform: booleanAttribute });
|
|
802
|
+
}
|
|
803
|
+
/** Opens the connected timepicker. */
|
|
804
|
+
_open(event) {
|
|
805
|
+
if (this.timepicker() && !this.disabled()) {
|
|
806
|
+
this.timepicker().open();
|
|
807
|
+
event.stopPropagation();
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0-next.8", ngImport: i0, type: MatTimepickerToggle, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
811
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "19.0.0-next.8", type: MatTimepickerToggle, isStandalone: true, selector: "mat-timepicker-toggle", inputs: { timepicker: { classPropertyName: "timepicker", publicName: "for", isSignal: true, isRequired: true, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "aria-label", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, tabIndex: { classPropertyName: "tabIndex", publicName: "tabIndex", isSignal: true, isRequired: false, transformFunction: null }, disableRipple: { classPropertyName: "disableRipple", publicName: "disableRipple", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "click": "_open($event)" }, properties: { "attr.tabindex": "null" }, classAttribute: "mat-timepicker-toggle" }, exportAs: ["matTimepickerToggle"], ngImport: i0, template: "<button\n mat-icon-button\n type=\"button\"\n aria-haspopup=\"listbox\"\n [attr.aria-label]=\"ariaLabel()\"\n [attr.aria-expanded]=\"timepicker().isOpen()\"\n [attr.tabindex]=\"disabled() ? -1 : tabIndex()\"\n [disabled]=\"disabled()\"\n [disableRipple]=\"disableRipple()\">\n\n <ng-content select=\"[matTimepickerToggleIcon]\">\n <svg\n class=\"mat-timepicker-toggle-default-icon\"\n height=\"24px\"\n width=\"24px\"\n viewBox=\"0 -960 960 960\"\n fill=\"currentColor\"\n focusable=\"false\"\n aria-hidden=\"true\">\n <path d=\"m612-292 56-56-148-148v-184h-80v216l172 172ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-400Zm0 320q133 0 226.5-93.5T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 133 93.5 226.5T480-160Z\"/>\n </svg>\n </ng-content>\n</button>\n", dependencies: [{ kind: "component", type: MatIconButton, selector: "button[mat-icon-button]", exportAs: ["matButton"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
|
812
|
+
}
|
|
813
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0-next.8", ngImport: i0, type: MatTimepickerToggle, decorators: [{
|
|
814
|
+
type: Component,
|
|
815
|
+
args: [{ selector: 'mat-timepicker-toggle', host: {
|
|
816
|
+
'class': 'mat-timepicker-toggle',
|
|
817
|
+
'[attr.tabindex]': 'null',
|
|
818
|
+
// Bind the `click` on the host, rather than the inner `button`, so that we can call
|
|
819
|
+
// `stopPropagation` on it without affecting the user's `click` handlers. We need to stop
|
|
820
|
+
// it so that the input doesn't get focused automatically by the form field (See #21836).
|
|
821
|
+
'(click)': '_open($event)',
|
|
822
|
+
}, exportAs: 'matTimepickerToggle', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, standalone: true, imports: [MatIconButton], template: "<button\n mat-icon-button\n type=\"button\"\n aria-haspopup=\"listbox\"\n [attr.aria-label]=\"ariaLabel()\"\n [attr.aria-expanded]=\"timepicker().isOpen()\"\n [attr.tabindex]=\"disabled() ? -1 : tabIndex()\"\n [disabled]=\"disabled()\"\n [disableRipple]=\"disableRipple()\">\n\n <ng-content select=\"[matTimepickerToggleIcon]\">\n <svg\n class=\"mat-timepicker-toggle-default-icon\"\n height=\"24px\"\n width=\"24px\"\n viewBox=\"0 -960 960 960\"\n fill=\"currentColor\"\n focusable=\"false\"\n aria-hidden=\"true\">\n <path d=\"m612-292 56-56-148-148v-184h-80v216l172 172ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-400Zm0 320q133 0 226.5-93.5T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 133 93.5 226.5T480-160Z\"/>\n </svg>\n </ng-content>\n</button>\n" }]
|
|
823
|
+
}] });
|
|
824
|
+
|
|
825
|
+
class MatTimepickerModule {
|
|
826
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0-next.8", ngImport: i0, type: MatTimepickerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
827
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.0.0-next.8", ngImport: i0, type: MatTimepickerModule, imports: [MatTimepicker, MatTimepickerInput, MatTimepickerToggle], exports: [CdkScrollableModule, MatTimepicker, MatTimepickerInput, MatTimepickerToggle] }); }
|
|
828
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.0.0-next.8", ngImport: i0, type: MatTimepickerModule, imports: [MatTimepicker, MatTimepickerToggle, CdkScrollableModule] }); }
|
|
829
|
+
}
|
|
830
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0-next.8", ngImport: i0, type: MatTimepickerModule, decorators: [{
|
|
831
|
+
type: NgModule,
|
|
832
|
+
args: [{
|
|
833
|
+
imports: [MatTimepicker, MatTimepickerInput, MatTimepickerToggle],
|
|
834
|
+
exports: [CdkScrollableModule, MatTimepicker, MatTimepickerInput, MatTimepickerToggle],
|
|
835
|
+
}]
|
|
836
|
+
}] });
|
|
837
|
+
|
|
838
|
+
/**
|
|
839
|
+
* Generated bundle index. Do not edit.
|
|
840
|
+
*/
|
|
841
|
+
|
|
842
|
+
export { MAT_TIMEPICKER_CONFIG, MatTimepicker, MatTimepickerInput, MatTimepickerModule, MatTimepickerToggle };
|
|
843
|
+
//# sourceMappingURL=timepicker.mjs.map
|