@tailng-ui/primitives 0.42.0 → 0.44.0
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/package.json +2 -2
- package/src/lib/form/_shared/select/tng-select.overlay.shared.d.ts +1 -0
- package/src/lib/form/_shared/select/tng-select.overlay.shared.d.ts.map +1 -1
- package/src/lib/form/_shared/select/tng-select.overlay.shared.js +8 -1
- package/src/lib/form/_shared/select/tng-select.overlay.shared.js.map +1 -1
- package/src/lib/form/autocomplete/tng-autocomplete.d.ts +2 -2
- package/src/lib/form/autocomplete/tng-autocomplete.d.ts.map +1 -1
- package/src/lib/form/autocomplete/tng-autocomplete.js.map +1 -1
- package/src/lib/form/autocomplete/tng-autocomplete.listbox.d.ts.map +1 -1
- package/src/lib/form/autocomplete/tng-autocomplete.listbox.js +5 -3
- package/src/lib/form/autocomplete/tng-autocomplete.listbox.js.map +1 -1
- package/src/lib/form/autocomplete/tng-autocomplete.overlay.d.ts +1 -0
- package/src/lib/form/autocomplete/tng-autocomplete.overlay.d.ts.map +1 -1
- package/src/lib/form/autocomplete/tng-autocomplete.overlay.js +25 -5
- package/src/lib/form/autocomplete/tng-autocomplete.overlay.js.map +1 -1
- package/src/lib/form/datepicker/tng-datepicker.overlay.d.ts +2 -1
- package/src/lib/form/datepicker/tng-datepicker.overlay.d.ts.map +1 -1
- package/src/lib/form/datepicker/tng-datepicker.overlay.js +13 -5
- package/src/lib/form/datepicker/tng-datepicker.overlay.js.map +1 -1
- package/src/lib/form/index.d.ts +0 -1
- package/src/lib/form/index.d.ts.map +1 -1
- package/src/lib/form/index.js +0 -1
- package/src/lib/form/index.js.map +1 -1
- package/src/lib/form/multi-autocomplete/tng-multi-autocomplete.overlay.d.ts +1 -0
- package/src/lib/form/multi-autocomplete/tng-multi-autocomplete.overlay.d.ts.map +1 -1
- package/src/lib/form/multi-autocomplete/tng-multi-autocomplete.overlay.js +8 -1
- package/src/lib/form/multi-autocomplete/tng-multi-autocomplete.overlay.js.map +1 -1
- package/src/lib/layout/index.d.ts +1 -2
- package/src/lib/layout/index.d.ts.map +1 -1
- package/src/lib/layout/index.js +1 -2
- package/src/lib/layout/index.js.map +1 -1
- package/src/lib/layout/stepper/__tests__/tng-stepper.test-harness.d.ts +44 -0
- package/src/lib/layout/stepper/__tests__/tng-stepper.test-harness.d.ts.map +1 -0
- package/src/lib/layout/stepper/__tests__/tng-stepper.test-harness.js +149 -0
- package/src/lib/layout/stepper/__tests__/tng-stepper.test-harness.js.map +1 -0
- package/src/lib/layout/stepper/index.d.ts +2 -0
- package/src/lib/layout/stepper/index.d.ts.map +1 -0
- package/src/lib/layout/stepper/index.js +2 -0
- package/src/lib/layout/stepper/index.js.map +1 -0
- package/src/lib/layout/stepper/tng-stepper.d.ts +198 -2
- package/src/lib/layout/stepper/tng-stepper.d.ts.map +1 -1
- package/src/lib/layout/stepper/tng-stepper.js +898 -2
- package/src/lib/layout/stepper/tng-stepper.js.map +1 -1
- package/src/lib/navigation/index.d.ts +0 -3
- package/src/lib/navigation/index.d.ts.map +1 -1
- package/src/lib/navigation/index.js +0 -3
- package/src/lib/navigation/index.js.map +1 -1
- package/src/lib/form/multiselect/tng-multiselect.d.ts +0 -7
- package/src/lib/form/multiselect/tng-multiselect.d.ts.map +0 -1
- package/src/lib/form/multiselect/tng-multiselect.js +0 -18
- package/src/lib/form/multiselect/tng-multiselect.js.map +0 -1
- package/src/lib/layout/bottom-sheet/tng-bottom-sheet.d.ts +0 -7
- package/src/lib/layout/bottom-sheet/tng-bottom-sheet.d.ts.map +0 -1
- package/src/lib/layout/bottom-sheet/tng-bottom-sheet.js +0 -18
- package/src/lib/layout/bottom-sheet/tng-bottom-sheet.js.map +0 -1
- package/src/lib/navigation/dropdown-menu/tng-dropdown-menu.d.ts +0 -7
- package/src/lib/navigation/dropdown-menu/tng-dropdown-menu.d.ts.map +0 -1
- package/src/lib/navigation/dropdown-menu/tng-dropdown-menu.js +0 -18
- package/src/lib/navigation/dropdown-menu/tng-dropdown-menu.js.map +0 -1
- package/src/lib/navigation/navigation-menu/tng-navigation-menu.d.ts +0 -7
- package/src/lib/navigation/navigation-menu/tng-navigation-menu.d.ts.map +0 -1
- package/src/lib/navigation/navigation-menu/tng-navigation-menu.js +0 -18
- package/src/lib/navigation/navigation-menu/tng-navigation-menu.js.map +0 -1
- package/src/lib/navigation/toolbar/tng-toolbar.d.ts +0 -7
- package/src/lib/navigation/toolbar/tng-toolbar.d.ts.map +0 -1
- package/src/lib/navigation/toolbar/tng-toolbar.js +0 -18
- package/src/lib/navigation/toolbar/tng-toolbar.js.map +0 -1
|
@@ -1,9 +1,573 @@
|
|
|
1
|
-
import { Directive, HostBinding } from '@angular/core';
|
|
1
|
+
import { Directive, ElementRef, HostBinding, HostListener, inject, input, isDevMode, output, } from '@angular/core';
|
|
2
|
+
import { createTngIdFactory } from '@tailng-ui/cdk';
|
|
2
3
|
import * as i0 from "@angular/core";
|
|
4
|
+
const createStepperTriggerId = createTngIdFactory('tng-stepper-trigger');
|
|
5
|
+
const createStepperPanelId = createTngIdFactory('tng-stepper-panel');
|
|
6
|
+
let nextStepperItemRegistrationOrder = 0;
|
|
7
|
+
function normalizeBooleanInput(value) {
|
|
8
|
+
if (typeof value === 'boolean') {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
if (typeof value === 'string') {
|
|
12
|
+
const normalized = value.trim().toLowerCase();
|
|
13
|
+
if (normalized === '' || normalized === 'true') {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
if (normalized === 'false') {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
function normalizeOrientationInput(value) {
|
|
23
|
+
return value === 'vertical' ? 'vertical' : 'horizontal';
|
|
24
|
+
}
|
|
25
|
+
function normalizeOptionalValueInput(value) {
|
|
26
|
+
if (value === undefined) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
if (value === null) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
if (typeof value === 'number' || typeof value === 'string') {
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
function normalizeValueInput(value) {
|
|
38
|
+
if (typeof value === 'number' || typeof value === 'string') {
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
return String(value);
|
|
42
|
+
}
|
|
43
|
+
function normalizeOptionalStringInput(value) {
|
|
44
|
+
if (value === undefined) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
if (value === null) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
if (typeof value === 'string') {
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') {
|
|
54
|
+
return String(value);
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
function compareStepperItemsByDomPosition(a, b) {
|
|
59
|
+
const aElement = a.getHostElement();
|
|
60
|
+
const bElement = b.getHostElement();
|
|
61
|
+
if (aElement === bElement) {
|
|
62
|
+
return a.getRegistrationOrder() - b.getRegistrationOrder();
|
|
63
|
+
}
|
|
64
|
+
const relativePosition = aElement.compareDocumentPosition(bElement);
|
|
65
|
+
if (relativePosition & Node.DOCUMENT_POSITION_FOLLOWING) {
|
|
66
|
+
return -1;
|
|
67
|
+
}
|
|
68
|
+
if (relativePosition & Node.DOCUMENT_POSITION_PRECEDING) {
|
|
69
|
+
return 1;
|
|
70
|
+
}
|
|
71
|
+
return a.getRegistrationOrder() - b.getRegistrationOrder();
|
|
72
|
+
}
|
|
73
|
+
function valuesEqual(a, b) {
|
|
74
|
+
return a === b;
|
|
75
|
+
}
|
|
3
76
|
export class TngStepper {
|
|
77
|
+
hostRef = inject(ElementRef);
|
|
78
|
+
items = new Set();
|
|
79
|
+
uncontrolledValue = null;
|
|
80
|
+
focusedValue = null;
|
|
81
|
+
lastSelectedValue = null;
|
|
82
|
+
lastSelectedIndex = -1;
|
|
83
|
+
initialized = false;
|
|
84
|
+
hasUserSelection = false;
|
|
85
|
+
hasExplicitFocus = false;
|
|
86
|
+
duplicateWarnings = new Set();
|
|
87
|
+
value = input(undefined, { ...(ngDevMode ? { debugName: "value" } : {}), transform: normalizeOptionalValueInput });
|
|
88
|
+
defaultValue = input(undefined, { ...(ngDevMode ? { debugName: "defaultValue" } : {}), transform: normalizeOptionalValueInput });
|
|
89
|
+
orientation = input('horizontal', { ...(ngDevMode ? { debugName: "orientation" } : {}), transform: normalizeOrientationInput });
|
|
90
|
+
linear = input(false, { ...(ngDevMode ? { debugName: "linear" } : {}), transform: normalizeBooleanInput });
|
|
91
|
+
loopFocus = input(true, { ...(ngDevMode ? { debugName: "loopFocus" } : {}), transform: normalizeBooleanInput });
|
|
92
|
+
ariaLabel = input(undefined, { ...(ngDevMode ? { debugName: "ariaLabel" } : {}), transform: normalizeOptionalStringInput });
|
|
93
|
+
ariaLabelledby = input(undefined, { ...(ngDevMode ? { debugName: "ariaLabelledby" } : {}), transform: normalizeOptionalStringInput });
|
|
94
|
+
valueChange = output();
|
|
95
|
+
stepChange = output();
|
|
96
|
+
get ariaLabelAttr() {
|
|
97
|
+
return this.ariaLabel() ?? null;
|
|
98
|
+
}
|
|
99
|
+
get ariaLabelledbyAttr() {
|
|
100
|
+
return this.ariaLabelledby() ?? null;
|
|
101
|
+
}
|
|
102
|
+
get dataLinear() {
|
|
103
|
+
return this.linear() ? '' : null;
|
|
104
|
+
}
|
|
105
|
+
get dataOrientation() {
|
|
106
|
+
return this.orientation();
|
|
107
|
+
}
|
|
4
108
|
dataSlot = 'stepper';
|
|
109
|
+
ngDoCheck() {
|
|
110
|
+
this.syncStateFromRegistry();
|
|
111
|
+
}
|
|
112
|
+
ngOnDestroy() {
|
|
113
|
+
this.items.clear();
|
|
114
|
+
}
|
|
115
|
+
registerItem(item) {
|
|
116
|
+
this.items.add(item);
|
|
117
|
+
this.syncStateFromRegistry();
|
|
118
|
+
}
|
|
119
|
+
unregisterItem(item) {
|
|
120
|
+
const orderedItems = [...this.getOrderedItems()].sort((a, b) => a.getLastKnownIndex() - b.getLastKnownIndex());
|
|
121
|
+
const removedValue = item.getValue();
|
|
122
|
+
const selectedValue = this.getEffectiveValue();
|
|
123
|
+
const removedIndex = valuesEqual(selectedValue, removedValue) ? this.lastSelectedIndex : item.getLastKnownIndex();
|
|
124
|
+
this.items.delete(item);
|
|
125
|
+
if (valuesEqual(selectedValue, removedValue)) {
|
|
126
|
+
this.applyLifecycleSelection(this.resolveNearestEnabledValue(orderedItems, removedIndex));
|
|
127
|
+
}
|
|
128
|
+
if (valuesEqual(this.focusedValue, removedValue)) {
|
|
129
|
+
this.focusedValue = this.resolveNearestEnabledValue(orderedItems, removedIndex);
|
|
130
|
+
this.hasExplicitFocus = false;
|
|
131
|
+
}
|
|
132
|
+
this.syncStateFromRegistry();
|
|
133
|
+
}
|
|
134
|
+
notifyItemMutated(item) {
|
|
135
|
+
if (this.isItemSelected(item) && item.disabled()) {
|
|
136
|
+
this.applyLifecycleSelection(this.resolveNeighborForItem(item));
|
|
137
|
+
}
|
|
138
|
+
if (valuesEqual(this.focusedValue, item.getValue()) && item.disabled()) {
|
|
139
|
+
this.focusedValue = this.resolveNeighborForItem(item);
|
|
140
|
+
this.hasExplicitFocus = false;
|
|
141
|
+
}
|
|
142
|
+
this.syncStateFromRegistry();
|
|
143
|
+
}
|
|
144
|
+
select(value) {
|
|
145
|
+
const item = this.findItemByValue(value);
|
|
146
|
+
if (item === null) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
this.requestActivation(item, 'programmatic');
|
|
150
|
+
}
|
|
151
|
+
focus(value) {
|
|
152
|
+
const item = this.findEnabledItemByValue(value);
|
|
153
|
+
if (item === null) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
this.focusItem(item);
|
|
157
|
+
}
|
|
158
|
+
next() {
|
|
159
|
+
this.moveFocusFromCurrent('next');
|
|
160
|
+
}
|
|
161
|
+
prev() {
|
|
162
|
+
this.moveFocusFromCurrent('prev');
|
|
163
|
+
}
|
|
164
|
+
getItemIndex(item) {
|
|
165
|
+
return this.getOrderedItems().indexOf(item);
|
|
166
|
+
}
|
|
167
|
+
getItemCount() {
|
|
168
|
+
return this.getOrderedItems().length;
|
|
169
|
+
}
|
|
170
|
+
isItemSelected(item) {
|
|
171
|
+
return valuesEqual(this.getEffectiveValue(), item.getValue());
|
|
172
|
+
}
|
|
173
|
+
isItemActivatable(item) {
|
|
174
|
+
if (item.disabled()) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
if (!this.linear()) {
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
if (this.isItemSelected(item) || item.completed()) {
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
const selectedIndex = this.getSelectedIndex();
|
|
184
|
+
const itemIndex = this.getItemIndex(item);
|
|
185
|
+
return selectedIndex >= 0 && itemIndex >= 0 && itemIndex < selectedIndex;
|
|
186
|
+
}
|
|
187
|
+
getItemState(item) {
|
|
188
|
+
if (item.disabled()) {
|
|
189
|
+
return 'disabled';
|
|
190
|
+
}
|
|
191
|
+
if (item.error()) {
|
|
192
|
+
return 'error';
|
|
193
|
+
}
|
|
194
|
+
if (this.isItemSelected(item)) {
|
|
195
|
+
return 'current';
|
|
196
|
+
}
|
|
197
|
+
if (item.completed()) {
|
|
198
|
+
return 'completed';
|
|
199
|
+
}
|
|
200
|
+
return 'upcoming';
|
|
201
|
+
}
|
|
202
|
+
getTriggerTabIndex(item) {
|
|
203
|
+
if (item.disabled()) {
|
|
204
|
+
return '-1';
|
|
205
|
+
}
|
|
206
|
+
const tabStopValue = this.resolveCurrentTabStopValue();
|
|
207
|
+
if (tabStopValue === null) {
|
|
208
|
+
return '-1';
|
|
209
|
+
}
|
|
210
|
+
return valuesEqual(tabStopValue, item.getValue()) ? '0' : '-1';
|
|
211
|
+
}
|
|
212
|
+
onTriggerFocused(item) {
|
|
213
|
+
if (!item.disabled()) {
|
|
214
|
+
this.focusedValue = item.getValue();
|
|
215
|
+
this.hasExplicitFocus = true;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
onTriggerClicked(item, event) {
|
|
219
|
+
if (!this.isItemActivatable(item)) {
|
|
220
|
+
event.preventDefault();
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
this.requestActivation(item, 'pointer');
|
|
224
|
+
}
|
|
225
|
+
onTriggerKeydown(item, event) {
|
|
226
|
+
if (item.disabled() || event.altKey || event.ctrlKey || event.metaKey) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (this.handleFocusKey(item, event)) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (!this.isActivationKey(event.key)) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
event.preventDefault();
|
|
236
|
+
this.requestActivation(item, 'keyboard');
|
|
237
|
+
}
|
|
238
|
+
requestActivation(item, trigger) {
|
|
239
|
+
if (!this.isItemActivatable(item)) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const nextValue = item.getValue();
|
|
243
|
+
const previousValue = this.getEffectiveValue();
|
|
244
|
+
if (valuesEqual(previousValue, nextValue)) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (!this.isControlled()) {
|
|
248
|
+
this.uncontrolledValue = nextValue;
|
|
249
|
+
this.hasUserSelection = true;
|
|
250
|
+
}
|
|
251
|
+
this.focusedValue = nextValue;
|
|
252
|
+
this.valueChange.emit(nextValue);
|
|
253
|
+
this.stepChange.emit({ value: nextValue, previousValue, trigger });
|
|
254
|
+
this.syncStateFromRegistry();
|
|
255
|
+
}
|
|
256
|
+
syncStateFromRegistry() {
|
|
257
|
+
this.warnForDuplicateValues();
|
|
258
|
+
const enabledItems = this.getEnabledItems();
|
|
259
|
+
if (enabledItems.length === 0) {
|
|
260
|
+
this.clearSelectionState();
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (!this.initialized) {
|
|
264
|
+
this.initializeSelection(enabledItems);
|
|
265
|
+
}
|
|
266
|
+
this.restoreRemovedDefaultSelectionIfNeeded();
|
|
267
|
+
this.normalizeSelectionForCurrentItems(enabledItems);
|
|
268
|
+
this.normalizeFocusForCurrentItems(enabledItems);
|
|
269
|
+
this.syncDomAttributes();
|
|
270
|
+
}
|
|
271
|
+
warnForDuplicateValues() {
|
|
272
|
+
if (!isDevMode()) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
const seen = new Set();
|
|
276
|
+
for (const item of this.getOrderedItems()) {
|
|
277
|
+
const value = item.getValue();
|
|
278
|
+
if (!seen.has(value)) {
|
|
279
|
+
seen.add(value);
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
if (this.duplicateWarnings.has(value)) {
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
this.duplicateWarnings.add(value);
|
|
286
|
+
// eslint-disable-next-line no-console
|
|
287
|
+
console.warn(`TngStepper: duplicate step value "${String(value)}" registered.`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
clearSelectionState() {
|
|
291
|
+
this.uncontrolledValue = null;
|
|
292
|
+
this.focusedValue = null;
|
|
293
|
+
this.hasExplicitFocus = false;
|
|
294
|
+
this.initialized = true;
|
|
295
|
+
this.syncDomAttributes();
|
|
296
|
+
}
|
|
297
|
+
initializeSelection(enabledItems) {
|
|
298
|
+
this.initialized = true;
|
|
299
|
+
if (this.isControlled()) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
const defaultValue = this.defaultValue();
|
|
303
|
+
this.uncontrolledValue =
|
|
304
|
+
defaultValue !== undefined && defaultValue !== null && this.findEnabledItemByValue(defaultValue) !== null
|
|
305
|
+
? defaultValue
|
|
306
|
+
: (enabledItems[0]?.getValue() ?? null);
|
|
307
|
+
}
|
|
308
|
+
normalizeSelectionForCurrentItems(enabledItems) {
|
|
309
|
+
const selectedItem = this.findEnabledItemByValue(this.getEffectiveValue());
|
|
310
|
+
if (selectedItem === null) {
|
|
311
|
+
if (!this.isControlled()) {
|
|
312
|
+
this.uncontrolledValue = this.resolveNearestEnabledValueForMissingSelection();
|
|
313
|
+
}
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
this.restoreDefaultSelectionIfNeeded(enabledItems);
|
|
317
|
+
}
|
|
318
|
+
restoreDefaultSelectionIfNeeded(enabledItems) {
|
|
319
|
+
if (this.isControlled() || this.hasUserSelection) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
const defaultValue = this.defaultValue();
|
|
323
|
+
if (defaultValue === undefined || defaultValue === null) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
if (enabledItems.some((item) => valuesEqual(item.getValue(), defaultValue))) {
|
|
327
|
+
this.uncontrolledValue = defaultValue;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
restoreRemovedDefaultSelectionIfNeeded() {
|
|
331
|
+
if (this.isControlled() || this.hasUserSelection) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const defaultValue = this.defaultValue();
|
|
335
|
+
if (defaultValue === undefined ||
|
|
336
|
+
defaultValue === null ||
|
|
337
|
+
!valuesEqual(this.lastSelectedValue, defaultValue) ||
|
|
338
|
+
this.findItemByValue(defaultValue) !== null) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
const orderedItems = [...this.getOrderedItems()].sort((a, b) => a.getLastKnownIndex() - b.getLastKnownIndex());
|
|
342
|
+
this.uncontrolledValue = this.resolveNearestEnabledValue(orderedItems, this.lastSelectedIndex);
|
|
343
|
+
}
|
|
344
|
+
normalizeFocusForCurrentItems(enabledItems) {
|
|
345
|
+
if (this.hasExplicitFocus &&
|
|
346
|
+
this.focusedValue !== null &&
|
|
347
|
+
this.findEnabledItemByValue(this.focusedValue) !== null) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
this.focusedValue = this.getEffectiveValue() ?? enabledItems[0]?.getValue() ?? null;
|
|
351
|
+
}
|
|
352
|
+
syncDomAttributes() {
|
|
353
|
+
const orderedItems = this.getOrderedItems();
|
|
354
|
+
const itemCount = orderedItems.length;
|
|
355
|
+
this.lastSelectedIndex = -1;
|
|
356
|
+
this.lastSelectedValue = null;
|
|
357
|
+
for (const [index, item] of orderedItems.entries()) {
|
|
358
|
+
if (this.isItemSelected(item)) {
|
|
359
|
+
this.lastSelectedIndex = index;
|
|
360
|
+
this.lastSelectedValue = item.getValue();
|
|
361
|
+
}
|
|
362
|
+
item.syncDomAttributes({
|
|
363
|
+
activatable: this.isItemActivatable(item),
|
|
364
|
+
current: this.isItemSelected(item),
|
|
365
|
+
index,
|
|
366
|
+
state: this.getItemState(item),
|
|
367
|
+
tabIndex: this.getTriggerTabIndex(item),
|
|
368
|
+
total: itemCount,
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
applyLifecycleSelection(value) {
|
|
373
|
+
if (!this.isControlled()) {
|
|
374
|
+
this.uncontrolledValue = value;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
handleFocusKey(item, event) {
|
|
378
|
+
const move = this.resolveFocusMove(event.key);
|
|
379
|
+
if (move === null) {
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
if (this.moveFocus(item, move)) {
|
|
383
|
+
event.preventDefault();
|
|
384
|
+
}
|
|
385
|
+
return true;
|
|
386
|
+
}
|
|
387
|
+
isActivationKey(key) {
|
|
388
|
+
return key === 'Enter' || key === ' ' || key === 'Spacebar';
|
|
389
|
+
}
|
|
390
|
+
resolveFocusMove(key) {
|
|
391
|
+
if (key === 'Home') {
|
|
392
|
+
return 'first';
|
|
393
|
+
}
|
|
394
|
+
if (key === 'End') {
|
|
395
|
+
return 'last';
|
|
396
|
+
}
|
|
397
|
+
if (this.orientation() === 'vertical') {
|
|
398
|
+
return this.resolveVerticalFocusMove(key);
|
|
399
|
+
}
|
|
400
|
+
return this.resolveHorizontalFocusMove(key);
|
|
401
|
+
}
|
|
402
|
+
resolveVerticalFocusMove(key) {
|
|
403
|
+
if (key === 'ArrowDown') {
|
|
404
|
+
return 'next';
|
|
405
|
+
}
|
|
406
|
+
if (key === 'ArrowUp') {
|
|
407
|
+
return 'prev';
|
|
408
|
+
}
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
resolveHorizontalFocusMove(key) {
|
|
412
|
+
if (key !== 'ArrowLeft' && key !== 'ArrowRight') {
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
const isRtl = this.resolveDirection() === 'rtl';
|
|
416
|
+
const moveNext = key === (isRtl ? 'ArrowLeft' : 'ArrowRight');
|
|
417
|
+
return moveNext ? 'next' : 'prev';
|
|
418
|
+
}
|
|
419
|
+
moveFocusFromCurrent(move) {
|
|
420
|
+
const current = this.findEnabledItemByValue(this.resolveCurrentTabStopValue()) ?? this.getEnabledItems()[0] ?? null;
|
|
421
|
+
if (current !== null) {
|
|
422
|
+
this.moveFocus(current, move);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
moveFocus(source, move) {
|
|
426
|
+
const enabledItems = this.getEnabledItems();
|
|
427
|
+
if (enabledItems.length === 0) {
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
const currentIndex = enabledItems.indexOf(source);
|
|
431
|
+
if (currentIndex < 0) {
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
const nextIndex = this.resolveFocusTargetIndex(enabledItems.length, currentIndex, move);
|
|
435
|
+
if (nextIndex === null) {
|
|
436
|
+
return false;
|
|
437
|
+
}
|
|
438
|
+
const target = enabledItems[nextIndex] ?? null;
|
|
439
|
+
if (target === null || target === source) {
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
this.focusItem(target);
|
|
443
|
+
return true;
|
|
444
|
+
}
|
|
445
|
+
resolveFocusTargetIndex(itemCount, currentIndex, move) {
|
|
446
|
+
if (move === 'first') {
|
|
447
|
+
return 0;
|
|
448
|
+
}
|
|
449
|
+
if (move === 'last') {
|
|
450
|
+
return itemCount - 1;
|
|
451
|
+
}
|
|
452
|
+
if (move === 'next') {
|
|
453
|
+
return this.resolveRelativeFocusTargetIndex(itemCount, currentIndex, 1);
|
|
454
|
+
}
|
|
455
|
+
return this.resolveRelativeFocusTargetIndex(itemCount, currentIndex, -1);
|
|
456
|
+
}
|
|
457
|
+
resolveRelativeFocusTargetIndex(itemCount, currentIndex, delta) {
|
|
458
|
+
const nextIndex = currentIndex + delta;
|
|
459
|
+
if (nextIndex >= 0 && nextIndex < itemCount) {
|
|
460
|
+
return nextIndex;
|
|
461
|
+
}
|
|
462
|
+
if (!this.loopFocus()) {
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
return delta > 0 ? 0 : itemCount - 1;
|
|
466
|
+
}
|
|
467
|
+
focusItem(item) {
|
|
468
|
+
this.focusedValue = item.getValue();
|
|
469
|
+
this.hasExplicitFocus = true;
|
|
470
|
+
item.focusTrigger();
|
|
471
|
+
}
|
|
472
|
+
getEffectiveValue() {
|
|
473
|
+
if (this.isControlled()) {
|
|
474
|
+
return this.getControlledEffectiveValue();
|
|
475
|
+
}
|
|
476
|
+
return this.getUncontrolledEffectiveValue();
|
|
477
|
+
}
|
|
478
|
+
getControlledEffectiveValue() {
|
|
479
|
+
const controlledValue = this.value();
|
|
480
|
+
if (controlledValue === undefined || controlledValue === null) {
|
|
481
|
+
return null;
|
|
482
|
+
}
|
|
483
|
+
const controlledItem = this.findItemByValue(controlledValue);
|
|
484
|
+
if (controlledItem === null) {
|
|
485
|
+
return this.getEnabledItems()[0]?.getValue() ?? null;
|
|
486
|
+
}
|
|
487
|
+
if (controlledItem.disabled()) {
|
|
488
|
+
return this.resolveNeighborForItem(controlledItem);
|
|
489
|
+
}
|
|
490
|
+
return controlledValue;
|
|
491
|
+
}
|
|
492
|
+
getUncontrolledEffectiveValue() {
|
|
493
|
+
if (!this.hasUserSelection) {
|
|
494
|
+
const defaultValue = this.defaultValue();
|
|
495
|
+
if (defaultValue !== undefined && defaultValue !== null && this.findEnabledItemByValue(defaultValue) !== null) {
|
|
496
|
+
return defaultValue;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
return this.uncontrolledValue;
|
|
500
|
+
}
|
|
501
|
+
isControlled() {
|
|
502
|
+
return this.value() !== undefined;
|
|
503
|
+
}
|
|
504
|
+
getSelectedIndex() {
|
|
505
|
+
const value = this.getEffectiveValue();
|
|
506
|
+
if (value === null) {
|
|
507
|
+
return -1;
|
|
508
|
+
}
|
|
509
|
+
return this.getOrderedItems().findIndex((item) => valuesEqual(item.getValue(), value));
|
|
510
|
+
}
|
|
511
|
+
resolveCurrentTabStopValue() {
|
|
512
|
+
if (this.focusedValue !== null && this.findEnabledItemByValue(this.focusedValue) !== null) {
|
|
513
|
+
return this.focusedValue;
|
|
514
|
+
}
|
|
515
|
+
const selectedValue = this.getEffectiveValue();
|
|
516
|
+
if (selectedValue !== null && this.findEnabledItemByValue(selectedValue) !== null) {
|
|
517
|
+
return selectedValue;
|
|
518
|
+
}
|
|
519
|
+
return this.getEnabledItems()[0]?.getValue() ?? null;
|
|
520
|
+
}
|
|
521
|
+
resolveNeighborForItem(item) {
|
|
522
|
+
const orderedItems = this.getOrderedItems();
|
|
523
|
+
return this.resolveNearestEnabledValue(orderedItems, orderedItems.indexOf(item));
|
|
524
|
+
}
|
|
525
|
+
resolveNearestEnabledValue(orderedItems, index) {
|
|
526
|
+
for (let i = index - 1; i >= 0; i -= 1) {
|
|
527
|
+
const item = orderedItems[i];
|
|
528
|
+
if (item !== undefined && !item.disabled()) {
|
|
529
|
+
return item.getValue();
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
for (let i = index + 1; i < orderedItems.length; i += 1) {
|
|
533
|
+
const item = orderedItems[i];
|
|
534
|
+
if (item !== undefined && !item.disabled()) {
|
|
535
|
+
return item.getValue();
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return null;
|
|
539
|
+
}
|
|
540
|
+
resolveNearestEnabledValueForMissingSelection() {
|
|
541
|
+
const controlledValue = this.getEffectiveValue();
|
|
542
|
+
const orderedItems = this.getOrderedItems();
|
|
543
|
+
const selectedIndex = orderedItems.findIndex((item) => valuesEqual(item.getValue(), controlledValue));
|
|
544
|
+
if (selectedIndex >= 0) {
|
|
545
|
+
return this.resolveNearestEnabledValue(orderedItems, selectedIndex);
|
|
546
|
+
}
|
|
547
|
+
return this.getEnabledItems()[0]?.getValue() ?? null;
|
|
548
|
+
}
|
|
549
|
+
findItemByValue(value) {
|
|
550
|
+
if (value === null) {
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
553
|
+
return this.getOrderedItems().find((item) => valuesEqual(item.getValue(), value)) ?? null;
|
|
554
|
+
}
|
|
555
|
+
findEnabledItemByValue(value) {
|
|
556
|
+
const item = this.findItemByValue(value);
|
|
557
|
+
return item !== null && !item.disabled() ? item : null;
|
|
558
|
+
}
|
|
559
|
+
getEnabledItems() {
|
|
560
|
+
return this.getOrderedItems().filter((item) => !item.disabled());
|
|
561
|
+
}
|
|
562
|
+
getOrderedItems() {
|
|
563
|
+
return Array.from(this.items).sort(compareStepperItemsByDomPosition);
|
|
564
|
+
}
|
|
565
|
+
resolveDirection() {
|
|
566
|
+
const host = this.hostRef.nativeElement;
|
|
567
|
+
return host.closest('[dir="rtl"]') !== null ? 'rtl' : 'ltr';
|
|
568
|
+
}
|
|
5
569
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngStepper, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
6
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "
|
|
570
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.1.1", type: TngStepper, isStandalone: true, selector: "[tngStepper]", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, defaultValue: { classPropertyName: "defaultValue", publicName: "defaultValue", isSignal: true, isRequired: false, transformFunction: null }, orientation: { classPropertyName: "orientation", publicName: "orientation", isSignal: true, isRequired: false, transformFunction: null }, linear: { classPropertyName: "linear", publicName: "linear", isSignal: true, isRequired: false, transformFunction: null }, loopFocus: { classPropertyName: "loopFocus", publicName: "loopFocus", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: true, isRequired: false, transformFunction: null }, ariaLabelledby: { classPropertyName: "ariaLabelledby", publicName: "ariaLabelledby", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { valueChange: "valueChange", stepChange: "stepChange" }, host: { properties: { "attr.aria-label": "this.ariaLabelAttr", "attr.aria-labelledby": "this.ariaLabelledbyAttr", "attr.data-linear": "this.dataLinear", "attr.data-orientation": "this.dataOrientation", "attr.data-slot": "this.dataSlot" } }, exportAs: ["tngStepper"], ngImport: i0 });
|
|
7
571
|
}
|
|
8
572
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngStepper, decorators: [{
|
|
9
573
|
type: Directive,
|
|
@@ -11,8 +575,340 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImpor
|
|
|
11
575
|
selector: '[tngStepper]',
|
|
12
576
|
exportAs: 'tngStepper',
|
|
13
577
|
}]
|
|
578
|
+
}], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }], defaultValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "defaultValue", required: false }] }], orientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "orientation", required: false }] }], linear: [{ type: i0.Input, args: [{ isSignal: true, alias: "linear", required: false }] }], loopFocus: [{ type: i0.Input, args: [{ isSignal: true, alias: "loopFocus", required: false }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabel", required: false }] }], ariaLabelledby: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabelledby", required: false }] }], valueChange: [{ type: i0.Output, args: ["valueChange"] }], stepChange: [{ type: i0.Output, args: ["stepChange"] }], ariaLabelAttr: [{
|
|
579
|
+
type: HostBinding,
|
|
580
|
+
args: ['attr.aria-label']
|
|
581
|
+
}], ariaLabelledbyAttr: [{
|
|
582
|
+
type: HostBinding,
|
|
583
|
+
args: ['attr.aria-labelledby']
|
|
584
|
+
}], dataLinear: [{
|
|
585
|
+
type: HostBinding,
|
|
586
|
+
args: ['attr.data-linear']
|
|
587
|
+
}], dataOrientation: [{
|
|
588
|
+
type: HostBinding,
|
|
589
|
+
args: ['attr.data-orientation']
|
|
590
|
+
}], dataSlot: [{
|
|
591
|
+
type: HostBinding,
|
|
592
|
+
args: ['attr.data-slot']
|
|
593
|
+
}] } });
|
|
594
|
+
export class TngStepperItem {
|
|
595
|
+
hostRef = inject(ElementRef);
|
|
596
|
+
stepper = inject(TngStepper);
|
|
597
|
+
registrationOrder = nextStepperItemRegistrationOrder++;
|
|
598
|
+
lastKnownIndex = -1;
|
|
599
|
+
trigger = null;
|
|
600
|
+
connectors = new Set();
|
|
601
|
+
panels = new Set();
|
|
602
|
+
triggerId = createStepperTriggerId();
|
|
603
|
+
value = input(createStepperTriggerId(), { ...(ngDevMode ? { debugName: "value" } : {}), transform: normalizeValueInput });
|
|
604
|
+
completed = input(false, { ...(ngDevMode ? { debugName: "completed" } : {}), transform: normalizeBooleanInput });
|
|
605
|
+
optional = input(false, { ...(ngDevMode ? { debugName: "optional" } : {}), transform: normalizeBooleanInput });
|
|
606
|
+
disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : {}), transform: normalizeBooleanInput });
|
|
607
|
+
error = input(false, { ...(ngDevMode ? { debugName: "error" } : {}), transform: normalizeBooleanInput });
|
|
608
|
+
label = input(undefined, { ...(ngDevMode ? { debugName: "label" } : {}), transform: normalizeOptionalStringInput });
|
|
609
|
+
description = input(undefined, { ...(ngDevMode ? { debugName: "description" } : {}), transform: normalizeOptionalStringInput });
|
|
610
|
+
dataSlot = 'stepper-item';
|
|
611
|
+
ngOnInit() {
|
|
612
|
+
this.stepper.registerItem(this);
|
|
613
|
+
}
|
|
614
|
+
ngDoCheck() {
|
|
615
|
+
this.stepper.notifyItemMutated(this);
|
|
616
|
+
}
|
|
617
|
+
ngOnDestroy() {
|
|
618
|
+
this.stepper.unregisterItem(this);
|
|
619
|
+
}
|
|
620
|
+
registerTrigger(trigger) {
|
|
621
|
+
this.trigger = trigger;
|
|
622
|
+
this.stepper.notifyItemMutated(this);
|
|
623
|
+
}
|
|
624
|
+
unregisterTrigger(trigger) {
|
|
625
|
+
if (this.trigger === trigger) {
|
|
626
|
+
this.trigger = null;
|
|
627
|
+
this.stepper.notifyItemMutated(this);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
registerConnector(connector) {
|
|
631
|
+
this.connectors.add(connector);
|
|
632
|
+
this.stepper.notifyItemMutated(this);
|
|
633
|
+
}
|
|
634
|
+
unregisterConnector(connector) {
|
|
635
|
+
this.connectors.delete(connector);
|
|
636
|
+
this.stepper.notifyItemMutated(this);
|
|
637
|
+
}
|
|
638
|
+
registerPanel(panel) {
|
|
639
|
+
this.panels.add(panel);
|
|
640
|
+
this.stepper.notifyItemMutated(this);
|
|
641
|
+
}
|
|
642
|
+
unregisterPanel(panel) {
|
|
643
|
+
this.panels.delete(panel);
|
|
644
|
+
this.stepper.notifyItemMutated(this);
|
|
645
|
+
}
|
|
646
|
+
getValue() {
|
|
647
|
+
return this.value();
|
|
648
|
+
}
|
|
649
|
+
getHostElement() {
|
|
650
|
+
return this.hostRef.nativeElement;
|
|
651
|
+
}
|
|
652
|
+
getRegistrationOrder() {
|
|
653
|
+
return this.registrationOrder;
|
|
654
|
+
}
|
|
655
|
+
getLastKnownIndex() {
|
|
656
|
+
return this.lastKnownIndex;
|
|
657
|
+
}
|
|
658
|
+
getTriggerId() {
|
|
659
|
+
return this.trigger?.getId() ?? this.triggerId;
|
|
660
|
+
}
|
|
661
|
+
getPanelId() {
|
|
662
|
+
return Array.from(this.panels)[0]?.getId() ?? null;
|
|
663
|
+
}
|
|
664
|
+
focusTrigger() {
|
|
665
|
+
this.trigger?.focusSelf();
|
|
666
|
+
}
|
|
667
|
+
syncDomAttributes(state) {
|
|
668
|
+
this.lastKnownIndex = state.index;
|
|
669
|
+
const host = this.hostRef.nativeElement;
|
|
670
|
+
host.setAttribute('data-state', state.state);
|
|
671
|
+
host.setAttribute('data-step-index', String(state.index));
|
|
672
|
+
this.setBooleanAttribute(host, 'data-optional', this.optional());
|
|
673
|
+
this.trigger?.syncDomAttributes(state);
|
|
674
|
+
for (const connector of this.connectors) {
|
|
675
|
+
connector.syncDomAttributes(state.state);
|
|
676
|
+
}
|
|
677
|
+
for (const panel of this.panels) {
|
|
678
|
+
panel.syncDomAttributes(state.current, this.getTriggerId());
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
setBooleanAttribute(element, name, value) {
|
|
682
|
+
if (value) {
|
|
683
|
+
element.setAttribute(name, '');
|
|
684
|
+
}
|
|
685
|
+
else {
|
|
686
|
+
element.removeAttribute(name);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngStepperItem, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
690
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.1.1", type: TngStepperItem, isStandalone: true, selector: "[tngStepperItem]", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, completed: { classPropertyName: "completed", publicName: "completed", isSignal: true, isRequired: false, transformFunction: null }, optional: { classPropertyName: "optional", publicName: "optional", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, error: { classPropertyName: "error", publicName: "error", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, description: { classPropertyName: "description", publicName: "description", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.data-slot": "this.dataSlot" } }, exportAs: ["tngStepperItem"], ngImport: i0 });
|
|
691
|
+
}
|
|
692
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngStepperItem, decorators: [{
|
|
693
|
+
type: Directive,
|
|
694
|
+
args: [{
|
|
695
|
+
selector: '[tngStepperItem]',
|
|
696
|
+
exportAs: 'tngStepperItem',
|
|
697
|
+
}]
|
|
698
|
+
}], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }], completed: [{ type: i0.Input, args: [{ isSignal: true, alias: "completed", required: false }] }], optional: [{ type: i0.Input, args: [{ isSignal: true, alias: "optional", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], error: [{ type: i0.Input, args: [{ isSignal: true, alias: "error", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], description: [{ type: i0.Input, args: [{ isSignal: true, alias: "description", required: false }] }], dataSlot: [{
|
|
699
|
+
type: HostBinding,
|
|
700
|
+
args: ['attr.data-slot']
|
|
701
|
+
}] } });
|
|
702
|
+
export class TngStepperTrigger {
|
|
703
|
+
hostRef = inject(ElementRef);
|
|
704
|
+
item = inject(TngStepperItem);
|
|
705
|
+
stepper = inject(TngStepper);
|
|
706
|
+
id = createStepperTriggerId();
|
|
707
|
+
dataSlot = 'stepper-trigger';
|
|
708
|
+
get idAttr() {
|
|
709
|
+
const explicitId = this.hostRef.nativeElement.getAttribute('id');
|
|
710
|
+
return explicitId ?? this.id;
|
|
711
|
+
}
|
|
712
|
+
get typeAttr() {
|
|
713
|
+
return this.hostRef.nativeElement.tagName.toLowerCase() === 'button' ? 'button' : null;
|
|
714
|
+
}
|
|
715
|
+
ngOnInit() {
|
|
716
|
+
this.item.registerTrigger(this);
|
|
717
|
+
}
|
|
718
|
+
ngOnDestroy() {
|
|
719
|
+
this.item.unregisterTrigger(this);
|
|
720
|
+
}
|
|
721
|
+
getId() {
|
|
722
|
+
return this.idAttr;
|
|
723
|
+
}
|
|
724
|
+
focusSelf() {
|
|
725
|
+
this.hostRef.nativeElement.focus();
|
|
726
|
+
}
|
|
727
|
+
syncDomAttributes(state) {
|
|
728
|
+
const host = this.hostRef.nativeElement;
|
|
729
|
+
if (state.current) {
|
|
730
|
+
host.setAttribute('aria-current', 'step');
|
|
731
|
+
}
|
|
732
|
+
else {
|
|
733
|
+
host.removeAttribute('aria-current');
|
|
734
|
+
}
|
|
735
|
+
if (!state.activatable) {
|
|
736
|
+
host.setAttribute('aria-disabled', 'true');
|
|
737
|
+
}
|
|
738
|
+
else {
|
|
739
|
+
host.removeAttribute('aria-disabled');
|
|
740
|
+
}
|
|
741
|
+
host.setAttribute('aria-label', this.resolveAriaLabel(state.index, state.total));
|
|
742
|
+
host.setAttribute('data-state', state.state);
|
|
743
|
+
host.setAttribute('data-step-index', String(state.index));
|
|
744
|
+
host.setAttribute('tabindex', state.tabIndex);
|
|
745
|
+
if (this.item.optional()) {
|
|
746
|
+
host.setAttribute('data-optional', '');
|
|
747
|
+
}
|
|
748
|
+
else {
|
|
749
|
+
host.removeAttribute('data-optional');
|
|
750
|
+
}
|
|
751
|
+
const panelId = this.item.getPanelId();
|
|
752
|
+
if (panelId !== null) {
|
|
753
|
+
host.setAttribute('aria-controls', panelId);
|
|
754
|
+
}
|
|
755
|
+
else {
|
|
756
|
+
host.removeAttribute('aria-controls');
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
onClick(event) {
|
|
760
|
+
this.stepper.onTriggerClicked(this.item, event);
|
|
761
|
+
}
|
|
762
|
+
onFocus() {
|
|
763
|
+
this.stepper.onTriggerFocused(this.item);
|
|
764
|
+
}
|
|
765
|
+
onKeydown(event) {
|
|
766
|
+
this.stepper.onTriggerKeydown(this.item, event);
|
|
767
|
+
}
|
|
768
|
+
resolveAriaLabel(index, total) {
|
|
769
|
+
const label = this.item.label() ?? this.hostRef.nativeElement.textContent?.trim() ?? 'Step';
|
|
770
|
+
return [label, `Step ${index + 1} of ${total}`, this.resolveStateText()]
|
|
771
|
+
.filter((part) => part.length > 0)
|
|
772
|
+
.join(', ');
|
|
773
|
+
}
|
|
774
|
+
resolveStateText() {
|
|
775
|
+
if (this.item.error()) {
|
|
776
|
+
return 'Error';
|
|
777
|
+
}
|
|
778
|
+
if (this.item.optional()) {
|
|
779
|
+
return 'Optional';
|
|
780
|
+
}
|
|
781
|
+
if (this.item.completed()) {
|
|
782
|
+
return 'Completed';
|
|
783
|
+
}
|
|
784
|
+
return '';
|
|
785
|
+
}
|
|
786
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngStepperTrigger, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
787
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.1", type: TngStepperTrigger, isStandalone: true, selector: "[tngStepperTrigger]", host: { listeners: { "click": "onClick($event)", "focus": "onFocus()", "keydown": "onKeydown($event)" }, properties: { "attr.data-slot": "this.dataSlot", "attr.id": "this.idAttr", "attr.type": "this.typeAttr" } }, exportAs: ["tngStepperTrigger"], ngImport: i0 });
|
|
788
|
+
}
|
|
789
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngStepperTrigger, decorators: [{
|
|
790
|
+
type: Directive,
|
|
791
|
+
args: [{
|
|
792
|
+
selector: '[tngStepperTrigger]',
|
|
793
|
+
exportAs: 'tngStepperTrigger',
|
|
794
|
+
}]
|
|
795
|
+
}], propDecorators: { dataSlot: [{
|
|
796
|
+
type: HostBinding,
|
|
797
|
+
args: ['attr.data-slot']
|
|
798
|
+
}], idAttr: [{
|
|
799
|
+
type: HostBinding,
|
|
800
|
+
args: ['attr.id']
|
|
801
|
+
}], typeAttr: [{
|
|
802
|
+
type: HostBinding,
|
|
803
|
+
args: ['attr.type']
|
|
804
|
+
}], onClick: [{
|
|
805
|
+
type: HostListener,
|
|
806
|
+
args: ['click', ['$event']]
|
|
807
|
+
}], onFocus: [{
|
|
808
|
+
type: HostListener,
|
|
809
|
+
args: ['focus']
|
|
810
|
+
}], onKeydown: [{
|
|
811
|
+
type: HostListener,
|
|
812
|
+
args: ['keydown', ['$event']]
|
|
813
|
+
}] } });
|
|
814
|
+
export class TngStepperLabel {
|
|
815
|
+
dataSlot = 'stepper-label';
|
|
816
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngStepperLabel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
817
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.1", type: TngStepperLabel, isStandalone: true, selector: "[tngStepperLabel]", host: { properties: { "attr.data-slot": "this.dataSlot" } }, exportAs: ["tngStepperLabel"], ngImport: i0 });
|
|
818
|
+
}
|
|
819
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngStepperLabel, decorators: [{
|
|
820
|
+
type: Directive,
|
|
821
|
+
args: [{
|
|
822
|
+
selector: '[tngStepperLabel]',
|
|
823
|
+
exportAs: 'tngStepperLabel',
|
|
824
|
+
}]
|
|
14
825
|
}], propDecorators: { dataSlot: [{
|
|
15
826
|
type: HostBinding,
|
|
16
827
|
args: ['attr.data-slot']
|
|
17
828
|
}] } });
|
|
829
|
+
export class TngStepperDescription {
|
|
830
|
+
dataSlot = 'stepper-description';
|
|
831
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngStepperDescription, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
832
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.1", type: TngStepperDescription, isStandalone: true, selector: "[tngStepperDescription]", host: { properties: { "attr.data-slot": "this.dataSlot" } }, exportAs: ["tngStepperDescription"], ngImport: i0 });
|
|
833
|
+
}
|
|
834
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngStepperDescription, decorators: [{
|
|
835
|
+
type: Directive,
|
|
836
|
+
args: [{
|
|
837
|
+
selector: '[tngStepperDescription]',
|
|
838
|
+
exportAs: 'tngStepperDescription',
|
|
839
|
+
}]
|
|
840
|
+
}], propDecorators: { dataSlot: [{
|
|
841
|
+
type: HostBinding,
|
|
842
|
+
args: ['attr.data-slot']
|
|
843
|
+
}] } });
|
|
844
|
+
export class TngStepperPanel {
|
|
845
|
+
hostRef = inject(ElementRef);
|
|
846
|
+
item = inject(TngStepperItem);
|
|
847
|
+
panelId = createStepperPanelId();
|
|
848
|
+
dataSlot = 'stepper-panel';
|
|
849
|
+
get id() {
|
|
850
|
+
return this.panelId;
|
|
851
|
+
}
|
|
852
|
+
constructor() {
|
|
853
|
+
this.item.registerPanel(this);
|
|
854
|
+
}
|
|
855
|
+
ngOnDestroy() {
|
|
856
|
+
this.item.unregisterPanel(this);
|
|
857
|
+
}
|
|
858
|
+
getId() {
|
|
859
|
+
return this.panelId;
|
|
860
|
+
}
|
|
861
|
+
syncDomAttributes(current, triggerId) {
|
|
862
|
+
const host = this.hostRef.nativeElement;
|
|
863
|
+
host.setAttribute('aria-labelledby', triggerId);
|
|
864
|
+
host.setAttribute('data-state', current ? 'active' : 'inactive');
|
|
865
|
+
if (current) {
|
|
866
|
+
host.removeAttribute('hidden');
|
|
867
|
+
}
|
|
868
|
+
else {
|
|
869
|
+
host.setAttribute('hidden', '');
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngStepperPanel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
873
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.1", type: TngStepperPanel, isStandalone: true, selector: "[tngStepperPanel]", host: { properties: { "attr.data-slot": "this.dataSlot", "attr.id": "this.id" } }, exportAs: ["tngStepperPanel"], ngImport: i0 });
|
|
874
|
+
}
|
|
875
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngStepperPanel, decorators: [{
|
|
876
|
+
type: Directive,
|
|
877
|
+
args: [{
|
|
878
|
+
selector: '[tngStepperPanel]',
|
|
879
|
+
exportAs: 'tngStepperPanel',
|
|
880
|
+
}]
|
|
881
|
+
}], ctorParameters: () => [], propDecorators: { dataSlot: [{
|
|
882
|
+
type: HostBinding,
|
|
883
|
+
args: ['attr.data-slot']
|
|
884
|
+
}], id: [{
|
|
885
|
+
type: HostBinding,
|
|
886
|
+
args: ['attr.id']
|
|
887
|
+
}] } });
|
|
888
|
+
export class TngStepperConnector {
|
|
889
|
+
hostRef = inject(ElementRef);
|
|
890
|
+
item = inject(TngStepperItem);
|
|
891
|
+
dataSlot = 'stepper-connector';
|
|
892
|
+
constructor() {
|
|
893
|
+
this.item.registerConnector(this);
|
|
894
|
+
}
|
|
895
|
+
ngOnDestroy() {
|
|
896
|
+
this.item.unregisterConnector(this);
|
|
897
|
+
}
|
|
898
|
+
syncDomAttributes(state) {
|
|
899
|
+
this.hostRef.nativeElement.setAttribute('data-state', state);
|
|
900
|
+
}
|
|
901
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngStepperConnector, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
902
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.1", type: TngStepperConnector, isStandalone: true, selector: "[tngStepperConnector]", host: { properties: { "attr.data-slot": "this.dataSlot" } }, exportAs: ["tngStepperConnector"], ngImport: i0 });
|
|
903
|
+
}
|
|
904
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngStepperConnector, decorators: [{
|
|
905
|
+
type: Directive,
|
|
906
|
+
args: [{
|
|
907
|
+
selector: '[tngStepperConnector]',
|
|
908
|
+
exportAs: 'tngStepperConnector',
|
|
909
|
+
}]
|
|
910
|
+
}], ctorParameters: () => [], propDecorators: { dataSlot: [{
|
|
911
|
+
type: HostBinding,
|
|
912
|
+
args: ['attr.data-slot']
|
|
913
|
+
}] } });
|
|
18
914
|
//# sourceMappingURL=tng-stepper.js.map
|