Skip to content

Commit

Permalink
feat(sbb-radio-button-group): emit radio button in change event (#2267)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeripeierSBB committed Dec 6, 2023
1 parent a9b4ad6 commit e0ce718
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {

import style from './radio-button-group.scss?lit&inline';

export type SbbRadioButtonGroupEventDetail = { value: any | null };
export type SbbRadioButtonGroupEventDetail = { value: any | null; radioButton: SbbRadioButton };

/**
* It can be used as a container for one or more `sbb-radio-button`.
Expand Down Expand Up @@ -221,21 +221,23 @@ export class SbbRadioButtonGroup extends LitElement {
return;
}

const radioButton = event.target as SbbRadioButton;

if (event.detail.checked) {
this.value = (event.target as HTMLInputElement).value;
this._emitChange(this.value);
this.value = radioButton.value;
this._emitChange(radioButton, this.value);
} else if (this.allowEmptySelection) {
this.value = this._radioButtons.find((radio) => radio.checked)?.value;
if (!this.value) {
this._emitChange();
this._emitChange(radioButton);
}
}
}

private _emitChange(value?: string): void {
this._change.emit({ value });
this._input.emit({ value });
this._didChange.emit({ value });
private _emitChange(radioButton: SbbRadioButton, value?: string): void {
this._change.emit({ value, radioButton });
this._input.emit({ value, radioButton });
this._didChange.emit({ value, radioButton });
}

private _updateRadios(initValue?: string): void {
Expand Down

0 comments on commit e0ce718

Please sign in to comment.