@@ -74,6 +74,7 @@ class UiSuggestFixtureDirective {
74
74
75
75
clearable ?: boolean ;
76
76
searchable ?: boolean ;
77
+ compact ?: boolean ;
77
78
searchableCountInfo ?: { count : number ; message : string } ;
78
79
alwaysExpanded ?: boolean ;
79
80
disabled ?: boolean ;
@@ -1655,6 +1656,30 @@ const sharedSpecifications = (
1655
1656
. forEach ( valueText => expect ( selectedChipsInnerText . includes ( valueText ) ) . toBeTrue ( ) ) ;
1656
1657
} ) ;
1657
1658
1659
+ it ( 'should display all selected values in compact mode' , ( ) => {
1660
+ const selectedValues = faker . helpers . shuffle ( component . items ! ) . slice ( 0 , 3 ) ;
1661
+ component . value = selectedValues ;
1662
+ component . compact = true ;
1663
+ component . searchable = true ;
1664
+
1665
+ fixture . detectChanges ( ) ;
1666
+
1667
+ const displayContainer = fixture . debugElement . query ( By . css ( '.display-container' ) ) ;
1668
+ const displayValue = displayContainer . query ( By . css ( '.display-value' ) ) ;
1669
+
1670
+ if ( ! uiSuggest . isFormControl ) {
1671
+ const displayTitle = displayContainer . query ( By . css ( '.display-title' ) ) ;
1672
+ expect ( displayTitle . nativeElement . innerText . trim ( ) ) . toBe ( `${ component . placeholder } :` ) ;
1673
+ } else {
1674
+ const displayTitle = fixture . debugElement . query ( By . css ( '.mat-form-field-label' ) ) ;
1675
+ expect ( displayTitle . nativeElement . innerText . trim ( ) ) . toEqual ( component . placeholder ) ;
1676
+ }
1677
+
1678
+ selectedValues
1679
+ . map ( value => value . text )
1680
+ . forEach ( valueText => expect ( displayValue . nativeElement . innerText . trim ( ) ) . toContain ( valueText ) ) ;
1681
+ } ) ;
1682
+
1658
1683
it ( 'should have a checkbox next to each item entry' , waitForAsync ( async ( ) => {
1659
1684
fixture . detectChanges ( ) ;
1660
1685
@@ -2428,7 +2453,8 @@ describe('Component: UiSuggest', () => {
2428
2453
[fetchStrategy]="fetchStrategy"
2429
2454
[minChars]="minChars"
2430
2455
[drillDown]="drillDown"
2431
- [readonly]="readonly">
2456
+ [readonly]="readonly"
2457
+ [compact]="compact">
2432
2458
</ui-suggest>
2433
2459
` ,
2434
2460
} )
@@ -2509,6 +2535,7 @@ describe('Component: UiSuggest', () => {
2509
2535
[fetchStrategy]="fetchStrategy"
2510
2536
[minChars]="minChars"
2511
2537
[drillDown]="drillDown"
2538
+ [compact]="compact"
2512
2539
formControlName="test">
2513
2540
</ui-suggest>
2514
2541
</mat-form-field>
@@ -2682,32 +2709,45 @@ describe('Component: UiSuggest', () => {
2682
2709
2683
2710
@Component ( {
2684
2711
template : `
2685
- <ui-suggest [placeholder]="placeholder"
2686
- [defaultValue]="defaultValue"
2687
- [clearable]="clearable"
2688
- [searchable]="searchable"
2689
- [enableCustomValue]="enableCustomValue"
2690
- [alwaysExpanded]="alwaysExpanded"
2691
- [headerItems]="headerItems"
2692
- [items]="items"
2693
- [value]="value"
2694
- [direction]="direction"
2695
- [displayPriority]="displayPriority"
2696
- [disabled]="disabled"
2697
- [multiple]="multiple"
2698
- [readonly]="readonly"
2699
- [fetchStrategy]="fetchStrategy"
2700
- [displayTemplateValue]="displayTemplateValue"
2701
- [searchableCountInfo]="searchableCountInfo"
2702
- [minChars]="minChars"
2703
- [drillDown]="drillDown">
2704
- <ng-template let-item >
2705
- <div class="item-template">{{ item.text }}</div>
2706
- </ng-template>
2712
+ <ui-suggest
2713
+ [placeholder]="placeholder"
2714
+ [defaultValue]="defaultValue"
2715
+ [clearable]="clearable"
2716
+ [searchable]="searchable"
2717
+ [enableCustomValue]="enableCustomValue"
2718
+ [alwaysExpanded]="alwaysExpanded"
2719
+ [headerItems]="headerItems"
2720
+ [items]="items"
2721
+ [value]="value"
2722
+ [direction]="direction"
2723
+ [displayPriority]="displayPriority"
2724
+ [disabled]="disabled"
2725
+ [multiple]="multiple"
2726
+ [readonly]="readonly"
2727
+ [fetchStrategy]="fetchStrategy"
2728
+ [displayTemplateValue]="displayTemplateValue"
2729
+ [searchableCountInfo]="searchableCountInfo"
2730
+ [minChars]="minChars"
2731
+ [drillDown]="drillDown"
2732
+ [compact]="compact"
2733
+ [compactSummaryTemplate]="compactSummaryTemplate"
2734
+ >
2735
+ <ng-template let-item>
2736
+ <div class="item-template">{{ item.text }}</div>
2737
+ </ng-template>
2707
2738
</ui-suggest>
2739
+ <ng-template #compactSummaryTemplate let-value>
2740
+ <div class="custom-display-value">
2741
+ <span class="text-ellipsis">{{value?.[0]?.text}}</span>
2742
+ <span *ngIf="(value?.length || 0) > 1">
2743
+ (+{{ (value?.length || 0) - 1 }}
2744
+ {{ value?.length === 2 ? "other" : "others" }})
2745
+ </span>
2746
+ </div>
2747
+ </ng-template>
2708
2748
` ,
2709
2749
} )
2710
- class UiSuggestCustomTemplateFixtureComponent extends UiSuggestFixtureDirective { }
2750
+ class UiSuggestCustomTemplateFixtureComponent extends UiSuggestFixtureDirective { }
2711
2751
2712
2752
describe ( 'Type: custom template' , ( ) => {
2713
2753
let fixture : ComponentFixture < UiSuggestCustomTemplateFixtureComponent > ;
@@ -2762,6 +2802,25 @@ describe('Component: UiSuggest', () => {
2762
2802
} ) ;
2763
2803
} ) ) ;
2764
2804
2805
+ it ( 'should render the compact summary using the provided custom template' , ( ) => {
2806
+ component . items = generateSuggetionItemList ( 'random' ) ;
2807
+
2808
+ const selectedValues = faker . helpers . shuffle ( component . items ! ) . slice ( 0 , 3 ) ;
2809
+ component . value = selectedValues ;
2810
+
2811
+ component . multiple = true ;
2812
+ component . compact = true ;
2813
+ component . searchable = true ;
2814
+
2815
+ fixture . detectChanges ( ) ;
2816
+
2817
+ const displayContainer = fixture . debugElement . query ( By . css ( '.display-container' ) ) ;
2818
+ const displayValue = displayContainer . query ( By . css ( '.custom-display-value' ) ) ;
2819
+ const summaryText = displayValue . nativeElement . innerText . trim ( ) ;
2820
+
2821
+ expect ( summaryText ) . toBe ( `${ selectedValues [ 0 ] . text } (+2 others)` ) ;
2822
+ } ) ;
2823
+
2765
2824
[ false , true ] . forEach ( ( multiple ) => {
2766
2825
[ false , true ] . forEach ( ( displayTemplateValue ) => {
2767
2826
it ( `should ${ ! multiple && displayTemplateValue ? '' : 'NOT' } render the displayed value with custom` +
0 commit comments