Skip to content

Commit 2f3f763

Browse files
palbizuPatricio Albizu
andauthored
fix: updating checkbox component in multi-select (#730)
* fix: updating checkbox component in multi-select * fix: fixing uts * fix: refactoring uts * fix: fixing uts * fix: roll back to last PR with variable renaming * fix: linter Co-authored-by: Patricio Albizu <[email protected]>
1 parent 72e5b49 commit 2f3f763

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

projects/components/src/multi-select/multi-select.component.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,16 @@
8080
height: 34px;
8181
padding: 4px 16px;
8282
cursor: pointer;
83-
font-size: 14px;
83+
font-size: 15px;
8484
align-items: center;
8585

8686
.checkbox {
8787
margin: 0px;
88+
color: $gray-3;
89+
90+
::ng-deep .mat-ripple {
91+
display: none;
92+
}
8893
}
8994

9095
.icon {

projects/components/src/multi-select/multi-select.component.test.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { createHostFactory, mockProvider, SpectatorHost } from '@ngneat/spectato
66
import { MockComponent } from 'ng-mocks';
77
import { NEVER } from 'rxjs';
88
import { ButtonComponent } from '../button/button.component';
9+
import { CheckboxComponent } from '../checkbox/checkbox.component';
910
import { DividerComponent } from '../divider/divider.component';
1011
import { LabelComponent } from '../label/label.component';
1112
import { LoadAsyncModule } from '../load-async/load-async.module';
@@ -30,7 +31,8 @@ describe('Multi Select Component', () => {
3031
MockComponent(LabelComponent),
3132
MockComponent(DividerComponent),
3233
MockComponent(SearchBoxComponent),
33-
MockComponent(ButtonComponent)
34+
MockComponent(ButtonComponent),
35+
MockComponent(CheckboxComponent)
3436
],
3537
shallow: true
3638
});
@@ -91,8 +93,11 @@ describe('Multi Select Component', () => {
9193
});
9294

9395
spectator.tick();
94-
const selectedElements = spectator.queryAll('input:checked', { root: true });
95-
expect(selectedElements.length).toBe(2);
96+
const selectedCheckboxElements = spectator.queryAll('ht-checkbox', { root: true });
97+
expect(
98+
selectedCheckboxElements.filter(checkboxElement => checkboxElement.getAttribute('ng-reflect-checked') === 'true')
99+
.length
100+
).toBe(2);
96101
}));
97102

98103
test('should display provided options with icons when clicked', fakeAsync(() => {
@@ -121,8 +126,11 @@ describe('Multi Select Component', () => {
121126
expect(spectator.query('.multi-select-content', { root: true })).toExist();
122127
expect(optionElements.length).toBe(6);
123128

124-
const selectedElements = spectator.queryAll('input:checked', { root: true });
125-
expect(selectedElements.length).toBe(2);
129+
const selectedCheckboxElements = spectator.queryAll('ht-checkbox', { root: true });
130+
expect(
131+
selectedCheckboxElements.filter(checkboxElement => checkboxElement.getAttribute('ng-reflect-checked') === 'true')
132+
.length
133+
).toBe(2);
126134

127135
optionElements.forEach((element, index) => {
128136
expect(element).toHaveText(selectionOptions[index].label);
@@ -216,7 +224,12 @@ describe('Multi Select Component', () => {
216224
spectator.click(clearSelectedButton!);
217225

218226
spectator.tick();
219-
expect(spectator.queryAll('input:checked', { root: true }).length).toBe(0);
227+
228+
expect(
229+
spectator
230+
.queryAll('ht-checkbox', { root: true })
231+
.filter(checkboxElement => checkboxElement.getAttribute('ng-reflect-checked') === 'true').length
232+
).toBe(0);
220233
expect(onChange).toHaveBeenCalledTimes(1);
221234
expect(onChange).toHaveBeenLastCalledWith([]);
222235
expect(spectator.query(LabelComponent)?.label).toEqual('Select options');
@@ -226,8 +239,8 @@ describe('Multi Select Component', () => {
226239
spectator.click(allOptionElement!);
227240

228241
spectator.tick();
229-
const selectedElements = spectator.queryAll('input:checked', { root: true });
230-
expect(selectedElements.length).toBe(6);
242+
const selectedCheckboxElements = spectator.queryAll('ht-checkbox', { root: true });
243+
expect(selectedCheckboxElements.length).toBe(6);
231244

232245
expect(onChange).toHaveBeenCalledWith(selectionOptions.map(option => option.value));
233246
expect(spectator.query(LabelComponent)?.label).toEqual('first and 5 more');

projects/components/src/multi-select/multi-select.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ import { MultiSelectJustify } from './multi-select-justify';
9292
(click)="this.onSelectionChange(item)"
9393
class="multi-select-option"
9494
>
95-
<input class="checkbox" type="checkbox" [checked]="this.isSelectedItem(item)" />
95+
<ht-checkbox class="checkbox" [checked]="this.isSelectedItem(item)"></ht-checkbox>
9696
<ht-icon
9797
class="icon"
9898
*ngIf="item.icon"

projects/components/src/multi-select/multi-select.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { CommonModule } from '@angular/common';
22
import { NgModule } from '@angular/core';
33
import { ButtonModule } from '../button/button.module';
4+
import { TraceCheckboxModule } from '../checkbox/checkbox.module';
45
import { DividerModule } from '../divider/divider.module';
56
import { IconModule } from '../icon/icon.module';
67
import { LabelModule } from '../label/label.module';
@@ -18,7 +19,8 @@ import { MultiSelectComponent } from './multi-select.component';
1819
DividerModule,
1920
TraceSearchBoxModule,
2021
ButtonModule,
21-
LoadAsyncModule
22+
LoadAsyncModule,
23+
TraceCheckboxModule
2224
],
2325
declarations: [MultiSelectComponent],
2426
exports: [MultiSelectComponent]

0 commit comments

Comments
 (0)