Skip to content

Commit

Permalink
feat: add required to chip-group #734
Browse files Browse the repository at this point in the history
  • Loading branch information
MadalenaCampos committed Jul 11, 2023
1 parent bdc01f8 commit f916210
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions projects/ion/src/lib/chip-group/chip-group.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*ngFor="let chip of chips; index as i"
[label]="chip.label"
[disabled]="chip.disabled || disabled"
[required]="chip.required || required"
[selected]="chip.selected"
[showDropdown]="chip.selected && chip.options"
[size]="chip.size || size"
Expand Down
18 changes: 11 additions & 7 deletions projects/ion/src/lib/chip-group/chip-group.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,21 @@ export class IonChipGroupComponent {
chipSelected.selected = !isChipSelected;
}

// const chipsSelecteds = this.chips.filter((chip) => chip.selected);
// if (this.required && !this.multiple) {
// chipSelected.selected = true;
// chipSelected.label = 'teste';
// this.selected.emit(chipSelected);
// return;
// }
if (this.required) {
this.checkRequired(chipSelected);
return;
}

this.selected.emit(chipSelected);
}

checkRequired(chipSelected: ChipInGroup) {
const selectedChips = this.chips.filter((chip) => chip.selected);
if (!selectedChips.length) {
chipSelected.selected = true;
}
}

dropdownEvents(options: DropdownItem[]): void {
if (options) {
this.dropdown.emit(options);
Expand Down
2 changes: 1 addition & 1 deletion projects/ion/src/lib/chip/chip.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class ChipComponent implements OnInit, AfterViewInit, DoCheck {
select(): void {
this.toggleDropdown();
if (!this.options) {
this.selected = !this.selected;
!this.selected;
}
this.events.emit({
selected: this.selected,
Expand Down
6 changes: 6 additions & 0 deletions stories/ChipGroup.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,9 @@ export const WithDropdown = Template.bind({});
WithDropdown.args = {
chips: chipsWithOptions,
};

export const WithRequired = Template.bind({});
WithRequired.args = {
chips,
required: true,
};

0 comments on commit f916210

Please sign in to comment.