Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: chip badge not geting the initial selecteds #855

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions projects/ion/src/lib/chip-group/chip-group.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ describe('With Dropdown', () => {
expect(screen.queryAllByText(option)).toHaveLength(1);
});

it('should not show badge when dont have item selected', async () => {
expect(screen.queryAllByTestId('badge-multiple')).toHaveLength(0);
});

it('should not close the dropdown when an option is selected and the chip is multiple', async () => {
await sut({
chips: [
Expand Down
11 changes: 11 additions & 0 deletions projects/ion/src/lib/chip/chip.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ describe('ChipComponent', () => {
expect(screen.getByTestId('badge-multiple')).toHaveTextContent('1');
});

it('should start with badge when an item is already selected', async () => {
await sut({
label: 'dropdown',
options: [
{ label: 'Option 1', selected: true },
{ label: 'Option 2', selected: false },
],
});
expect(screen.queryAllByTestId('badge-multiple')).toHaveLength(1);
});

describe('With Dropdown', () => {
const dropdownEvent = jest.fn();
beforeEach(async () => {
Expand Down
1 change: 1 addition & 0 deletions projects/ion/src/lib/chip/chip.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export class ChipComponent implements OnInit, AfterViewInit, DoCheck {

ngDoCheck(): void {
this.updateLabel();
this.setBadgeValue(this.getSelectedOptions().length);
}

getSelectedOptions(): DropdownItem[] {
Expand Down
18 changes: 18 additions & 0 deletions stories/Chip.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ WithDropdown.args = {
multiple: true,
};

export const WithItemAlreadySelected = Template.bind({});
WithItemAlreadySelected.args = {
label: 'Animais',
options: [
{ label: 'Cat', selected: true },
{ label: 'Dog' },
{ label: 'Monkey' },
{ label: 'Human' },
{ label: 'Bird' },
{ label: 'Fish' },
{ label: 'Goat' },
{ label: 'Lion' },
{ label: 'Tiger' },
],
icon: 'close',
multiple: true,
};

export const WithDropdownWithSearch = Template.bind({});
WithDropdownWithSearch.args = {
label: 'Animais',
Expand Down
Loading