Skip to content

Commit acb629a

Browse files
author
Konstantin Dinev
committed
Merge branch 'master' of https://github.com/IgniteUI/igniteui-angular into coverage-extras
2 parents 5c67b34 + 9f5fee3 commit acb629a

File tree

12 files changed

+105
-4
lines changed

12 files changed

+105
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes for each version of this project will be documented in this
88

99
- `IgxCombo`, `IgxSimpleCombo`
1010
- Introduced the `selectionChanged` event for both components. The event is not cancelable and is emitted after the selection is committed and the component state is updated.
11+
- Added `disableClear` input that allows hiding the clear button even when items are selected. Defaults to `false`.
1112

1213
## 21.1.3
1314

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
"karma-chrome-launcher": "~3.2.0",
144144
"karma-coverage": "^2.0.3",
145145
"karma-jasmine": "~5.1.0",
146+
"karma-jasmine-spec-tags": "^2.0.0",
146147
"karma-junit-reporter": "^2.0.1",
147148
"karma-parallel": "^0.3.1",
148149
"karma-spec-reporter": "^0.0.36",

projects/igniteui-angular/combo/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@ You can disable combo using the following code:
164164

165165
<div class="divider--half"></div>
166166

167+
### Disable Clear
168+
You can hide the clear button using the following code:
169+
170+
```html
171+
<igx-combo [disableClear]="true"></igx-combo>
172+
```
173+
174+
When set to `true`, the clear button is not rendered even when items are selected.
175+
176+
<div class="divider--half"></div>
177+
167178
### Grouping
168179
Defining a combo's groupKey option will group the items, according to that key.
169180

@@ -320,7 +331,8 @@ When igxCombo is opened, allow custom values are enabled and add item button is
320331
| `searchPlaceholder ` | defines the placeholder text for search input | string |
321332
| `collapsed` | gets drop down state | boolean |
322333
| `disabled` | defines whether the control is active or not | boolean |
323-
| `ariaLabelledBy` | defines label ID related to combo | boolean |
334+
| `disableClear` | defines whether the clear button is rendered | boolean |
335+
| `ariaLabelledBy` | defines label ID related to combo | string |
324336
| `type` | Combo style. - "line", "box", "border", "search" | string |
325337
| `valid` | gets if control is valid, when used in a form | boolean |
326338
| `overlaySettings` | gets/sets the custom overlay settings that control how the drop-down list displays | OverlaySettings |

projects/igniteui-angular/combo/src/combo/combo.common.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,22 @@ export abstract class IgxComboBaseDirective implements IgxComboBase, AfterViewCh
456456
@Input({ transform: booleanAttribute })
457457
public disabled = false;
458458

459+
/**
460+
* Disables the clear button. The default is `false`.
461+
*
462+
* ```typescript
463+
* // get
464+
* let myComboDisableClear = this.combo.disableClear;
465+
* ```
466+
*
467+
* ```html
468+
* <!--set-->
469+
* <igx-combo [disableClear]="true"></igx-combo>
470+
* ```
471+
*/
472+
@Input({ transform: booleanAttribute })
473+
public disableClear = false;
474+
459475
/**
460476
* Sets the visual combo type.
461477
* The allowed values are `line`, `box`, `border` and `search`. The default is `box`.

projects/igniteui-angular/combo/src/combo/combo.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<ng-container ngProjectAs="igx-suffix">
1919
<ng-content select="igx-suffix,[igxSuffix]"></ng-content>
2020
</ng-container>
21-
@if (displayValue) {
21+
@if (displayValue && !disableClear) {
2222
<igx-suffix [attr.aria-label]="resourceStrings.igx_combo_clearItems_placeholder" class="igx-combo__clear-button"
2323
(click)="handleClearItems($event)">
2424
@if (clearIconTemplate) {

projects/igniteui-angular/combo/src/combo/combo.component.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,6 +2228,25 @@ describe('igxCombo', () => {
22282228
fixture.detectChanges();
22292229
expect(fixture.debugElement.queryAll(By.css(`.${CSS_CLASS_CLEARBUTTON}`)).length).toBeFalsy();
22302230
});
2231+
it('should default disableClear to false', () => {
2232+
expect(combo.disableClear).toBe(false);
2233+
});
2234+
it('should hide the clear button when disableClear is true and items are selected', () => {
2235+
combo.select(['Maryland']);
2236+
fixture.detectChanges();
2237+
// Verify the clear button is visible before setting disableClear
2238+
expect(fixture.debugElement.queryAll(By.css(`.${CSS_CLASS_CLEARBUTTON}`)).length).toBe(1);
2239+
2240+
combo.disableClear = true;
2241+
fixture.detectChanges();
2242+
expect(fixture.debugElement.queryAll(By.css(`.${CSS_CLASS_CLEARBUTTON}`)).length).toBe(0);
2243+
});
2244+
it('should show the clear button when disableClear is false (default) and items are selected', () => {
2245+
combo.select(['Maryland']);
2246+
fixture.detectChanges();
2247+
expect(combo.disableClear).toBe(false);
2248+
expect(fixture.debugElement.queryAll(By.css(`.${CSS_CLASS_CLEARBUTTON}`)).length).toBe(1);
2249+
});
22312250
it('should select/deselect item on check/uncheck', () => {
22322251
const dropdown = combo.dropdown;
22332252
spyOn(combo.selectionChanging, 'emit').and.callThrough();

projects/igniteui-angular/simple-combo/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,17 @@ You can disable the combo using the following code:
150150

151151
<div class="divider--half"></div>
152152

153+
### Disable Clear
154+
You can hide the clear button using the following code:
155+
156+
```html
157+
<igx-simple-combo [disableClear]="true"></igx-simple-combo>
158+
```
159+
160+
When set to `true`, the clear button is not rendered even when a value is selected.
161+
162+
<div class="divider--half"></div>
163+
153164
### Grouping
154165
Defining a combo's groupKey option will group the items, according to that key.
155166

@@ -292,7 +303,8 @@ When the combo is opened, allow custom values are enabled and add item button is
292303
| `placeholder ` | Defines the "empty value" text. | `string` |
293304
| `collapsed` | Gets the dropdown state. | `boolean` |
294305
| `disabled` | Defines whether the control is active or not. | `boolean` |
295-
| `ariaLabelledBy` | Defines label ID related to combo. | `boolean` |
306+
| `disableClear` | Defines whether the clear button is rendered. | `boolean` |
307+
| `ariaLabelledBy` | Defines label ID related to combo. | `string` |
296308
| `valid` | gets if control is valid, when used in a form. | `boolean` |
297309
| `overlaySettings` | Controls how the dropdown is displayed. | `OverlaySettings` |
298310
| `selected` | Get current selection state. | `Array<any>` |

projects/igniteui-angular/simple-combo/src/simple-combo/simple-combo.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<ng-content select="igx-suffix,[igxSuffix]"></ng-content>
2626
</ng-container>
2727

28-
@if (hasSelectedItem) {
28+
@if (hasSelectedItem && !disableClear) {
2929
<igx-suffix [attr.aria-label]="resourceStrings.igx_combo_clearItems_placeholder" class="igx-combo__clear-button"
3030
(click)="handleClear($event)">
3131
@if (clearIconTemplate) {

projects/igniteui-angular/simple-combo/src/simple-combo/simple-combo.component.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,26 @@ describe('IgxSimpleCombo', () => {
17991799
expect(clearButton).toBeNull();
18001800
});
18011801

1802+
it('should default disableClear to false', () => {
1803+
expect(combo.disableClear).toBe(false);
1804+
});
1805+
it('should hide the clear button when disableClear is true and an item is selected', () => {
1806+
combo.select('Wisconsin');
1807+
fixture.detectChanges();
1808+
// Verify the clear button is visible before setting disableClear
1809+
expect(fixture.debugElement.queryAll(By.css(`.${CSS_CLASS_CLEARBUTTON}`)).length).toBe(1);
1810+
1811+
combo.disableClear = true;
1812+
fixture.detectChanges();
1813+
expect(fixture.debugElement.queryAll(By.css(`.${CSS_CLASS_CLEARBUTTON}`)).length).toBe(0);
1814+
});
1815+
it('should show the clear button when disableClear is false (default) and an item is selected', () => {
1816+
combo.select('Wisconsin');
1817+
fixture.detectChanges();
1818+
expect(combo.disableClear).toBe(false);
1819+
expect(fixture.debugElement.queryAll(By.css(`.${CSS_CLASS_CLEARBUTTON}`)).length).toBe(1);
1820+
});
1821+
18021822
it('should open the combo to the top when there is no space to open to the bottom', fakeAsync(() => {
18031823
fixture = TestBed.createComponent(IgxBottomPositionSimpleComboComponent);
18041824
fixture.detectChanges();

0 commit comments

Comments
 (0)