Skip to content

Commit

Permalink
feat: add undefined or null state to middle option on triple toggle #…
Browse files Browse the repository at this point in the history
  • Loading branch information
iurynogueira committed Mar 26, 2024
1 parent 459bcce commit cd76ef6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions projects/ion/src/lib/core/types/triple-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ export interface TripleToggleProps {
options?: TripleToggleOptions;
onlyShowIcon?: boolean;
ionClick?: EventEmitter<SafeAny>;
middleValue?: SafeAny;
}
12 changes: 12 additions & 0 deletions projects/ion/src/lib/triple-toggle/triple-toggle.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ describe('IonTripleToggleComponent', () => {
expect(screen.getByTestId(firstOptionId)).toHaveClass(selectedOption);
});

it.only('should show the selected option when started with it', async () => {
await sut({
ionClick: {
emit: clickEvent,
} as SafeAny,
middleValue: null,
});
const element = screen.getByTestId(middleOptionId);
fireEvent.click(element);
expect(clickEvent).toHaveBeenCalledWith(null);
});

it('should show selected middle option when none option are selected initially', async () => {
await sut({
options: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export class IonTripleToggleComponent implements OnInit, OnChanges {
@Input() size: Size = 'md';
@Input() options: TripleToggleOptions;
@Input() onlyShowIcon = false;
@Input() middleValue = undefined;

@Output() ionClick = new EventEmitter();

public optionsToRender: TripleToggleOptionsToRender;
Expand All @@ -39,7 +41,7 @@ export class IonTripleToggleComponent implements OnInit, OnChanges {
label: 'Sim',
};
private DEFAULT_MIDDLE_OPTION: TripleToggleOption = {
value: undefined,
value: this.middleValue,
label: '-',
selected: true,
};
Expand Down

0 comments on commit cd76ef6

Please sign in to comment.