Skip to content

Commit

Permalink
Modify refactor (#13010)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kisters-BS authored Aug 29, 2023
1 parent a542e94 commit af79321
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/app/components/selectbutton/selectbutton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,28 +172,26 @@ export class SelectButton implements ControlValueAccessor {
return;
}

const optionValue = this.getOptionValue(option);

if (this.multiple) {
if (this.isSelected(option)) this.removeOption(option);
else this.value = [...(this.value || []), this.getOptionValue(option)];
else this.value = [...(this.value || []), optionValue];

this.onModelChange(this.value);

this.onChange.emit({
originalEvent: event,
value: this.value
});
} else {
let value = this.getOptionValue(option);

if (this.value !== value) {
this.value = this.getOptionValue(option);
this.onModelChange(this.value);
} else if (this.value !== optionValue) {
this.value = optionValue;
this.onModelChange(this.value);

this.onChange.emit({
originalEvent: event,
value: this.value
});
}
this.onChange.emit({
originalEvent: event,
value: this.value
});
}

this.onOptionClick.emit({
Expand All @@ -213,7 +211,7 @@ export class SelectButton implements ControlValueAccessor {

isSelected(option: any) {
let selected = false;
let optionValue = this.getOptionValue(option);
const optionValue = this.getOptionValue(option);

if (this.multiple) {
if (this.value && Array.isArray(this.value)) {
Expand All @@ -225,7 +223,7 @@ export class SelectButton implements ControlValueAccessor {
}
}
} else {
selected = ObjectUtils.equals(this.getOptionValue(option), this.value, this.dataKey);
selected = ObjectUtils.equals(optionValue, this.value, this.dataKey);
}

return selected;
Expand Down

1 comment on commit af79321

@vercel
Copy link

@vercel vercel bot commented on af79321 Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.