@skyux/lookup 11.16.0 → 11.17.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.
|
@@ -3086,10 +3086,11 @@ class SkyLookupComponent extends SkyLookupAutocompleteAdapter {
|
|
|
3086
3086
|
this.#_selectMode = value;
|
|
3087
3087
|
this.#updateForSelectMode();
|
|
3088
3088
|
if (multipleToSingle) {
|
|
3089
|
-
|
|
3089
|
+
const value = this.#getValue();
|
|
3090
|
+
if (value?.length > 1) {
|
|
3090
3091
|
// The `setTimeout` is needed to avoid a `ExpressionChangedAfterItHasBeenCheckedError` error in template forms.
|
|
3091
3092
|
setTimeout(() => {
|
|
3092
|
-
this.writeValue([
|
|
3093
|
+
this.writeValue([value[0]]);
|
|
3093
3094
|
this.#changeDetector.detectChanges();
|
|
3094
3095
|
});
|
|
3095
3096
|
}
|
|
@@ -3101,11 +3102,12 @@ class SkyLookupComponent extends SkyLookupAutocompleteAdapter {
|
|
|
3101
3102
|
get tokens() {
|
|
3102
3103
|
return this.#_tokens;
|
|
3103
3104
|
}
|
|
3104
|
-
set tokens(
|
|
3105
|
+
set tokens(tokens) {
|
|
3106
|
+
const value = this.#getValue();
|
|
3105
3107
|
// Collapse the tokens into a single token if the user has selected many options.
|
|
3106
|
-
if (this.enableShowMore &&
|
|
3108
|
+
if (this.enableShowMore && value.length > 5) {
|
|
3107
3109
|
this.#resourcesService
|
|
3108
|
-
.getString('skyux_lookup_tokens_summary',
|
|
3110
|
+
.getString('skyux_lookup_tokens_summary', value.length.toString())
|
|
3109
3111
|
.pipe(take(1))
|
|
3110
3112
|
.subscribe((label) => {
|
|
3111
3113
|
this.#_tokens = [
|
|
@@ -3117,20 +3119,17 @@ class SkyLookupComponent extends SkyLookupAutocompleteAdapter {
|
|
|
3117
3119
|
});
|
|
3118
3120
|
}
|
|
3119
3121
|
else {
|
|
3120
|
-
this.#_tokens =
|
|
3122
|
+
this.#_tokens = tokens;
|
|
3121
3123
|
this.#changeDetector.markForCheck();
|
|
3122
3124
|
}
|
|
3123
3125
|
}
|
|
3126
|
+
/**
|
|
3127
|
+
* @internal
|
|
3128
|
+
* @deprecated This is exposed for unit tests only; refactor unit tests to
|
|
3129
|
+
* derive the control value a different way.
|
|
3130
|
+
*/
|
|
3124
3131
|
get value() {
|
|
3125
|
-
return this.#
|
|
3126
|
-
}
|
|
3127
|
-
set value(newValue) {
|
|
3128
|
-
this.#_value = newValue;
|
|
3129
|
-
if (!this.#pickerModalOpen()) {
|
|
3130
|
-
this.tokens = this.#parseTokens(newValue);
|
|
3131
|
-
}
|
|
3132
|
-
this.onChange(this.#_value);
|
|
3133
|
-
this.onTouched();
|
|
3132
|
+
return this.#getValue();
|
|
3134
3133
|
}
|
|
3135
3134
|
set autocompleteInputDirective(value) {
|
|
3136
3135
|
this.#_autocompleteInputDirective = value;
|
|
@@ -3142,6 +3141,8 @@ class SkyLookupComponent extends SkyLookupAutocompleteAdapter {
|
|
|
3142
3141
|
#idle;
|
|
3143
3142
|
#markForTokenFocusOnKeyUp;
|
|
3144
3143
|
#ngUnsubscribe;
|
|
3144
|
+
#notifyChange;
|
|
3145
|
+
#notifyTouched;
|
|
3145
3146
|
#openNativePicker;
|
|
3146
3147
|
#openSelectionModal;
|
|
3147
3148
|
#_required;
|
|
@@ -3162,6 +3163,19 @@ class SkyLookupComponent extends SkyLookupAutocompleteAdapter {
|
|
|
3162
3163
|
#resourcesService;
|
|
3163
3164
|
#selectionModalSvc;
|
|
3164
3165
|
#windowRef;
|
|
3166
|
+
#getValue() {
|
|
3167
|
+
return this.#_value ? this.#_value : [];
|
|
3168
|
+
}
|
|
3169
|
+
#setValue(newValue, options) {
|
|
3170
|
+
this.#_value = newValue;
|
|
3171
|
+
if (this.selectMode === 'multiple' && !this.#pickerModalOpen()) {
|
|
3172
|
+
this.tokens = this.#parseTokens(newValue);
|
|
3173
|
+
}
|
|
3174
|
+
if (options.emitEvent) {
|
|
3175
|
+
this.#notifyChange?.(this.#_value);
|
|
3176
|
+
}
|
|
3177
|
+
this.#updateForSelectMode();
|
|
3178
|
+
}
|
|
3165
3179
|
constructor(ngControl, inputBoxHostSvc, themeSvc) {
|
|
3166
3180
|
super();
|
|
3167
3181
|
this.inputBoxHostSvc = inputBoxHostSvc;
|
|
@@ -3193,11 +3207,6 @@ class SkyLookupComponent extends SkyLookupAutocompleteAdapter {
|
|
|
3193
3207
|
this.#resourcesService = inject(SkyLibResourcesService);
|
|
3194
3208
|
this.#selectionModalSvc = inject(SkySelectionModalService);
|
|
3195
3209
|
this.#windowRef = inject(SkyAppWindowRef);
|
|
3196
|
-
// Angular automatically constructs these methods.
|
|
3197
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
3198
|
-
this.onChange = (value) => { };
|
|
3199
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
3200
|
-
this.onTouched = () => { };
|
|
3201
3210
|
if (ngControl) {
|
|
3202
3211
|
ngControl.valueAccessor = this;
|
|
3203
3212
|
}
|
|
@@ -3250,16 +3259,15 @@ class SkyLookupComponent extends SkyLookupAutocompleteAdapter {
|
|
|
3250
3259
|
});
|
|
3251
3260
|
}
|
|
3252
3261
|
onAutocompleteSelectionChange(change) {
|
|
3253
|
-
/* istanbul ignore else */
|
|
3254
3262
|
if (change.selectedItem) {
|
|
3255
3263
|
this.#addToSelected(change.selectedItem);
|
|
3256
3264
|
}
|
|
3257
|
-
else
|
|
3258
|
-
this
|
|
3265
|
+
else {
|
|
3266
|
+
this.#setValue([], { emitEvent: true });
|
|
3259
3267
|
}
|
|
3260
3268
|
}
|
|
3261
3269
|
onAutocompleteBlur() {
|
|
3262
|
-
this
|
|
3270
|
+
this.#notifyTouched?.();
|
|
3263
3271
|
}
|
|
3264
3272
|
onTokensChange(change) {
|
|
3265
3273
|
if (!change) {
|
|
@@ -3269,14 +3277,11 @@ class SkyLookupComponent extends SkyLookupAutocompleteAdapter {
|
|
|
3269
3277
|
if (change.length === 0) {
|
|
3270
3278
|
this.#focusInput();
|
|
3271
3279
|
}
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
this.#_value = change.map((token) => {
|
|
3280
|
+
this.tokens = change;
|
|
3281
|
+
const value = change.map((token) => {
|
|
3275
3282
|
return token.value;
|
|
3276
3283
|
});
|
|
3277
|
-
this
|
|
3278
|
-
this.onChange(this.#_value);
|
|
3279
|
-
this.onTouched();
|
|
3284
|
+
this.#setValue(value, { emitEvent: true });
|
|
3280
3285
|
}
|
|
3281
3286
|
}
|
|
3282
3287
|
onTokensFocusIndexOverRange() {
|
|
@@ -3309,14 +3314,13 @@ class SkyLookupComponent extends SkyLookupAutocompleteAdapter {
|
|
|
3309
3314
|
}
|
|
3310
3315
|
writeValue(value) {
|
|
3311
3316
|
// Since we are dealing with arrays - clone the array being sent in to ensure we aren't modifying a consumers outer array
|
|
3312
|
-
this
|
|
3313
|
-
this.#updateForSelectMode();
|
|
3317
|
+
this.#setValue(value ? value.slice() : [], { emitEvent: false });
|
|
3314
3318
|
}
|
|
3315
3319
|
registerOnChange(fn) {
|
|
3316
|
-
this
|
|
3320
|
+
this.#notifyChange = fn;
|
|
3317
3321
|
}
|
|
3318
3322
|
registerOnTouched(fn) {
|
|
3319
|
-
this
|
|
3323
|
+
this.#notifyTouched = fn;
|
|
3320
3324
|
}
|
|
3321
3325
|
// Allows Angular to disable the input.
|
|
3322
3326
|
setDisabledState(disabled) {
|
|
@@ -3417,11 +3421,11 @@ class SkyLookupComponent extends SkyLookupAutocompleteAdapter {
|
|
|
3417
3421
|
this.showMoreConfig.customPicker.open({
|
|
3418
3422
|
items: this.data,
|
|
3419
3423
|
initialSearch,
|
|
3420
|
-
initialValue: this
|
|
3424
|
+
initialValue: this.#getValue(),
|
|
3421
3425
|
});
|
|
3422
3426
|
}
|
|
3423
3427
|
else {
|
|
3424
|
-
const initialValue = this
|
|
3428
|
+
const initialValue = this.#getValue();
|
|
3425
3429
|
if (this.#hasSearchAsync()) {
|
|
3426
3430
|
this.#openSelectionModal =
|
|
3427
3431
|
this.#createSelectionModalInstance(initialSearch);
|
|
@@ -3469,7 +3473,7 @@ class SkyLookupComponent extends SkyLookupAutocompleteAdapter {
|
|
|
3469
3473
|
}
|
|
3470
3474
|
}
|
|
3471
3475
|
#createSelectionModalInstance(initialSearch) {
|
|
3472
|
-
const initialValue = this
|
|
3476
|
+
const initialValue = this.#getValue();
|
|
3473
3477
|
const modalConfig = this.showMoreConfig?.nativePickerConfig || {};
|
|
3474
3478
|
if (!modalConfig.itemTemplate) {
|
|
3475
3479
|
modalConfig.itemTemplate = this.searchResultTemplate;
|
|
@@ -3504,7 +3508,7 @@ class SkyLookupComponent extends SkyLookupAutocompleteAdapter {
|
|
|
3504
3508
|
});
|
|
3505
3509
|
}
|
|
3506
3510
|
#createNativePickerInstance(initialSearch) {
|
|
3507
|
-
const initialValue = this
|
|
3511
|
+
const initialValue = this.#getValue();
|
|
3508
3512
|
const modalConfig = this.showMoreConfig?.nativePickerConfig || {};
|
|
3509
3513
|
if (!modalConfig.itemTemplate) {
|
|
3510
3514
|
modalConfig.itemTemplate = this.searchResultTemplate;
|
|
@@ -3543,21 +3547,22 @@ class SkyLookupComponent extends SkyLookupAutocompleteAdapter {
|
|
|
3543
3547
|
this.searchAsync.emit(args);
|
|
3544
3548
|
}
|
|
3545
3549
|
#addToSelected(item) {
|
|
3550
|
+
const value = this.#getValue();
|
|
3546
3551
|
let selectedItems;
|
|
3547
3552
|
if (this.selectMode === 'single') {
|
|
3548
3553
|
selectedItems = [item];
|
|
3549
3554
|
}
|
|
3550
3555
|
else {
|
|
3551
|
-
selectedItems =
|
|
3556
|
+
selectedItems = value;
|
|
3552
3557
|
const idProperty = this.idProperty || '';
|
|
3553
3558
|
// If items have a unique identifier, don't allow the same item to be added twice.
|
|
3554
3559
|
if (!this.idProperty ||
|
|
3555
|
-
!
|
|
3560
|
+
!value.some((existingItem) => existingItem[idProperty] === item[idProperty])) {
|
|
3556
3561
|
selectedItems.push(item);
|
|
3557
3562
|
}
|
|
3558
3563
|
this.clearSearchText();
|
|
3559
3564
|
}
|
|
3560
|
-
this
|
|
3565
|
+
this.#setValue(selectedItems, { emitEvent: true });
|
|
3561
3566
|
}
|
|
3562
3567
|
#addEventListeners() {
|
|
3563
3568
|
this.#idle = new Subject();
|
|
@@ -3640,8 +3645,9 @@ class SkyLookupComponent extends SkyLookupAutocompleteAdapter {
|
|
|
3640
3645
|
}
|
|
3641
3646
|
}
|
|
3642
3647
|
if (addItemToValue) {
|
|
3648
|
+
const oldValue = this.#getValue();
|
|
3643
3649
|
const newValue = this.selectMode === 'multiple'
|
|
3644
|
-
?
|
|
3650
|
+
? oldValue.concat(args.item)
|
|
3645
3651
|
: [args.item];
|
|
3646
3652
|
this.writeValue(newValue);
|
|
3647
3653
|
}
|
|
@@ -3663,7 +3669,8 @@ class SkyLookupComponent extends SkyLookupAutocompleteAdapter {
|
|
|
3663
3669
|
#updateForSelectMode() {
|
|
3664
3670
|
if (this.autocompleteInputDirective) {
|
|
3665
3671
|
if (this.selectMode === 'single') {
|
|
3666
|
-
|
|
3672
|
+
const value = this.#getValue();
|
|
3673
|
+
this.autocompleteInputDirective.value = value && value[0];
|
|
3667
3674
|
}
|
|
3668
3675
|
else {
|
|
3669
3676
|
this.clearSearchText();
|